Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python script that checks Instagram and flashes Pimoroni's Blinkt if the follower count has increased
#!/usr/bin/python
import urllib2
from urllib import quote
import time
import json
from config import (
ig_style,
ig_account,
ig_access_token,
)
from blinkt import set_pixel, show, set_clear_on_exit, set_brightness
import math
# The functions that creates the magic - checks your Instagram account for the number of followers then sends this data to Slack to notify you.
set_clear_on_exit()
reds = [0, 0, 0, 0, 0, 16, 64, 255, 64, 16, 0, 0, 0, 0, 0]
start_time = time.time()
# This function is for the Knight Rider KITT light effect
def larson():
count = 0
while (count < 75):
delta = (time.time() - start_time) * 16
offset = int(abs((delta % 16) - 8))
for i in range(8):
set_pixel(i, reds[offset + i], 0, 0)
show()
time.sleep(0.1), count
count = count + 1
# This function gets the follower count from Instagram
def fanCount():
ig_url = 'https://api.instagram.com/v1/users/self/?access_token={}'.format(quote(ig_access_token))
fanCount = urllib2.urlopen(ig_url).read()
jsonResponse = json.loads(fanCount)
return jsonResponse['data']['counts']['followed_by']
# I want to write the jsonResponse output to a text file, and ideally I would like to check this file. If the follower count has increased,
# I would like to overwrite the text file with the new count, and then use this value in the "if / else" bit below.
# Triggers the KITT effect on the Blinkt if the follower count is greater than 320 - customise this number to be alerted of your key milestones.
if int(fanCount()) < 320: # If I could pull the "320" from the text file created by the jsonResponse output, that would be awesome!
larson()
exit()
else:
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.