-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.py
More file actions
72 lines (56 loc) · 2.6 KB
/
exec.py
File metadata and controls
72 lines (56 loc) · 2.6 KB
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
# -*- coding: utf-8 -*-
import sys
from geopy import geocoders
from geoteste import TrataGeo, listener
from tweepy import OAuthHandler
from tweepy import Stream
#Change them with your authotenfication tokens
ckey = 'B4qL5xWeoAtT4HDeM8fPRTUau'
csecret ='XpctNz94QrAmv7ybKHNS70TK9DhD8LBadFNo4Rv3rxQlR1e7bd'
atoken = '138579781-WdFq2TX2MSIW1Gh8JsQzY4iWqaO032TLVqUVjhSc'
asecret = 'yHE559wpPnHJmFzeFY9JOHSUO5zSQhxGhJnZcGNEOWArR'
#################################
help_str='''
Coletor de tweets. Desenvolvimento por Alexandre Prates
Modo de executar:
$ python exec.py "Cidade" "raio em relação ao centro da cidade" "linguagem"
Nome da cidade - Nome da ciodade que deseja coletar as twets, esse parametro é obrigatório
Raio em relação ao centro da cidade - essa é a distância em km do raio em relação ao coordenadas do centro da cidade, esse campo é obrigatório
linguagem - idioma da tweet, esse parametro eh opcional.
Exemplo de execucao;
$ python exec.py "São Paulo" 10
Coleta as tweets da cidade de são paulo em um raio de 10 km.
$ python exec.py "São Paulo" 10 pt
Coleta as tweets da cidade de são paulo em um raio de 10 km com idioma portugues
'''
if __name__ == "__main__":
argumentos = sys.argv
if len(argumentos) > 1:
if (len(argumentos) == 2 and ( argumentos[1] == "-h" or argumentos[1] == "--help" ) ):
print help_str
elif ( len(argumentos) > 2 and len(argumentos) < 5 ) :
if len(argumentos) == 4:
lang = argumentos[3]
else:
lang = None
adress=str(argumentos[1]) #Location (City name, adress...)
halfradius=float(argumentos[2]) #Radius in Km of the Bounding Box
g = geocoders.GoogleV3()
place, (lat, lng) = g.geocode(adress)
geo = TrataGeo()
location = [geo.bounding_box(lng,lat,halfradius)[0],geo.bounding_box(lng,lat,halfradius)[1],geo.bounding_box(lng,lat,halfradius)[2],geo.bounding_box(lng,lat,halfradius)[3]]
# print "Location of "+ adress+" :",lng,lat
#location = ','.join([ str(i) for i in location])
print location
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
while True:
try:
twitterStream = Stream(auth, listener(lang=lang))
twitterStream.filter(locations=location)
except Exception as e:
print e
else:
print "use a opção -h ou --help para opter ajuda."
else:
print "use a opção -h ou --help para opter ajuda."