Created
April 25, 2017 06:36
-
-
Save bobquest33/cf5db632881f4edc49c530f912827c30 to your computer and use it in GitHub Desktop.
100 Scripts in 30 Days challenge: Script 18,19,20 - Getting trending topics on Twitter using Tweepy
This file contains 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
APP_NAME = "" | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET = "" | |
access_token = "" | |
access_token_secret = "" |
This file contains 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 -*- | |
import os | |
import sys | |
import twitter | |
import toml | |
import glob | |
import json | |
import tweepy | |
for conffilename in glob.glob('conf\\*.toml'): | |
with open(conffilename) as conffile: | |
config = toml.loads(conffile.read()) | |
APP_NAME = config["APP_NAME"] | |
CONSUMER_KEY = config["CONSUMER_KEY"] | |
CONSUMER_SECRET = config["CONSUMER_SECRET"] | |
access_token = config["access_token"] | |
access_token_secret = config["access_token_secret"] | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
available_loc = api.trends_available() | |
print(json.dumps(available_loc,indent=1)) | |
with open("available_locs_for_trend.json","w") as wp: | |
wp.write(json.dumps(available_loc, indent=1)) |
This file contains 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
import geocoder | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import twitter | |
import toml | |
import glob | |
import json | |
import tweepy | |
loc = " ".join(sys.argv[1:]) | |
for conffilename in glob.glob('conf\\*.toml'): | |
with open(conffilename) as conffile: | |
config = toml.loads(conffile.read()) | |
APP_NAME = config["APP_NAME"] | |
CONSUMER_KEY = config["CONSUMER_KEY"] | |
CONSUMER_SECRET = config["CONSUMER_SECRET"] | |
access_token = config["access_token"] | |
access_token_secret = config["access_token_secret"] | |
g = geocoder.osm(loc) | |
print(g) | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
closest_loc = api.trends_closest(g.lat,g.lng) | |
print(json.dumps(closest_loc,indent=1)) | |
with open("closest_loc_for_trend.json","w") as wp: | |
wp.write(json.dumps(closest_loc, indent=1)) |
This file contains 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 -*- | |
import geocoder | |
import os | |
import sys | |
import toml | |
import glob | |
import json | |
import tweepy | |
loc = " ".join(sys.argv[1:]) | |
for conffilename in glob.glob('conf\\*.toml'): | |
with open(conffilename) as conffile: | |
config = toml.loads(conffile.read()) | |
APP_NAME = config["APP_NAME"] | |
CONSUMER_KEY = config["CONSUMER_KEY"] | |
CONSUMER_SECRET = config["CONSUMER_SECRET"] | |
access_token = config["access_token"] | |
access_token_secret = config["access_token_secret"] | |
g = geocoder.osm(loc) | |
print(g) | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
closest_loc = api.trends_closest(g.lat,g.lng) | |
print(json.dumps(closest_loc,indent=1)) | |
trends = [] | |
for loc in closest_loc: | |
closest_trend = api.trends_place(loc["woeid"]) | |
trends.append(closest_trend) | |
print(json.dumps(trends,indent=1)) | |
with open("twitter_loc_trend.json","w") as wp: | |
wp.write(json.dumps(trends, indent=1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment