-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweepy3.py
91 lines (78 loc) · 11.6 KB
/
tweepy3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import json
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
#Enter Twitter API Key information
consumer_key = 'Hyka0SXV23sFCQ0U9auR2q8Au'
consumer_secret = 'JdKOI2vyzSgOJfYm1hWaMRyvx44b5xDkvmWvuZlTEmsw2Nsc1R'
access_token = '875029771108876289-425WXbLn3qSCa6Cez4TSLHpHtPkTNbo'
access_secret = 'InJJSC6A88moCtE3oXRoNmjFVRfniG8BI8In7b06ZuVR1'
#file = open("htvalley2.json", "w")
#file.write("hello")
#file.write("X,Y\n")
print("hello")
data_list = []
count = 0
latitudes = [35.685,40.6943,19.4424,19.017,-23.5587,28.67,31.2165,22.495,34.1139,23.7231,-34.6025,24.87,30.05,-22.925,34.75,39.9289,14.6042,55.7522,41.105,48.8667,37.5663,6.4433,-6.1744,23.145,41.8373,51.5,-12.048,35.6719,-4.3297,4.5964,22.5524,30.58,22.305,39.13,13.09,25.0358,12.97,13.75,31.56,29.565,25.7839,17.4,32.7936,-33.45,40.0077,-19.915,40.4,29.7869,23.0301,10.78,38.9047,33.7627,43.7,1.293,-8.8383,33.3386,41.3833,22.5804,41.805,15.5881,18.53,42.3188,-33.92,59.939,22.33,23.0489,24.6408,21.0333,20.67,-37.82,31.2,30.67,16.7834,33.5722,34.275,-30.05,21.2,23.0965,5.32,-15.7833,39.9272,25.67,35.32,32.05,45.5,26.58,-8.0756,47.6211,45.75,37.7562,-3.75,24.5204,42.3834,-12.97,35.0951,-26.17,52.5218,36.7631,41.896,39.0194,6.275,34.5167,37.9833,35.155,-33.92,32.8312,43.865,33.6,38.9228,26.46,12,32.08,9.0333,-25.42,36.8,21.5169,-1.2833,30.25,-26.1496,10.501,45.47,48.78,25.07,-6.8,44.9635,26.9211,37.875,50.1,36.09,-7.2492,38.7227,27.9942,36.675,33.595,-22.9,39.7621,22.6333,14.6504,50.2604,36.23,-29.865,50.4334,26.855,30.01,34.755,24.1521,40.6501,7.38,31.41,26.08,28.2,14.7158,38.4361,27.8504,36.056,37.4761,43.075,24.45,-2.22,5.4136,36.27,33.5,35.8668,21.17,40.7503,38.05,36.8028,48.2,43.85,15.6167,-6.95,-6.2173,49.5004,28.68,28.02,40.7498,49.2734,52.475,3.4,40.84,38.2871,53.5004,19.05,32.8925,41.3117,23.132,30.7804,39.3051,22.82,-1.45,25.625,18.4701,43.805,34.88,40.3953,5.55,37.5304,3.58,-17.7539,34.28,33.9381,35.08,38.6358,36.2333,10.73,29.3697,26.4282,45.5371,20.05,34.3878,40.6522,31.85,22.7151,-16.72,15.3547,29.4658,18.541,20.83,33.6361,33.0004,44.4334,29.88,4.0604,39.6243,23,40.08,-25.2964,34.75,-27.455,33.6,38.5667,33.872,37.3021,53.9,35.03,10.96,28.4772,34.1299,10.23,53.55,22.31,-3.1,34.4504,31.58,-2.98,50.8333,51.45,41.4767,23.25,40.82,40.4396,34.68,-23.9537,30.6501,52.25,34.0253,-20.324,-0.215,-18.9166,11,46.58,31.7503,30.82,47.5,45.0704,31.3005,30.9278,39.1412,6.69,40.7834,47.345,41.115,30.3006,24.965,36.58,36.2,32.7,39.1239,3.8667,23.37,27.1704,21.2,-16.498,19.2502,9.0833,-17.8178,39.7771,30.3704,22.84,36.7204,32.5,19.5,32.1304,28.88,-31.955,19.3304,17.73,53.83,34.68,39.986,30.2,10.015,-34.858,32.1604,-22.9,25.92,43.78,24.28,12.65,9.5315,40.2,21.15,36.7335,20.0004,41.8654,29.03,36.3355,35.2079,11.55,29.5804,24.9,50,25.38,40.8501,6.1319,-31.4,32.63,25.2866,3.1667,-25.9553,10.52,35.171,35.53,13.71,30.5333,45.77,35.8004,0.3167,38.0863,52.08,7.11,43.29,29.0004,31.47,-6.9666,28.4333,55.03,21.43,25.23,43.0642,-36.8481,31.7304,-4.2592,28.6004,25.33,-11.68,31.6904,28.6604,-25.7069,35.23,41.15,23.6833,-15.4166,31.78,36.345,56.85,34.005,21.97,22.7875,-6.15,9.92,36.995,53.3667,23.1751,9.935,8.968,56.333,42.27,51.43,48.1299,33.58,59.3508,-5.14,22.31,23.8004,44.575,46.21,29.63,30.8704,34.6,26.5944,51.2204,21.9204,37.405,31.64,-20.3676,3.2167,43.325,41.823,18.01,-32.9511,25.455,6.3405,35.4004,-9.62,42.6833,34.1495,32.1167,-7.7188,50.0833,55.8744,29.5671,30.3322,12.3703,45.4167,-34.935,28.4704,25.5701,34.1,16.52,53.195,54.99,-32.8453,22.63,38.7669,34.3456,8.4508,10.05,10.05,60.1756,55.7499,19.8957,51.083,19.41,47.38,38.8704,29.4,25.3714,40.1812,2.0667,41.725,32.68,-12.75,7.5304,44.8186,40.7774,21.2167,29.12,55.155,-5.78,38.56,55.6786,35.2191,27.83,37.2578,36.1715,-26.6496,32.02,35.1046,35.5467,31.95,35.99,37.5295,53.3331,53.55,17.6704,47.2346,48.48,36.62,40.83,50.65,23.37,37.075,6.3106,-2.516,52.35,31.7784,30.0687,14.6211,22.2769,-27.58,-33.97,46.83,4.81,35.8324,54.79,26.88,41.3304,38.1663,32.8204,24.5,7.1301,10.2469,51.92,34.73,50.93,39.9304,34.0546,12.1131,14.102,17.9771,19.7666,11.595,12.153,13.5167,41.3275,27.7167,47.9167,-1.9536,42.8731,59.9167,4.3666,8.47,33.7,6.4,17.9667,56.95,18.0864,23.6133,37.95,45.8,43.85,47.005,-13.9833,15.3333,24.4667,-20.1666,0.3854,26.2361,54.6834,42,-29.12,48.15,11.865,59.4339,-41.3,35.8997,-29.3167,51.1811,-3.3761,-35.283,28.6,46.0553,6.4833,4.8833,10.652,-9.4647,46.9167,-22.57,6.802,5.835,-8.5594,25.0834,-19.041,35.1667,-6.1833,6.932,-24.6463,6.8184,13.102,-18.133,64.15,3.75,12.2004,42.466,-11.7042,6.9,14.9167,4.1667,4.83,49.6117,27.473,-26.3167,0.3334,-9.438,12.5304,-13.8415,42.5,13.1483,-17.7334,13.4539,-21.1385,14.002,43.7396,47.1337,17.118,12.0526,-4.6166,43.9172,1.3382,7.103,15.301,17.302,17.252,-14.274,-26.4667,-8.5167,6.9166,15.2137,13.4745]
longitudes = [139.7514,-73.9249,-99.131,72.857,-46.625,77.23,121.4365,88.3247,-118.4068,90.4086,-58.3975,66.99,31.25,-43.225,135.4601,116.3883,120.9822,37.6155,29.01,2.3333,126.9997,3.3915,106.8294,113.325,-87.6862,-0.1167,-77.0501,51.4243,15.315,-74.0833,114.1221,114.27,114.185,117.2,80.28,121.5683,77.56,100.5166,74.35,106.595,-80.2102,78.48,-96.7662,-70.667,-75.1339,-43.915,-3.6834,-95.3905,72.58,106.695,-77.0163,-84.4225,-79.42,103.8558,13.2344,44.3939,2.1834,88.3299,123.45,32.5342,73.85,-71.0846,151.1852,30.316,91.8,113.7447,46.7727,105.85,-103.33,144.975,29.95,104.07,96.1667,-112.0891,108.895,-51.2,72.84,109.6091,-4.04,-47.9161,32.8644,-100.33,139.58,118.78,-73.5833,106.72,-34.9156,-122.3244,126.65,-122.443,-38.58,117.67,-83.1024,-38.48,129.01,28.03,13.4015,3.0506,12.4833,125.7547,-75.575,69.1833,23.7333,136.915,18.435,-117.1225,125.34,-7.6164,121.6298,80.32,8.52,34.77,38.7,-49.32,118.05,39.2192,36.8167,120.17,28.3299,-66.917,9.205,9.2,102.68,39.2683,-93.2678,75.81,112.5451,8.675,120.33,112.7508,-9.1449,-82.4451,116.995,130.41,-47.1,-104.8759,120.2666,121.03,19.02,37.17,30.98,30.5166,80.915,31.19,113.6651,120.6817,-73.9496,3.93,73.11,119.3,112.97,-17.4731,27.1518,112.9,103.792,126.6422,141.34,118.08,-79.92,100.3294,59.57,36.3,128.607,79.09,120.83,114.48,10.1797,16.3666,126.55,32.48,107.57,106.9723,8.47,115.88,120.6501,-73.7976,-123.1216,-1.92,-76.5,14.245,141.0217,-2.248,-98.2,13.18,69.2949,-82.3642,106.13,-76.6144,108.32,-48.48,85.13,-69.9001,87.575,117.57,49.8622,-0.2167,121.4,98.65,-63.226,117.18,-117.3948,118.33,-90.2451,-115.2654,-71.66,47.9783,50.0997,-122.65,110.32,132.4429,109.822,117.28,75.865,-49.3,44.2066,-98.5254,-72.336,106.6801,116.9789,112.53,26.0999,121.55,9.71,118.1944,120.2,113.3,-57.6415,72.35,153.0351,73.04,-121.4683,35.5097,-121.8489,27.5666,135.75,-74.8,-81.3369,118.7734,-67.98,10,73.18,-60,115.65,120.3,104.75,4.3333,7.0166,-81.6805,77.41,111.66,-79.9763,112.4701,-46.3329,113.16,21,-6.8361,-40.366,-78.5001,47.5166,76.95,125,116.48,108.4,19.0833,7.67,120.62,75.8723,-84.506,-1.63,-73.9662,123.99,122.94,-97.7517,121.2168,114.48,117.1201,51.7,-94.5541,11.5167,116.67,78.015,110.38,-68.15,73.1602,7.5333,31.0447,-86.1458,113.44,89.56,119.1001,-117.08,-70.67,114.07,105.38,115.84,-99.67,83.305,-1.58,135.17,-82.9851,71.455,76.2239,-56.1711,74.185,-43.1,114.95,11.25,109.25,-8,-13.6802,29.07,-101.7,-76.0435,73.78,123.87,111.68,127.425,-80.8304,104.9166,105.05,118.58,36.25,68.375,-73.8662,1.2228,-64.1823,116.98,51.533,101.7,32.5892,7.44,126.9104,139.705,-89.203,105.5333,4.83,50.97,32.5833,46.3012,4.27,125.63,5.375,77.7,104.77,110.42,77.3167,82.96,39.82,55.28,-87.9673,174.763,118.48,15.2847,112.33,83,27.48,-106.49,77.4084,28.2294,115.45,-8.62,86.9833,28.2833,119.97,43.145,60.6,71.535,96.085,86.1975,23.6,78.12,35.32,-1.5,79.9551,-84.0841,-79.533,44.0001,118.95,6.75,11.575,119.03,18.0973,119.432,70.8,86.42,129.59,6.14,52.57,120.1,105.92,104.8333,6.78,110.87,-5.98,74.87,-40.318,-51.2167,76.915,-71.4187,79.58,-60.6663,81.84,5.62,116.55,-35.73,23.3167,73.1995,20.0667,109.0154,14.466,-4.2507,103.7333,-81.6749,-1.5247,-75.7,138.6,117.97,-103.42,74.815,80.63,50.1513,73.4,151.815,110.15,125.4524,108.7147,124.6853,105.77,-69.3,24.9341,49.1263,75.3203,-114.08,-99.03,8.55,115.48,104.78,55.4065,44.5136,45.3667,44.7908,109.02,15.76,5.76,20.468,-111.93,81.4333,119.65,61.4387,-35.24,68.7739,12.5635,128.5836,113.15,127.0109,-86.7843,27.96,112.13,-89.9773,129.317,35.9333,119.3801,-77.4756,-6.2489,-113.5,75.9,39.7127,35,101.77,114.93,3.08,85.33,37.385,-10.8048,-44.266,4.9166,35.2066,-89.9288,-90.527,113.5678,-48.52,25.6,130.35,7.01,-78.6438,56.04,112.59,123.75,-85.6485,34.98,39.58,-73.1259,-67.5958,4.48,36.72,6.95,119.62,-5.0004,15.0491,-87.2175,-76.7674,96.1186,43.148,-86.2685,2.1167,19.8189,85.3166,106.9166,30.0605,74.5852,10.75,18.5583,-13.2342,73.1666,2.52,102.6,24.1,-15.9753,58.5933,58.3833,16,18.383,28.8577,33.7833,38.9333,54.3666,57.5,9.458,50.5831,25.3166,21.4335,26.2299,17.117,-15.5984,24.728,174.7833,14.5147,27.4833,71.4278,29.36,149.129,77.2,14.515,2.6166,114.9333,-61.517,147.1925,7.467,17.0835,-58.167,-55.167,125.5795,-77.35,-65.2595,33.3666,35.75,79.8578,25.9119,-5.2755,-59.6165,178.4417,-21.95,8.7833,-69.02,19.2663,43.2402,79.95,-23.5167,73.4999,31.58,6.13,89.639,31.1333,6.7333,159.9498,-70.029,-171.7386,1.5165,-61.2121,168.3166,-16.5917,-175.2206,-61,7.4069,9.5167,-61.85,-61.7416,55.45,12.4667,173.0176,171.38,-61.387,-62.717,-88.7671,-170.7046,31.2,179.2166,158.15,145.7546,144.7504]
# generate random integer values
from random import seed
from random import random
from random import randint
# seed random number generator
seed(5)
# generate some integers
for _ in range(100):
value = randint(0, 599)
print(value)
with open('/Users/jenniferdryden/New Unity Project (3)/Assets/Unity3DGlobe/Resources/population3.json') as json_file:
jabe = json.load(json_file)
print(jabe['AllData'][0]['Data'][0])
jabe['AllData'][0]['Data'].append(latitudes[value])
jabe['AllData'][0]['Data'].append(longitudes[value])
jabe['AllData'][0]['Data'].append(0.3 + (random() * (1.0 - 0.3)))
with open ('/Users/jenniferdryden/New Unity Project (3)/Assets/Unity3DGlobe/Resources/population3.json', 'w') as outfile:
json.dump(jabe, outfile)
time.sleep(0.5)
class listener(StreamListener):
def on_data(self, data):
global count
#How many tweets you want to find, could change to time based
if count <= 2000:
# file = open("htvalley8.json", "w")
# file.write("X,Y\n")
json_data = json.loads(data)
coords = json_data["coordinates"]
if coords is not None:
print(coords["coordinates"])
lon = coords["coordinates"][0]
lat = coords["coordinates"][1]
print(6)
data_list.append(json_data)
print(7)
#with open("/Users/jenniferdryden/New Unity Project (3)/Assets/Unity3DGlobe/Resources/htvalley8.json", "a") as file:
with open('/Users/jenniferdryden/New Unity Project (3)/Assets/Unity3DGlobe/Resources/population2.json') as json_file:
jabe = json.load(json_file)
print(jabe['AllData'][0]['Data'][0])
jabe['AllData'][0]['Data'].append(lat)
jabe['AllData'][0]['Data'].append(lon)
jabe['AllData'][0]['Data'].append(0.7)
with open ('/Users/jenniferdryden/New Unity Project (3)/Assets/Unity3DGlobe/Resources/population2.json', 'w') as outfile:
json.dump(jabe, outfile)
print(8)
count += 1
print(9)
# file.close()
print(11)
return True
else:
file.close()
return False
def on_error(self, status):
print(status)
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
twitterStream = Stream(auth, listener())
#What you want to search for here
twitterStream.filter(track=["coronavirus"])