Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: astral-sh/ruff-action@v3
- uses: actions/setup-python@v5
with:
python-version: "3.14"
allow-prereleases: true
- name: Install dependencies
run: pip install phpserialize>=1.3 setuptools>=42 mypy
- name: Run mypy
run: mypy wpparser/

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install dependencies
run: |
pip install --upgrade pip
pip install pytest phpserialize>=1.3
- name: Run tests
run: pytest -s tests/
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
__pycache__/
.DS_Store
.*.swp
tags
Expand All @@ -8,4 +9,6 @@ build
.coverage
*.egg-info/
venv*
.tox/
.tox/
.pytest_cache/
.ruff_cache/
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

5 changes: 0 additions & 5 deletions Makefile

This file was deleted.

172 changes: 84 additions & 88 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
[![Build Status](https://travis-ci.org/marteinn/wpparser.svg?branch=master)](https://travis-ci.org/marteinn/wpparser)
[![PyPI version](https://badge.fury.io/py/wpparser.svg)](http://badge.fury.io/py/wpparser)

# wpparser

This library parses Wordpress xml based exports into a simple python dictionary.

This library parses WordPress XML exports into a Python dictionary.

## How it works
## Installation

The library uses ElementTree to traverse through the export file.
```bash
pip install wpparser
```

## Usage

import wpparser

data = wpparser.parse("./blog.wordpress.2014-09-26.xml")
>>> {"blog": {"tagline": "Tagline",...
```python
import wpparser

data = wpparser.parse("./blog.wordpress.2014-09-26.xml")
```

## What it returns

It returns a well formatted dict, containing the following datatypes:
A dictionary containing:

- Blog: The general blog information, such as tagline, site url.
- Authors: A list with the different authors.
- Categories: The categories in use, organized as a nested array.
- Tags: A list with the different tags.
- Posts: An array that contains all posts, the post object might also contain the different comments belonging to the post.
- **blog**: General blog information (title, tagline, site url, etc.)
- **authors**: List of authors
- **categories**: Categories organized as a nested tree
- **tags**: List of tags
- **posts**: List of posts, including comments and post metadata

### Example:
### Example

```python
{
Expand All @@ -37,85 +35,83 @@ It returns a well formatted dict, containing the following datatypes:
"site_url": "http://marteinn.se/blog",
"blog_url": "http://marteinn.se/blog",
"language": "en-US",
"title": "Marteinn / Blog"
"title": "Marteinn / Blog",
},
"authors: [{
"login": "admin",
"last_name": None,
"display_name": "admin",
"email": "martin@marteinn.se",
"first_name": None}
"authors": [
{
"login": "admin",
"last_name": None,
"display_name": "admin",
"email": "martin@marteinn.se",
"first_name": None,
}
],
"categories": [
{
"parent": None,
"term_id": "3",
"name": "Action Script",
"nicename": "action-script",
"children": [
{
"parent": "action-script",
"term_id": "20",
"name": "Flash related",
"nicename": "flash-related",
"children": [],
}
],
}
],
"tags": [{"term_id": "1", "slug": "bash", "name": "Bash"}],
"posts": [
{
"creator": "admin",
"excerpt": None,
"post_date_gmt": "2014-09-22 20:10:40",
"post_date": "2014-09-22 21:10:40",
"post_type": "post",
"menu_order": "0",
"guid": "http://marteinn.se/blog/?p=828",
"title": "Post Title",
"comments": [
{
"date_gmt": "2014-09-24 23:08:31",
"parent": "0",
"date": "2014-09-25 00:08:31",
"id": "85929",
"user_id": "0",
"author": "Author",
"author_email": None,
"author_ip": "111.111.111.111",
"approved": "1",
"content": "Comment title",
"author_url": "http://example.com",
"type": "pingback",
}
],
"content": "Text",
"post_parent": "0",
"post_password": None,
"status": "publish",
"description": None,
"tags": ["tag"],
"ping_status": "open",
"post_id": "1",
"link": "http://www.marteinn.se/blog/slug/",
"pub_date": "Mon, 22 Sep 2014 20:10:40 +0000",
"categories": ["category"],
"is_sticky": "0",
"post_name": "slug",
}
],
"categories": [{
"parent": None,
"term_id": "3",
"name": "Action Script",
"nicename": "action-script",
"children": [{
"parent": "action-script",
"term_id": "20",
"name": "Flash related",
"nicename": "flash-related",
"children": []
}]
}],
"tags": [{
"term_id": "1",
"slug": "bash",
"name": "Bash"
}],
"posts": [{
"creator": "admin",
"excerpt": None,
"post_date_gmt": "2014-09-22 20:10:40",
"post_date": "2014-09-22 21:10:40",
"post_type": "post",
"menu_order": "0",
"guid": "http://marteinn.se/blog/?p=828",
"title": "Post Title",
"comments": [{
"date_gmt": "2014-09-24 23:08:31",
"parent": "0",
"date": "2014-09-25 00:08:31",
"id": "85929",
"user_id": "0",
"author": u"Author",
"author_email": None,
"author_ip": "111.111.111.111",
"approved": "1",
"content": u"Comment title",
"author_url": "http://example.com",
"type": "pingback"
}],
"content": "Text",
"post_parent": "0",
"post_password": None,
"status": "publish",
"description": None,
"tags": ["tag"],
"ping_status": "open",
"post_id": "1",
"link": "http://www.marteinn.se/blog/slug/",
"pub_date": "Mon, 22 Sep 2014 20:10:40 +0000",
"categories": ["category"],
"is_sticky": "0",
"post_name": "slug"
}]
}
```

## Installation

wpparser can easily be installed through pip.

$ pip install wpparser


## Contributing

Want to contribute? Awesome. Just send a pull request.


## License

wpparser is released under the [MIT License](http://www.opensource.org/licenses/MIT).
71 changes: 71 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "wpparser"
dynamic = ["version"]
description = "Parse wordpress export files into a well formatted python dictionary"
readme = "README.md"
license = "MIT"
requires-python = ">=3.10"
authors = [
{ name = "Martin Sandström", email = "martin@marteinn.se" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3.14",
]
dependencies = [
"phpserialize>=1.3",
]

[project.urls]
Homepage = "https://github.com/marteinn/wpparser"

[tool.setuptools.dynamic]
version = { attr = "wpparser.__version__" }

[tool.ruff]
target-version = "py314"
line-length = 120

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"RUF", # ruff-specific rules
]

[tool.ruff.lint.isort]
known-third-party = ["phpserialize"]

[tool.mypy]
python_version = "3.14"
strict = true
warn_unused_configs = true

no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true

show_error_codes = true
pretty = true

[[tool.mypy.overrides]]
module = ["phpserialize"]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = ["tests.*"]
disallow_untyped_defs = false
2 changes: 0 additions & 2 deletions requirements/dev.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements/install.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements/tests.txt

This file was deleted.

33 changes: 0 additions & 33 deletions runtests.py

This file was deleted.

Loading