Created
June 24, 2017 18:22
-
-
Save cr5315/270c8dbcb334fc10c1fe17d69d9d3521 to your computer and use it in GitHub Desktop.
Instagram Follower Count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the list of Instagram accounts you want to get the follower counts of | |
# An @ is not required at the start of the name, and will be removed if there is one | |
INSTAGRAM_ACCOUNTS = [ | |
"nasa" | |
] | |
# Telegram bot token acquired from the BotFather | |
TELEGRAM_BOT_TOKEN = "GET_ONE" | |
# Telegram "chat ids" where the message will be sent | |
# see https://stackoverflow.com/a/37396871 for an easy way to get your chat id | |
TELEGRAM_USERS = [ | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import config | |
import json | |
import urllib | |
import urllib2 | |
class InstagramAccount(object): | |
def __init__(self, username): | |
self.follower_count = 0 | |
self.username = username | |
self.url = "https://www.instagram.com/%s/?__a=1" % self.username | |
def get_follower_count(self): | |
response = urllib2.urlopen(self.url) | |
data = json.load(response) | |
self.follower_count = data["user"]["followed_by"]["count"] | |
return self.follower_count | |
if __name__ == "__main__": | |
accounts = [] | |
message = "Instagram Follower Update:" | |
for instagram_account in config.INSTAGRAM_ACCOUNTS: | |
# Can't have the @ in front for whatever reason | |
if instagram_account.startswith("@"): | |
instagram_account = instagram_account[1:] | |
account = InstagramAccount(instagram_account) | |
account.get_follower_count() | |
accounts.append(account) | |
message += "\n%s has %s follower(s)" % (account.username, account.follower_count) | |
for telegram_account in config.TELEGRAM_USERS: | |
result = urllib2.urlopen("https://api.telegram.org/bot%s/sendMessage" % config.TELEGRAM_BOT_TOKEN, | |
urllib.urlencode({"chat_id": telegram_account, "text": message})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment