-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhawkeye.py
268 lines (220 loc) · 10.5 KB
/
hawkeye.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/env python
"""
eagle_prefetch.py
Designed to scan Twitter for viable accounts, for established parameters
Selects the userd_ids of the top 100 followed and follower accounts
Solomon Abiola
http://www.ewizardii.com
"""
## Import Modules
from random import shuffle
import os
import time
from threading import Thread
import json
import gzip
import oauth2 as oauth
#Run main program
#Creates a thread of network calls to Twitter passes through VPN and Proxy
def lvl1():
## Thread loop - birdofprey
class birdofprey(Thread):
def __init__ (self,ip,id,api_name,oauth_token,oauth_token_secret):
Thread.__init__(self)
self.ip = ip
self.id = id
self.api_name = api_name
self.oauth_token = oauth_token
self.oauth_token_secret = oauth_token_secret
def run(self):
## OAuth Dance!
consumer_key = '3y1428CJNYI3uqgW8oFcEA'
consumer_secret = 'GPpj8e6jOVkecaxfb5GmgIvI8ObnqYzo80oXt8v3c'
consumer = oauth.Consumer(consumer_key, consumer_secret)
token = oauth.Token(self.oauth_token, self.oauth_token_secret)
client = oauth.Client(consumer, token)
PROXY_DOMAIN = "twitter" + str(self.api_name) + "-ewizardii.apigee.com"
try:
pidgin = ("http://twitter" + str(self.api_name) + "-ewizardii.apigee.com/1/statuses/user_timeline.json?user_id="+ str(self.ip) + "?count=200")
resp, content = client.request(pidgin, "GET", PROXY_DOMAIN)
output = str(content)
fileObj = open("C:/Twitter/json_scrap/temp_" + str(self.ip) + ".json","w")
fileObj.write(output)
fileObj.close()
## Grab the tweets per user
## Create scratch for JSON file
json_data = open("C:/Twitter/json_scrap/temp_" + str(self.ip) + ".json")
data = json.load(json_data)
## Get selected data from JSON file
i = 0
twitter_data = {}
for record in data:
twitter_data[i] = {}
twitter_data[i]['created_at'] = data[i]['created_at']
twitter_data[i]['favorited'] = data[i]['favorited']
twitter_data[i]['id_str'] = data[i]['id_str']
twitter_data[i]['in_reply_to_status_id_str'] = data[i]['in_reply_to_status_id_str']
twitter_data[i]['in_reply_to_user_id_str'] = data[i]['in_reply_to_user_id_str']
twitter_data[i]['retweet_count'] = data[i]['retweet_count']
twitter_data[i]['retweeted'] = data[i]['retweeted']
twitter_data[i]['text'] = data[i]['text']
record_id = data[i]['user']
twitter_data[i]['id_str'] = record_id['id_str']
twitter_data[i]['id'] = record_id['id']
twitter_data[i]['location'] = record_id['location']
twitter_data[i]['time_zone'] = record_id['time_zone']
twitter_data[i]['followers_count'] = record_id['followers_count']
twitter_data[i]['created_at'] = record_id['created_at']
twitter_data[i]['statuses_count'] = record_id['statuses_count']
twitter_data[i]['verified'] = record_id['verified']
twitter_data[i]['screen_name'] = record_id['screen_name']
i = i + 1
## Write JSON and compress it into Gzip
with open('C:/Twitter/json/user_' + str(self.ip) + '_id_' + str(record_id['id_str'])+ '.json', mode='w') as f:
json.dump(twitter_data, f, indent=2, encoding='utf-8')
# f_in = open('C:/Twitter/json/user_' + str(self.ip) + '_id_' + str(record_id['id_str'])+ '.json', 'rb')
# f_out = gzip.open('C:/Twitter/json/user_' + str(self.ip) + '_id_' + str(record_id['id_str'])+ '.json.gz', 'wb')
# f_out.writelines(f_in)
# f_out.close()
# f_in.close()
# os.remove('C:/Twitter/json_scrap/temp_" + str(self.ip) + ".json')
self.storage_i = i
self.passed = 1
self.block = 0
## Display the status of the project
## print str(i) + " tweets found for " + str(self.ip) + " \n"
## print "Completed"
## Log the status of the project
with open('C:/Twitter/status.txt', mode='a') as a_file:
new_iii = str(i) + " tweets found for " + str(self.ip) + " \n"
a_file.write(new_iii)
a_file.write(new_iv)
except:
pass
# with open('C:/Twitter/error_log.txt', mode='a') as a_file:
# new_i = str(self.ip) + '\t R:' + str(content) + '\n'
# a_file.write(new_i)
def join(self,timeout=None):
Thread.join(self, timeout)
## Necessary Variables
source = []
json_data2 = open("C:/Twitter/commodore.json")
data2 = json.load(json_data2)
id = -1
## In manual mode you will want to set this k
k = 0
## Load the Users into the RAM
a = set()
for i in range(1):
with open("C:/Twitter/user/user_{0}.json".format(i)) as json_data:
data = json.load(json_data)
a.update(d['su'] for d in data)
print("Cleaned length is {0}".format(len(a)))
# Take Cleaned List and Randomize it for Analysis
new = list(a)
shuffle(new)
# Delete old Arrays to clear up RAM
del a
del data
## Massive For-loop used to call the correct APIs and Twitter Users
for hour in range(3):
for host in range(0,9750):
## User 1 and 2 in API 1
ip = new[k]
id = id + 1
oauth_token = data2[0]['oauth_token']
oauth_token_secret = data2[0]['oauth_token_secret']
urlv = birdofprey(ip,id,1,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
ip = new[k]
id = id + 1
oauth_token = data2[1]['oauth_token']
oauth_token_secret = data2[1]['oauth_token_secret']
urlv = birdofprey(ip,id,1,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
## User 3 in API 1
ip = new[k]
id = id + 1
oauth_token = data2[2]['oauth_token']
oauth_token_secret = data2[2]['oauth_token_secret']
urlv = birdofprey(ip,id,1,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
ip = new[k]
id = id + 1
oauth_token = data2[0]['oauth_token']
oauth_token_secret = data2[0]['oauth_token_secret']
urlv = birdofprey(ip,id,2,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
## User 3 in API 2
ip = new[k]
id = id + 1
oauth_token = data2[1]['oauth_token']
oauth_token_secret = data2[1]['oauth_token_secret']
urlv = birdofprey(ip,id,2,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
## User 3 in API 2
ip = new[k]
id = id + 1
oauth_token = data2[2]['oauth_token']
oauth_token_secret = data2[2]['oauth_token_secret']
urlv = birdofprey(ip,id,2,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
for host in range(0,9750):
## User 1 and 2 in API 1
ip = new[k]
id = id + 1
oauth_token = data2[0]['oauth_token']
oauth_token_secret = data2[0]['oauth_token_secret']
urlv = birdofprey(ip,id,1,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
ip = new[k]
id = id + 1
oauth_token = data2[1]['oauth_token']
oauth_token_secret = data2[1]['oauth_token_secret']
urlv = birdofprey(ip,id,1,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
## User 1 and 2 in API 2
ip = new[k]
id = id + 1
oauth_token = data2[0]['oauth_token']
oauth_token_secret = data2[0]['oauth_token_secret']
urlv = birdofprey(ip,id,2,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
ip = new[k]
id = id + 1
oauth_token = data2[1]['oauth_token']
oauth_token_secret = data2[1]['oauth_token_secret']
urlv = birdofprey(ip,id,2,oauth_token,oauth_token_secret)
urlv.start()
source.append(urlv)
k = k + 1
time.sleep(4200)
print "Done Sleeping"
print "Complete Hour: " + str(hour)
## Timing Script
def time_code(arg):
'''For running code once,and take time'''
start = time.clock()
arg()
end = time.clock()
print 'Code time %.6f seconds' % (end - start)
if __name__ == '__main__':
time_code(lvl1)