-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgeotweet.py
305 lines (269 loc) · 10.5 KB
/
geotweet.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/python -u
#-*- coding: utf-8 -*-
#########################################################################
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, #
# MA 02110-1301, USA. #
############################# DISCALIMER ################################
# Usage of this software for probing/attacking targets without prior #
# mutual consent, is illegal. It's the end user's responsability to #
# obey alla applicable local laws. Developers assume no liability and #
# are not responible for any missue or damage caused by thi program #
#########################################################################
import tweepy, geopy, sys, getopt, time, folium, SimpleHTTPServer, SocketServer, webbrowser
#Autenticazione
from geopy.geocoders import Nominatim
from keys import keys
SCREEN_NAME = keys['screen_name']
CONSUMER_KEY = keys['consumer_key']
CONSUMER_SECRET = keys['consumer_secret']
ACCESS_TOKEN = keys['access_token']
ACCESS_TOKEN_SECRET = keys['access_token_secret']
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
geolocator = Nominatim()
number = 20
TAG = "x"
ZONE = "IT"
check_ZONE = "x"
MAPS = "x"
check_USER = "x"
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
def has_colours(stream):
if not (hasattr(stream, "isatty") and stream.isatty()):
return False
#if not hasattr(stream, "isatty"):
# return False
#if not stream.isatty():
# return False
try:
import curses
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
# TODO: log console
return False
has_colours = has_colours(sys.stdout)
def printout(text, colour=WHITE):
if has_colours:
seq = "\x1b[1;%dm" % (30+colour) + text + "\x1b[0m"
sys.stdout.write(seq)
else:
sys.stdout.write(text)
def logo_geotweet():
print "----------------------------------------------"
printout(" _____ _____ _ " + "\n", GREEN)
printout("| __|___ ___|_ _|_ _ _ ___ ___| |_ " + "\n", BLUE)
printout("| | | -_| . | | | | | | | -_| -_| _|" + "\n", YELLOW)
printout("|_____|___|___| |_| |_____|___|___|_| " + "\n", MAGENTA)
printout(" Another way to use twitter " + "\n", CYAN)
def credit():
printout("[+]" , GREEN)
print ("Create by @Pinperepette, @Daniele_kk, @eddy_mane, @porelmorro, @grostein, @ludo237"+ "\n")
def usage():
logo_geotweet()
printout("[USAGE:] " + "\n" , GREEN)
print (sys.argv[0] + " " + "[-h|--help] [-t|--tag] [-u|--user] "+ "\n"+"[-z|--zone] [-l|--line] [-n|--number] [-m|--maps]")
print "----------------------------------------------"
printout("[EXAMPLE USER:] " , BLUE)
print (" " +sys.argv[0] + " " + "-u Pinperepette")
printout("[EXAMPLE ZONE:] ", YELLOW)
print (" " +sys.argv[0] + " " + "-z IT")
printout("[EXAMPLE TAG:] ", RED)
print (" " +sys.argv[0] + " " + "-t Coccodio")
printout("[EXAMPLE LINE:] ", MAGENTA)
print (" " +sys.argv[0] + " " + "-l Pinperepette"+ "\n")
credit()
def http_run():
printout("[HTTP RUN:] ", YELLOW)
#Localhost 8000 is busy most of the time
print " localhost:1337 "
printout("[STOP:] ", RED)
print " press ctrl + c "
try:
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", 1337), Handler)
httpd.serve_forever()
except KeyboardInterrupt:
httpd.shutdown()
httpd.server_close()
def search_user():
user = api.get_user(arg_user_search, include_entities=1)
print "----------------------------------------------"
printout("[NAME:] ", GREEN)
print user.name.encode('utf-8')
printout("[ALIAS:] ", BLUE)
print "@" + user.screen_name.encode('utf-8')
printout("[ID:] ", RED)
print user.id
printout("[URL:] ", BLACK)
print user.url
printout("[GEOLOCATION:] ", MAGENTA)
if user.status.geo == None:
print user.status.geo
else:
print user.status.geo['coordinates']
location = geolocator.reverse(user.status.geo['coordinates'],timeout=20)
print location.address.encode('utf-8')
printout("[FOLLOWERS:] ", GREEN)
print user.followers_count
printout("[FRIENDS:] ", BLUE)
print user.friends_count
printout("[BIO:] ", WHITE)
print user.description.encode('utf-8')
credit()
def timeline_user():
cont = 0
user = api.user_timeline(screen_name, count=number)
for tweet in user:
print "----------------------------------------------"
printout("[TWEET:] ", YELLOW)
print " " + tweet.text.encode('utf-8')
printout("[SOURCE:] ", GREEN)
print tweet.source.encode('utf-8')
printout("[DATE:] ", RED)
print tweet.created_at
printout("[RT:] ", BLUE)
print tweet.retweet_count
printout("[FAV:] ", WHITE)
print tweet.favorite_count
if tweet.geo == None:
printout("[GEOLOCATION:] ", MAGENTA)
print tweet.geo
else:
printout("[GEOLOCATION:] ", MAGENTA)
print tweet.geo['coordinates']
location = geolocator.reverse(tweet.geo['coordinates'],timeout=20)
printout("[ADDRESS:] ", CYAN)
print location.address.encode('utf-8')
if cont == 0:
map_1 = folium.Map(location=tweet.geo['coordinates'], zoom_start=4, width=1800, height =1200)
cont = cont + 1
else:
cont = cont + 1
map_1.simple_marker(location=tweet.geo['coordinates'],popup=tweet.text.encode('utf-8'))
location = geolocator.reverse(tweet.geo['coordinates'],timeout=20)
if MAPS == "y":
map_1.create_map(path='maps_user.html')
credit()
def search_tag():
c = tweepy.Cursor(api.search, q=TAG)
for tweet in c.items(int(number)):
print "------------------------------------------------"
printout("[NAME:] ", GREEN)
print tweet.user.name.encode('utf-8')
printout("[ALLIAS:] ", BLUE)
print "@" + tweet.user.screen_name.encode('utf-8')
printout("[TWEET:] ", YELLOW)
print " " + tweet.text.encode('utf-8')
printout("[ID:] ", RED)
print tweet.user.id
printout("[GEOLOCATION:] ", MAGENTA)
if tweet.coordinates == None:
print tweet.coordinates
else:
print tweet.coordinates['coordinates']
location = geolocator.reverse(tweet.coordinates['coordinates'],timeout=20)
print location.address.encode('utf-8')
printout("[SOURCE:] ", BLACK)
print tweet.source.encode('utf-8')
printout("[TWEET ID:] ", WHITE)
print tweet.id
printout("[NUMBER RT:] ", YELLOW)
print tweet.retweet_count
if MAPS == "y":
print "------------------------------------------------"
printout("[!] ", RED)
print "in search tag, maps are not abilited"
else:
sys.exit(2)
credit()
def search_zone_map():
cont = 0
places = api.geo_search(query=ZONE, granularity="country")
place_id = places[0].id
tweets = api.search(q="place:%s" % place_id,count=number)
for tweet in tweets:
print "------------------------------------------------"
printout("[NAME:] ", GREEN)
print tweet.user.name.encode('utf-8')
printout("[ALIAS:] ", BLUE)
print "@" + tweet.user.screen_name.encode('utf-8')
printout("[TWEET:] ", YELLOW)
print " " + tweet.text.encode('utf-8')
printout("[GEOLOCATION:] ", MAGENTA)
print tweet.geo['coordinates']
location = geolocator.reverse(tweet.geo['coordinates'],timeout=20)
printout("[ADDRESS:] ", CYAN)
print location.address.encode('utf-8')
if cont == 0:
map_1 = folium.Map(location=tweet.geo['coordinates'], zoom_start=4, width=1800, height =1200)
cont = cont + 1
else:
cont = cont + 1
map_1.simple_marker(location=tweet.geo['coordinates'],popup=tweet.user.screen_name.encode('utf-8'))
location = geolocator.reverse(tweet.geo['coordinates'],timeout=20)
if MAPS == "y":
map_1.create_map(path='maps.html')
else:
sys.exit(2)
credit()
def getopt_menu():
global ZONE
global arg_user_search
global screen_name
global TAG
global number
global check_ZONE
global MAPS
global check_USER
try:
opts, args = getopt.getopt(sys.argv[1:], "hz:t:u:l:n:ms", ["help", "zone=","tag=","user=","line=","number=","maps=","server="])
except getopt.GetoptError as err:
print str(err)
sys.exit(2)
for o, a in opts:
if o in ("-n", "--number"):
number = a
elif o in ("-m", "--maps"):
MAPS = "y"
elif o in ("-t", "--tag"):
TAG = a
elif o in ("-l", "--line"):
screen_name = a
check_USER = "y"
elif o in ("-u", "--user"):
arg_user_search = a
search_user()
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-z", "--zone"):
check_ZONE = "y"
ZONE = a
elif o in ("-s", "--server"):
http_run()
else:
print "CoccoDio"
def main():
getopt_menu()
if TAG != "x":
search_tag()
if check_ZONE != "x":
search_zone_map()
if check_USER != "x":
timeline_user()
if __name__ == "__main__":
main()