Skip to content
Snippets Groups Projects
Commit 75721e7a authored by Felipe Ramos's avatar Felipe Ramos
Browse files

open file in case it doesnt exist

parent 150f1d54
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import sys
collector_type = sys.argv[1]
cityCoord = '-34.926068,138.736903,60km'
#change code to your current Twitter account
API_key = 'SZS77byadyNlV99Vc0JQvDNS3'
......@@ -14,8 +15,12 @@ baerer_token = 'AAAAAAAAAAAAAAAAAAAAAIq9OwEAAAAAZWncNeg2Hjj80ehT39b%2FenLaHI0%3D
access_token = "1386612665682853892-Tp6J5KfT4Wr8gsIPYSr2G5W15axUlj"
access_secret = "hN59hNhidGKLJpsJ8nX8Dr2EEB4m9ny0w70K2Fd0dpY8Q"
import os.path
outfile = open('twt_stream.json', 'r+', encoding ='utf-8')
if os.path.isfile('twt_stream.json'):
outfile = open('twt_stream.json', 'a+', encoding ='utf-8')
else:
outfile = open('twt_stream.json', 'w+', encoding ='utf-8')
class StreamListener(tweepy.StreamListener):
......@@ -78,12 +83,17 @@ if __name__ == "__main__":
tags=['AFL', 'tennis', 'footie', 'swimming', 'AustraliaOpen', 'soccer']
box = [144.5,-38.2,145.49,-37.41] #Melb box
#box = [144.5,-38.2,145.49,-37.41] #Melb box
box = [138.01,-35.5,139.4,-34.4] #Adelaide
stream.filter(track=tags, locations= box, languages=["en"])
stream.filter(track=tags, locations= box, languages=["en"])
#north: -37.41,
#south: -38.20311,
#east: 145.41,
#west: 144.5,
elif collector_type == 'search':
......@@ -91,7 +101,7 @@ if __name__ == "__main__":
twts = {}
# capure the most data
for tweet in api.search(q="AFL OR tennis OR footie OR swimming OR AustraliaOpen OR soccer", geocode='-37.7980882,144.9334346,60km', count=100, tweet_mode="extended"):
for tweet in api.search(q="AFL OR tennis OR footie OR swimming OR AustraliaOpen OR soccer", geocode=cityCoord, count=100, tweet_mode="extended"):
#tweet = tweet._json
print("")
print(tweet.user.screen_name)
......@@ -109,7 +119,7 @@ if __name__ == "__main__":
# twts[tweet.id] = tweet
# Get responses
for tweet in api.search(q='to:'+ v.user.screen_name, geocode='-37.7980882,144.9334346,60km', count=100, sinceId = v.id):
for tweet in api.search(q='to:'+ v.user.screen_name, geocode=cityCoord, count=100, sinceId = v.id):
if tweet.in_reply_to_status_id_str == v.id_str:
replies.append(tweet)
twts[tweet.id_str] = tweet
......@@ -118,7 +128,7 @@ if __name__ == "__main__":
# loops to get all responses of responses
while replies:
current = replies.pop(0)
for tweet in api.search(q='to:'+ current.user.screen_name, geocode='-37.7980882,144.9334346,60km', count=100, sinceId = current.id):
for tweet in api.search(q='to:'+ current.user.screen_name, geocode=cityCoord, count=100, sinceId = current.id):
if tweet.in_reply_to_status_id_str == current.id_str:
replies.append(tweet)
twts[tweet.id_str] = tweet
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment