A python script that will send the user an email with a link to all their Pinboard bookmarks that were made on the date the script is run, in years past. Think, TimeHop for Pinboard. If there were no links saved on that day, do not send an email.
I'm sure there are ways to optimize this code that are beyond my current skill level. If you discover any improvements, please let me know!
If you haven't yet, make sure you install pinboard.py:
pip3 install "pinboard>=2.0"
You may also need dateutil
:
pip3 install python-dateutil
If you're missing anything else, you should get an error when you try and run the script saying something to the effect of: ModuleNotFoundError: No module named '[module name]]'
. That means you need to install that module.
This code uses a config.py
file in the same directory as the script, which contains your secrets.
To use this, rename config-example.py
to config.py
and update all the variables:
Config | Description |
---|---|
MSG_FROM | Email address where the daily email should be sent from |
MSG_TO | Email address where you want the email sent |
SMTP_SERVER | Your SMTP server address |
SMTP_USERNAME | Your SMTP server username |
FIRST_POST_YEAR | The year in which you made your first Pinboard bookmark |
Also, add your Pinboard API token (from your Pinboard password page) and SMTP passwords as environmental variables (/etc/environment
):
PINBOARD_API_TOKEN
SMTP_PASS
You can do this with a cron job.
First, make sure rundailypinboard.sh
and daily-pinboard.py
are set as executable:
chmod +x rundailypinboard.sh
chmod +x daily-pinboard.py
Open your crontab file:
crontab -e
Then, add the following line to your crontab file:
0 7 * * * /path/to/rundailypinboard.sh
Make sure you replace /path/to/rundailypinboard.sh
with the actual path to your rundailypinboard.sh script.
The cronjob code above runs the script daily at 7am ET (my server's set timezone). You can adjust that to your desired cadence and time.
- improve the format of the email (make it pretty!)
- change API key and email password before making Repo public
- successfully retrieve daily posts
- test for when there are multiple results
- save post to a variable, and retrieve name and content
- figure out how to send via email (sendgrid?)
- hide Pinboard API key
- edit the code so that if the email is empty, it will not send
the api returns this for a given date:
{'date': datetime.datetime(2022, 6, 11, 21, 13, 49), 'user': 'dannberg', 'posts': [<Bookmark description="lionheart/pinboard.py: A full-featured Python wrapper (and command-line utility) for the Pinboard API. Built by the makers of Pushpin for Pinboard." url="github.com">]}
A special thank you to OpenAI's ChatGPT for the code help! Damn, that tool is nifty.