def StreamLocation(loc, verbose): if loc != "all" and loc in locationbox.keys(): box = locationbox[loc] elif loc == "all": box = [] for citygrid in locationbox.values(): box += citygrid else: raise ValueError("Location not known ; How about these ones %s ?" % locationbox.keys()) listen = Listener(arg=loc, verbose=verbose) stream = tweepy.Stream(auth, listen) print "Streaming started at %s location..." % (loc) stream.filter(locations=box)
words = Placenames[loc] else: raise ValueError("Location not known ; How about these ones %s ?" % Placenames.keys()) listen = Listener(arg=loc, prefix="placename", verbose=verbose) stream = tweepy.Stream(auth, listen) print "Streaming started using %s location from Placenames..." % (loc) stream.filter(track=words) if __name__ == "__main__": if sys.argv[1].split("-")[0] == "Location": if sys.argv[1].split("-")[1] in locationbox.keys() or sys.argv[1].split("-")[1] == "all": if len(sys.argv) > 2: verbose = True if "-v" in sys.argv[2:] else False else: verbose = False StreamLocation(loc=sys.argv[1].split("-")[1], verbose=verbose) else: raise KeyError("Geocode for location not known, try one of these <all> or %s" % locationbox.keys()) elif sys.argv[1].split("-")[0] == "Track": if sys.argv[1].split("-")[1] in Placenames.keys(): if len(sys.argv) > 2: verbose = True if "-v" in sys.argv[2:] else False else: verbose = False StreamTrack(loc=sys.argv[1].split("-")[1], verbose=verbose)