Skip to main content

Export "Saved Stories" from Apple News to SQLite

Project description

apple-news-to-sqlite

Export Apple News Saved Stories to SQLite

Install

pip install apple-news-to-sqlite

Source code

apple-news-to-sqlite

Usage

apple-news-to-sqlite articles.db

apple-news-to-sqlite --dump

Your Terminal app will require full disk access in order to access the saved article database in the Apple News app sandbox.

CLI help

Usage: apple-news-to-sqlite [OPTIONS] [DB_PATH]

  Export your Apple News saved stories/articles to a SQLite database

  Example usage:

      apple-news-to-sqlite articles.db

  This will populate articles.db with an "articles" table containing information
  about your saved articles.

  Note: the contents of the articles themselves are not stored in the database,
  only metadata about the article such as title, author, url, etc.

Options:
  --version       Show the version and exit.
  --dump, --json  Print saved stories to standard output as JSON.
  --all           Process all saved articles; if not specified, only saved
                  articles that have not previously been stored in the database
                  are processed.
  --schema        Create database schema and exit.
  --help          Show this message and exit.

Using apple-news-to-sqlite in your own Python code

get_saved_articles() returns a list of dictionaries, each representing a saved article with the following keys:

* id: str
* date: datetime.datetime
* url: str
* title: str
* description: str
* image: str
* author: str
>>> from apple_news_to_sqlite import get_saved_articles
>>> articles = get_saved_articles()

How it works

Through reverse engineering, it was determined that the Apple News app stores saved articles in a file called reading-list in the following directory:

~/Library/Containers/com.apple.news/Data/Library/Application Support/com.apple.news/com.apple.news.public-com.apple.news.private-production/

This format of this file is unknown but it is a binary file that contains two embedded binary plist files. The first contains an NSKeyedArchiver object which I have not yet inspected. The second bplist contains a list of saved article IDs along with the date they were saved. The article IDs are used to look up the article data on Apple's News site and the article data is extracted with Beautiful Soup.

Testing

The code is at the "it works on my machine" stage of testing. (M1 Mini, macOS Ventura 13.1)

I've also tested this on macOS Catalina 10.15.7 and it appears to work correctly.

If it doesn't work for you, please open an issue!

Contributing

Contributions of all types are welcome! Fork the repo, make a branch, and submit a PR.

See README_DEV.md for developer notes.

Thanks

Thanks to Simon Willison who inspired this project with his excellent "everything-to-sqlite" dogsheep project.

Thanks Simon also for the excellent tools sqlite-utils and Datasette.

Thanks also to Dave Bullock who inspired this project and helped tremendously with the reverse engineering and initial code.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apple_news_to_sqlite-0.4.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apple_news_to_sqlite-0.4.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file apple_news_to_sqlite-0.4.1.tar.gz.

File metadata

  • Download URL: apple_news_to_sqlite-0.4.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for apple_news_to_sqlite-0.4.1.tar.gz
Algorithm Hash digest
SHA256 738c55ef64a897989f1ff0c71ceb3e03dab2aa9baa5ee271e39473c934141c8b
MD5 f7d5e1d66c6f42e320c9242edec3a528
BLAKE2b-256 262b5de50498616ae509bc4b0315feb4e7b689e236331009e8167805aea432a9

See more details on using hashes here.

File details

Details for the file apple_news_to_sqlite-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for apple_news_to_sqlite-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d42e71586cd01111b7e301f5bce7d8736c73db82ec733bc35220d442a74dbe8e
MD5 2aac70f4efd30166832348b6f0ac5067
BLAKE2b-256 ab12c597f05f01fdca5372cca6d9379799e3dc056d4d854fe38f1a2d3ce77af8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page