-
-
Save martindale/9ae0d45dcd57b384feae0566fd82d9a1 to your computer and use it in GitHub Desktop.
Follow Friday
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
# -*- coding: utf-8 -*- | |
from TwitterAPI import TwitterAPI | |
from collections import Counter | |
import json | |
import time | |
import logging | |
# Edit ff.py for your account. Go to https://apps.twitter.com/ to get your API keys. | |
# Don't forget to fill in your screen name (or someone else's). | |
CONSUMER_KEY = '' | |
CONSUMER_SECRET = '' | |
ACCESS_TOKEN = '' | |
ACCESS_TOKEN_SECRET = '' | |
USER = 'eiaine' | |
# adjust according to desired timeframe | |
# I have it starting from a year ago | |
YEAR_AGO = 948009043389333504 | |
def main(): | |
logging.basicConfig(level=logging.INFO) | |
api = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
newest = None | |
counter = Counter([]) | |
while True: | |
if newest and int(newest) < YEAR_AGO: | |
break | |
favs_raw = api.request('favorites/list', | |
{'screen_name': USER, 'count': 200, 'since_id': YEAR_AGO, 'max_id': newest, 'include_entities': False}) | |
favs = json.loads(favs_raw.response.text) | |
if len(favs) == 0: | |
break | |
newest = favs[-1]["id"] - 1 | |
logging.info(newest) | |
friends = [f["user"]["id_str"] for f in favs if not f["in_reply_to_status_id"]] | |
counter += Counter(friends) | |
logging.info(counter.most_common(50)) | |
# Optional; use if rate limiting is an issue | |
# time.sleep(20) | |
top = counter.most_common(20) | |
top = [t[0] for t in top] | |
friends_raw = api.request('users/lookup', {'user_id': top}) | |
friends = json.loads(friends_raw.response.text) | |
for friend in friends: | |
print(friend["screen_name"]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment