Pi Life, part two
2020-Jul-11, Saturday 01:47 pmIn Pi Life, part one I only got as far as making my raspberry pi functional again through upgrade. Now on to the script I want to put on it.
After doing a project, and writing it up, I am usually too lazy to tweet my own blog posts, so I wrote a little python script to scrape my RSS feed and post a link to the most recent post to twitter. (For people who don't use RSS.)
Step Two; create twitter app entry and get access tokens
This part seems to change constantly, so here are some posts I used to help me along the way;
https://www.digitalocean.com/community/tutorials/how-to-create-a-twitter-app
https://iag.me/socialmedia/how-to-create-a-twitter-app-in-8-easy-steps/
https://code.tutsplus.com/articles/creating-a-twitter-oauth-application--net-16614
Step Three; create python script
Assuming you have python3 already;
And because
Create a python script something like this (the exact code will depend on the structure of your RSS);
( code )
Step Four; deal with errors
My main error happened when I wanted to get an image used in a post. My images are self-hosted, Let's Encrypt signed. And the python3 libraries were not happy;
Now you can just turn off verification;
But you still get an annoying warning message.
I tried so many different ways to try and fix this. This is the only thing I found that worked.
First, go to Let's Encrypt Certs and save the Intermediate, Active, cross-signed cert. Remove the
If no errors, all good.
Now, in python;
Mine returns
Edit this file, append everything in
Step Five;
Glory in the lack of errors/warnings. And automatically created tweets, I guess.
After doing a project, and writing it up, I am usually too lazy to tweet my own blog posts, so I wrote a little python script to scrape my RSS feed and post a link to the most recent post to twitter. (For people who don't use RSS.)
Step Two; create twitter app entry and get access tokens
This part seems to change constantly, so here are some posts I used to help me along the way;
https://www.digitalocean.com/community/tutorials/how-to-create-a-twitter-app
https://iag.me/socialmedia/how-to-create-a-twitter-app-in-8-easy-steps/
https://code.tutsplus.com/articles/creating-a-twitter-oauth-application--net-16614
Step Three; create python script
Assuming you have python3 already;
pip3 install tweepy
pip3 install feedparser
pip3 install bs4
pip3 install lxmlAnd because
BeautifulSoup can't seem to find lxml this way;sudo apt-get install python3-lxmlCreate a python script something like this (the exact code will depend on the structure of your RSS);
( code )
Step Four; deal with errors
My main error happened when I wanted to get an image used in a post. My images are self-hosted, Let's Encrypt signed. And the python3 libraries were not happy;
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)Now you can just turn off verification;
response = get(img_link, verify=False)But you still get an annoying warning message.
I tried so many different ways to try and fix this. This is the only thing I found that worked.
First, go to Let's Encrypt Certs and save the Intermediate, Active, cross-signed cert. Remove the
.txt suffix. Verify this cert fixes the error for you with;curl https://your_website --cacert /path/to/lets-encrypt-x3-cross-signed.pemIf no errors, all good.
Now, in python;
import certifi
print(certifi.where())Mine returns
/home/pi/.local/lib/python3.7/site-packages/certifi/cacert.pemEdit this file, append everything in
lets-encrypt-x3-cross-signed.pem to the end. (Leave a comment telling yourself what you did for future.) Save and exit. Rerun the tweeting python script.Step Five;
Glory in the lack of errors/warnings. And automatically created tweets, I guess.