Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Last active August 29, 2015 14:20

Revisions

  1. dannguyen revised this gist Apr 29, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion quickie-tweepy-listmaker.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    import json
    from os.path import expanduser
    TWITTER_CREDS_FILE = expanduser('~/.creds/me.json')
    SOURCE_URL = 'http://srccon.org/sessions/proposals/'
    SOURCE_URL = 'http://srccon.org/sessions/'
    LIST_NAME = 'srccon-2015'
    BATCH_COUNT = 50

  2. dannguyen revised this gist Apr 29, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion quickie-tweepy-listmaker.py
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@
    ###
    ### Downloading the page and getting names
    html = requests.get(SOURCE_URL).text
    names = set(re.findall('twitter.com/@?(\w+)', html))
    names = set([n.lower() for n in re.findall('twitter.com/@?(\w+)', html)])
    # whatever, good enough for me
    print("%s Twitter accounts found" %len(names))

  3. dannguyen revised this gist Apr 29, 2015. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion quickie-tweepy-listmaker.py
    Original file line number Diff line number Diff line change
    @@ -12,18 +12,23 @@
    LIST_NAME = 'srccon-2015'
    BATCH_COUNT = 50


    ###
    ### Downloading the page and getting names
    html = requests.get(SOURCE_URL).text
    names = set(re.findall('twitter.com/@?(\w+)', html))
    # whatever, good enough for me
    print("%s Twitter accounts found" %len(names))

    ###
    ### Fire up Tweepy and get an api handler
    c = json.load(open(TWITTER_CREDS_FILE))
    auth = tweepy.OAuthHandler(c['consumer_key'], c['consumer_secret'])
    auth.set_access_token(c['access_token'], c['access_token_secret'])
    api = tweepy.API(auth)
    myname = api.me().screen_name

    ###
    ### Create and add to the list
    print("Creating list %s/%s" % (myname, LIST_NAME))
    api.create_list(LIST_NAME)
    # apparently it needs to be broken up
  4. dannguyen created this gist Apr 29, 2015.
    35 changes: 35 additions & 0 deletions quickie-tweepy-listmaker.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    """
    Get all Twitter handles listed on a page, add them to a list
    """

    import tweepy
    import requests
    import re
    import json
    from os.path import expanduser
    TWITTER_CREDS_FILE = expanduser('~/.creds/me.json')
    SOURCE_URL = 'http://srccon.org/sessions/proposals/'
    LIST_NAME = 'srccon-2015'
    BATCH_COUNT = 50


    ### Downloading the page and getting names
    html = requests.get(SOURCE_URL).text
    names = set(re.findall('twitter.com/@?(\w+)', html))
    # whatever, good enough for me
    print("%s Twitter accounts found" %len(names))
    ### Fire up Tweepy and get an api handler
    c = json.load(open(TWITTER_CREDS_FILE))
    auth = tweepy.OAuthHandler(c['consumer_key'], c['consumer_secret'])
    auth.set_access_token(c['access_token'], c['access_token_secret'])
    api = tweepy.API(auth)
    myname = api.me().screen_name
    print("Creating list %s/%s" % (myname, LIST_NAME))
    api.create_list(LIST_NAME)
    # apparently it needs to be broken up
    for i in range(0, (len(names) // BATCH_COUNT) + 1):
    k = (i * 50), ((i+1) * 50)
    somenames = list(names)[k[0]:k[1]]
    print("Adding members %s - %s" % (k[0], k[0] + len(somenames)))
    api.add_list_members(somenames, slug = LIST_NAME, owner_screen_name = myname)