-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpronto
executable file
·166 lines (143 loc) · 5.64 KB
/
pronto
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: binary -*-
# Author: https://twitter.com/GuerrillaWF
# Native imports
import re
import os
import sys
import json
import time
import string
import getopt
from core.libs import database
from core.libs.twitter import operations
from core.libs.functions import Utilities
from core.info import notifications
class ProntoRuntimeError(RuntimeError):
pass
class Pronto(object):
def __init__(self):
self.verbose = True
self.__options = {}
self.__util = Utilities()
self.__notify = notifications()
self.__twitter = operations()
def __tell(self, text, sep=' ', end='\n', stream=sys.stdout, flush=False):
if self.verbose or stream != sys.stdout:
stream.write(text)
if end is not None:
stream.write(end)
else:
if sep is not None:
stream.write(sep)
if flush or end is None:
stream.flush()
def boot(self):
args, commands = getopt.getopt(sys.argv[1:], 'u:')
args = dict(args)
if len(commands) == 1 and commands[0] in self.commands:
command = commands[0]
else:
# if no args or options exist, show the help.
command = 'help'
args = {}
# if everything checks out. Run the desired command with the desired option(s)
func = self.commands[command]
req_params, opt_params = func.cli_options
for param in req_params:
if param not in args:
raise ProntoRuntimeError("The command '%s' requires the " \
"option '%s'. See 'help'." % \
(command, param))
for arg, value in args.iteritems():
if arg in req_params or arg in opt_params:
if arg == '-u':
self.__options['username'] = value.lower()
# Prevent messages from corrupting stdout
if value == '-':
self.verbose = False
else:
raise ProntoRuntimeError("The command '%s' ignores the " \
"option '%s'." % (command, arg))
self.__tell("\nPronto | GuerrillaWarfare - https://github.com/GuerrillaWarfare")
try:
func(self, **self.__options) # A wild TypeError appears from the tall grass.
# Will have to fix this TypeError later. Not sure what's causing this exactly.
except TypeError, e:
print e
#self.print_help() # For now call on the help, they always know what to do.
def print_help(self):
"""Show this message again.
"""
self.__tell('Usage Pronto [option] [command]'
'\n'
'\n Options:'
'\n -u : Define a username/handle.'
'\n'
'\n Commands:')
m = max([len(command) for command in self.commands])
for command, func in sorted(self.commands.items()):
self.__tell(' %s%s : %s' % (command, \
' ' * (m - len(command)), \
func.__doc__.split('\n')[0]))
print_help.cli_options = ((), ())
def __following__(self, username):
"""Obtain a users following.
"""
database.store().following2file(username, self.__twitter.CollectFollowing(username))
__following__.cli_options = (('-u',), ())
def __followers__(self, username):
"""Obtain a users followers.
"""
database.store().followers2file(username, self.__twitter.CollectFollowers(username))
__followers__.cli_options = (('-u',), ())
def __profile__(self, username):
"""Get a users basic profile information.
"""
self.__twitter.GetEntireProfile(username)
__profile__.cli_options = (('-u',), ())
def __tweets__(self, username):
"""Collect a users tweets.
"""
self.__twitter.CollectStatuses(username)
__tweets__.cli_options = (('-u',), ())
def __visualize__(self, username):
"""Visualize a handles tweets.
"""
try:
store.VisualizeTweetLinks(username)
except OSError:
self.__util.pi("{}{}'s tweets have not been recorded yet.".format(self.__notify.ERROR , username))
self.__util.pi("{}try './pronto -u [username] tweets {}' to harvest {}'s tweets.\n".format(self.__notify.INFO, username, username))
__visualize__.cli_options = (('-u',), ())
def __exhaustion__(self):
"""Massively collect Twitter handles from hashtags/trends.
"""
print "\n" + self.__notify.INFO + "Starting the mass collection engine..."
self.__twitter.CollectHandlesFromTrendStream()
__exhaustion__.cli_options = ((), ())
def documentation(self):
"""Documentation, for those who need it.
"""
print """
./pronto -u [username] following | Get who a user is following.
./pronto -u [username] followers | Get a users followers.
./pronto -u [username] profile | Get basic profile information.
./pronto -u [username] tweets | collect a users tweets. (in the next version)
./pronto exhaustion | Massively collect users from hashtags/trends.
"""
documentation.cli_options = ((), ())
commands = {
'help':print_help,
'following':__following__,
'followers':__followers__,
'profile':__profile__,
'exhaustion':__exhaustion__,
'docs':documentation
}
if __name__ == "__main__":
try:
Pronto().boot()
except KeyboardInterrupt:
print "\nExiting Pronto ..."