Python-powered toolkit to supercharge your pocket experience! π οΈ easily manage, organize, and export your saved links and articles with advanced search, tagging, and more.
pocket-tools/
βββ pocket_tools/ # Core Python package
β βββ __init__.py # Initializes the package and optionally imports key functions
β βββ pocket.py # Core logic for interacting with the Pocket API
β βββ utils.py # Utility functions (e.g., for JSON formatting)
β βββ __pycache__/ # Auto-generated compiled Python files (ignored in version control)
βββ tests/ # Unit tests
β βββ test_pocket.py # Unit tests for the Pocket API integration
βββ config/ # Configuration files
β βββ settings.json # API keys and settings for fetching all data
β βββ settings_tag.json # API keys and settings for fetching data by tag
βββ output/ # Directory for generated output files
β βββ pocket_all_data.json # Example output containing fetched Pocket API data
βββ README.md # Documentation and project overview
βββ LICENSE # Licensing information for the project
βββ setup.py # Configuration script for packaging and distribution
βββ requirements.txt # List of external dependencies for the project
βββ .gitignore # Specifies files and directories to ignore in version control
βββ main.py # Main entry point for running the application
You need to acomplish following steps in order to get access token for your application.
- Visit Pocket Developers Signup.
- Set your app permissions:
- Read Only: if the app only retrieves data.
- Add, Modify: if the app also adds or modifies data.
- Note down the generated
consumer_key
.
- Run the following
curl
command to request arequest_token
(replaceYOUR_CONSUMER_KEY
with your application's key. replaceredirect_uri
with the url of your application or leave it as it is if you are working in CLI, as we do in this case):
curl https://getpocket.com/v3/oauth/request -X POST \
-H "Content-Type: application/json" \
-H "X-Accept: application/json" \
-d "{\"consumer_key\":\"YOUR_CONSUMER_KEY\",\"redirect_uri\":\"urn:ietf:wg:oauth:2.0:oob\"}"
- You will receive a response in JSON format, e.g. (note
your_request_token
value.) use it in the next step:
{"code":"your_request_token"}
- Paste the following link to the browser (paste token from the previous step in place of
your_request_token
):
https://getpocket.com/auth/authorize?request_token=your_request_token&redirect_uri=urn:ietf:wg:oauth:2.0:oob
- Open the link and authorize the application.
- After successful authorization, you will see a confirmation message. No further action in the browser is needed.
- Run the following curl command:
- Replace:
YOUR_CONSUMER_KEY
with your app's key.your_request_token
with the token from Step 2.
curl https://getpocket.com/v3/oauth/authorize -X POST \
-H "Content-Type: application/json" \
-H "X-Accept: application/json" \
-d "{\"consumer_key\":\"YOUR_CONSUMER_KEY\",\"code\":\"your_request_token\"}"
- You will receive a response containing the access_token and the username:
{"access_token":"your_access_token","username":"user_name"}
- Save the
access_token
β it will be needed for API requests.
- Store keys and tokens securely: Use configuration files with appropriate permissions.
- Avoid
--insecure
in curl commands: Unless testing in a trusted local environment. - Do not publish
consumer_key
oraccess_token
: Keep them private and out of public repositories.
Create isolated Python environment if you wish to - please refer to my article.
Clone repository:
$ git clone https://github.com/skaczmarek-dev/pocket-tools
Install dependencies:
$ pip install -r pocket-tools/requirements.txt
Create directory to store config file
$ cd pocket tools
$ mkdir config
Create file config/settings.json
with following credentials obtained in step 2. and 4.:
{
"consumer_key":"YOUR_CONSUMER_KEY",
"access_token":"YOUR_ACCESS_TOKEN",
"detailType": "complete"
}
Prepare output directory
$ cd pocket-tools
$ mkdir output
Run the main form the directory of a pocket-tools
$ python3 main.py
Run tests form the directory of a pocket-tools
$ python3 -m unittest tests/test_pocket.py
- [] simplify the installation process with setup.py