Example #1
0
def runStreamer(kind, appname, cred_file, rootdir, fileprefix, input_list, langs=None):
    init_msg(kind, appname, cred_file, rootdir, fileprefix)
    AC = AuthClient(cred_file)
    api, auth = AC.create_tweepy_client(appname)
    while True:
        try:
            st = twitterStream.Streamer(api, auth, rootdir, fileprefix)
            if kind == "filter":
                st.streamFilter(input_list, langs)
            elif kind == "geo":
                st.streamLocation(input_list)
            elif kind == "userlist" or kind == "userlist_newsorg":
                st.streamFriends()
            elif kind == "random":
                st.streamRandom(langs)
            else:
                print("Incorrect stream kind. Must be one of 'filter', 'random' or 'userlist'.")
                exit(0)
        except http.client.IncompleteRead:
            continue
        except urllib3.exceptions.ReadTimeoutError:
            continue
        except (KeyboardInterrupt, SystemExit):
            st.disconnect()
            print("*    KeyboardInterrupt or SystemExit caught  ")
            exit(0)
        except:
            continue
Example #2
0
def make_friends(appname, cred_file):

    appname = "CanPol"
    appname = "xdatax"
    AC = AuthClient(cred_file)
    access_token, access_token_secret, consumer_key, consumer_secret = AC.get_credentials(appname)
    client = TwitterRestClient(consumer_key, consumer_secret)
    usr = "******"

    newfriend = client.add_friend(usr)
    profile = client.get_single_user(usr)
Example #3
0
def update_verified(appname, cred_file, verifiedFile):
    usr = "******"
    updatedVerifedFile = ".tempUpdatedVerifiedFile.json"
    AC = AuthClient(cred_file)
    access_token, access_token_secret, consumer_key, consumer_secret = AC.get_credentials(appname)
    client = TwitterRestClient(consumer_key, consumer_secret)
    profile = client.get_single_user(usr)
    num_friends = profile['friends_count']
    num_required = sum(1 for i in (line.strip() for line in open(verifiedFile))) - num_friends
    fo = open(updatedVerifedFile, "w")
    num_results = 0
    while num_results < num_required:
        result = client.get_friends(usr)
        next_cursor = result['next_cursor_str']
        users = result['users']
        num_results += len(users)
        print("Total number downloaded: {}".format(num_results))
        for u in users:
            json_str = json.dumps(u)
            fo.write(json_str + "\n")
        time.sleep(5)
    fo.close()
    mergedVerified(verifiedFile, updatedVerifedFile)
def run(streamkind, appname, cred_file, rootdir, fileprefix, input_list):
    init_msg(streamkind, appname, cred_file, rootdir, fileprefix)
    AC = AuthClient(cred_file)
    api, auth = AC.create_tweepy_client(appname)
    langs = ["en", "fr"]
    # track_terms = [t.strip().split("\t")[0].strip() for t in open("election2015Keywords.txt") if not t.startswith("#")]
    # print(",".join(track_terms))

    while True:
        print("Streamkind is ..... {}".format(streamkind))
        try:
            st = Streamer(api, auth, rootdir, fileprefix)
            if streamkind == "filter":
                print("FILTERING TRACK TERMS")
                # st.streamFilter(track_terms, langs)
                st.streamFilter(input_list, langs)
            elif streamkind == "geo":
                print("FILTERING GEO BOUNDS")
                # canada_geo_bounds = [-141.0, 41.7, -52.6, 83.1]
                # st.streamLocation(canada_geo_bounds)
                st.streamLocation(input_list)
            elif streamkind == "userlist" or streamkind == "userlist_newsorg":
                print("STREAMING USER TIMELINE")
                st.streamFriends()
            else:
                print("Incorrect stream kind. Must be one of 'filter', 'random' or 'userlist'.")
                exit(0)
        except http.client.IncompleteRead:
            continue
        except urllib3.exceptions.ReadTimeoutError:
            continue
        except (KeyboardInterrupt, SystemExit):
            st.disconnect()
            print("*    KeyboardInterrupt or SystemExit caught  ")
            break
        except:
            continue
import json
import sys
import time
# local imports
# UGLY HACK - FIND A BETTER WAY TO IMPORT
# sys.path.insert(0, "../")
from AuthClient import *

from twitter import *


appname = "CanPol"
cred_file = "../credentials.json"
AC = AuthClient(cred_file)
access_token, access_token_secret, consumer_key, consumer_secret = AC.get_credentials(appname)
# client = TwitterRestClient(consumer_key, consumer_secret)

# https://api.twitter.com/1.1/friendships/create.json



t = Twitter(auth=OAuth(access_token, access_token_secret, consumer_key, consumer_secret))
# t.friendships.create(screen_name="dmrider")




'''
PURPOSE:
    given a list of screen_names for valid twitter accounts, add them to "my" accound as friends