Пример #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
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