First you need to make sure that the python interpreter can
access the feedparser
, google-api-python-client
and google_auth_oauthlib
libraries.
If using /usr/bin/python
, you can install them with:
pip3 install feedparser google-api-python-client google_auth_oauthlib
Edit the variables in private_variables.py
.
Because your computer might not be on 24/7, I run this script multiple times per day (between 06:00 and 21:00 every hour). I do this by adding a cron job at my Raspberry Pi, by using crontab -e
and then adding:
0 8-21/1 * * 1-5 /usr/bin/python ~/arxiv-feed-mailer/send_arxiv.py >> ~/arxiv-feed-mailer/send.log 2>&1
Step 1: Turn on the Gmail API
Click this button to create a new Cloud Platform project and automatically enable the Gmail API:
In resulting dialog click DOWNLOAD CLIENT CONFIGURATION and save the file credentials.json
to your working directory.
-
Follow step 1: Turn on the Gmail API to create a
client_secret.json
file. -
Install the Google Client Library and other Python dependencies with:
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib feedparser
- Run the code using the following command:
python gmailsendapi.py
(add the --noauth_local_webserver
flag if you work through ssh
)
3.a The sample will attempt to open a new window or tab in your default browser. If this fails, copy the URL from the console and manually open it in your browser.
3.b If you are not already logged into your Google account, you will be prompted to log in. If you are logged into multiple Google accounts, you will be asked to select one account to use for the authorization.
3.c Click the Accept button.
3.d The sample will proceed automatically, and you may close the window/tab.
- Place credentials and configuration files in a folder
There are a few files that contain the configuration and credentials, that can be placed in a different directory.
By default, this directory is
~/Dropbox/arxiv/
, you can modify it ingmailsendapi.py
andsend_arxiv.py
. The list of files that must be (plus [optionals]) in that folder are
client_secret.json
credentials.json
token.pickle
- [
send.txt
] - [
private_variables.py
]
- Authorization information is stored on the file system, so subsequent executions will not prompt for authorization.
This is an entire screen capture of the e-mail: