Published: 2019-05-09 02:07 |
Category: Projects | Tags: code, instagram, open web, programming, project, proof of concept, python, rss
tl;dr: I have a hacky proof-of-concept method for getting an Instagram account as an RSS feed. It uses Python and you can grab the source files here.
I'm not on Instagram because I got tired of only seeing three people's photos interwoven with ads. The problem is I still have friends who post frequently there and I feel like I should still be able to see those photos.
The wonderful thing about the Internet is that you can do things that weren't really meant to be done. Instagram (nor most other companies) provide RSS feeds anymore in order to force you into their platform. That's silly. I've been teaching myself Python and this seemed like a good way to flex some of my new powers.
Get that feed
Inspired by Andy Barefoot, who did some magic on his personal site with PHP, I decided to do the same using Python. What resulted was a command line program which can fetch any public Instagram account and create an XML document I could subscribe to.
I'm going to use Alane Levine as my guinea [STRIKEOUT:pig] dog for this post. To create the feed, run:
python subscribe.py cogdog
where the argument is the username of the account. I'm using a handly lbrary called PyRSS2Gen by Andrew Dalke to create the properly formatted feed. I ran the script and then threw it on my server and subscribed, just to see what would happen.


evil cackle
Update that feed
Instagram only shows 12 photos at a time. If I ran this script over and over, it would drop a photo from the feed each time it updated. That's no good.
I wrote up a second (notably more hacky) companion which takes almost the same form in order to update the feed rather than create one from scratch:
python update.py cogdog
This little guy looks for the existing XML doc and then fetches the user's Instagram page yet again. Instead of writing everything, it only writes things with timestamps newer than the most recent feed item. It's a little brute force, but hey, every tool can be a hammer if you swing hard enough.
Improvements
The subscribe script only loads those initial 12 photos. I may still go back and have it get the entire profile in the first go, but limiting it seems okay to me.
It's not general-purpose yet because you have to know how to install Python and several modules as well as have a web server to host the feeds on. I started finessing this into a small webapp which would do all the jobs, but my brain is stretched pretty far as it is.
If you want the source, it's in a GitHub gist and you can certainly tweak and improve. Let me know if you make changes or how I could do this better in the future.
Holy cow, that's neat. I better post more photos for ya.