-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstalker.py
More file actions
397 lines (367 loc) · 12.7 KB
/
Copy pathstalker.py
File metadata and controls
397 lines (367 loc) · 12.7 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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# -*- coding: utf-8 -*-
# @Author: Amar Prakash Pandey
# @Date: 2016-03-24
# @Email: amar.om1994@gmail.com
# @Github username: @amarlearning
# @Last Modified by: Amar Prakash Pandey
# @Last Modified date: 2016-08-01
# MIT License. You can find a copy of the License
# @http://amarlearning.mit-license.org
import sys
import datetime
import urllib
import os
import re
from tabulate import tabulate
from clint.textui import colored, puts
from bs4 import BeautifulSoup
# Global variables used in program
def head() :
"""official banner for PyStalker printed in yellow color"""
clear()
pystalker_banner = r"""
____ ____ _ _ _
| _ \ _ _/ ___|| |_ __ _| | | _____ _ __
| |_) | | | \___ \| __/ _` | | |/ / _ \ '__|
| __/| |_| |___) | || (_| | | < __/ |
|_| \__, |____/ \__\__,_|_|_|\_\___|_|
|___/
- By Amar Prakash Pandey(@amarlearning)
"""
puts(colored.yellow(pystalker_banner))
def clear():
"""for removing the clutter from the screen when necessary"""
os.system('cls' if os.name == 'nt' else 'clear')
def space() :
"""providing one line space in the console when needed"""
print ""
def regex(username) :
"""validating username using regular expression"""
regex_pattern = r'^[A-Za-z0-9_]+$'
match = re.findall(regex_pattern, username)
if len(match) == 1 :
return 1
else :
return 0
def check_already_present(username) :
"""because redundancy is not good"""
loop = 0
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path)
file_read = file_content.read()
users_list = file_read.split()
for user in users_list :
if username == user :
loop = 1
return loop
def delete_a_username(delete_node) :
"""no need to stalk everyone everytime"""
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path)
file_read = file_content.read()
users_list = file_read.split()
print users_list
loop = 0
flag = -10
for user in users_list :
if delete_node == user :
flag = loop
loop = loop + 1
if flag > -1 :
del users_list[flag]
print users_list
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path,'w')
for user in users_list :
user = " " + user
file_content.write(user)
file_content.close()
flag = 6
call_defined_function(menu(flag))
else :
flag = 5
call_defined_function(menu(flag))
def notification(flag) :
"""notifications tell us what going on behind the scene"""
if flag == 1 :
puts(colored.red("error : wrong value entered! input correct value."))
space()
flag = 0
elif flag == 2 :
puts(colored.yellow("success : username successfully added to data file."))
space()
flag = 0
elif flag == 3 :
puts(colored.red("error : invalid username entered."))
space()
flag = 0
elif flag == 4 :
puts(colored.red("error : username already present."))
space()
flag = 0
elif flag == 5 :
puts(colored.red("error : username not present in list."))
space()
flag = 0
elif flag == 6 :
puts(colored.yellow("success : username deleted successfully."))
space()
flag = 0
def add_name_to_data(username) :
"""adding a username to the data file"""
flag = regex(username)
if flag == 1 :
carry = check_already_present(username)
if carry == 0 :
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path,'a')
username = " " + username
file_content.write(username)
file_content.close()
flag = 2
call_defined_function(menu(flag))
else :
flag = 4
call_defined_function(menu(flag))
else :
flag = 3
call_defined_function(menu(flag))
def get_webpage_data(webpage,username) :
scrapper = BeautifulSoup(webpage , 'html.parser')
matches = scrapper.prettify()
find_what_you_are_looking_for(scrapper,username)
def print_in_style(catch,username) :
table = [[1,username,catch[10:]]]
headers = ["Sno.","Username", "Last Visit"]
print tabulate(table, headers, tablefmt="fancy_grid")
space()
puts(colored.magenta("Note : press '1' to return back to menu."))
puts(colored.magenta("Note : press '0' to exit."))
space()
x = int(raw_input("Action : "))
if(x == 1) :
flag = 0
call_defined_function(menu(flag))
elif(x == 0) :
clear()
else :
flag = 1
call_defined_function(menu(flag))
def print_full_table(mylist) :
header = ["Sno.","Username", "Last Visit"]
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path)
users_list = file_content.read().split()
loop = 0
table = []
print len(mylist)
print "Sno. \t username \t Last Visit"
for x in mylist :
print " "+ str(loop+1) + "\t " + users_list[loop] +"\t "+ x[10:]
loop += 1
def find_what_you_are_looking_for(scrapper,username) :
matches = scrapper.find('div',{'id':'pageContent'})
match = matches.find('div',{'class':'roundbox'})
match = match.find('ul')
for li in match.find_all('li') :
catch = li.get_text()
if "Last visit" in catch :
catch = catch.strip()
catch = re.sub(r"\s", "", catch)
print_in_style(catch,username)
def check_connection(username) :
url = "http://codeforces.com/profile/" + username
response = urllib.urlopen(url)
if response == None :
print "Check your Internet conneciton! Not working."
else :
get_webpage_data(response,username)
def add_new_name(username) :
"""adding a username to the data file then stalking"""
flag = regex(username)
if flag == 1 :
carry = check_already_present(username)
if carry == 0 :
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path,'a')
username = " " + username
file_content.write(username)
file_content.close()
else :
flag = 4
call_defined_function(menu(flag))
else :
flag = 3
call_defined_function(menu(flag))
def full_play() :
"""hacking into your system..lolz wait means stalking all data"""
loop = 1
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path)
users_list = file_content.read().split()
puts(colored.cyan("[ Getting data from internet.. ]"))
puts(colored.green("[ Started stalking user accounts.. ]"))
space()
print "Sno. \t username \t Last Visit"
for user in users_list :
url = "http://codeforces.com/profile/" + user
response = urllib.urlopen(url)
if response == None :
print "Check your Internet conneciton! Not working."
else :
scrapper = BeautifulSoup(response , 'html.parser')
matches = scrapper.prettify()
matches = scrapper.find('div',{'id':'pageContent'})
match = matches.find('div',{'class':'roundbox'})
match = match.find('ul')
mylist = []
for li in match.find_all('li') :
catch = li.get_text()
if "Last visit" in catch :
catch = catch.strip()
catch = re.sub(r"\s", "", catch)
print " "+ str(loop+1) + "\t " + user +"\t "+ catch[10:]
loop += 1
if loop == 1 :
puts(colored.cyan("message : No entries found!"))
# else :
# print_full_table(mylist)
space()
puts(colored.magenta("Note : press '1' to return back to menu."))
puts(colored.magenta("Note : press '0' to exit."))
space()
x = int(raw_input("Action : "))
if(x == 1) :
flag = 0
call_defined_function(menu(flag))
elif(x == 0) :
clear()
else :
flag = 1
call_defined_function(menu(flag))
def show_all_data() :
"""showing all entries present in the data file"""
loop = 1
cwd = os.getcwd()
file_path = cwd+"/DATA"
file_content = open(file_path)
users_list = file_content.read().split()
puts(colored.green("List of entries present in data file."))
space()
for user in users_list :
puts(colored.yellow(str(loop)+". "+user))
loop = loop + 1
if loop == 1 :
puts(colored.cyan("message : No entries found!"))
space()
puts(colored.magenta("Note : press '1' to return back to menu."))
puts(colored.magenta("Note : press '0' to exit."))
space()
x = int(raw_input("Action : "))
if(x == 1) :
flag = 0
call_defined_function(menu(flag))
elif(x == 0) :
clear()
else :
flag = 1
call_defined_function(menu(flag))
def show_doc() :
doc = """
A very simple python script to check what your friend are doing on coding sites.
You can see you friends Last visit, Last question solved, Last contest given.
- Simple to use : Built with love so it's easy to use. Problem ? see the doc.
- Infinite options : There are many so i'll list all of them
- Add any number of usernames.
- single command will stalk every username.
- you can stalk any user anonymous.
- Secure : Belive me it's secure, till you take care of data file (no playing).
- Text Highlighting is cross platform - Supports Linux, MAC, Windows for the terminal based highlighting.
"""
puts(colored.cyan(doc))
space()
puts(colored.magenta("Note : press '1' to return back to menu."))
puts(colored.magenta("Note : press '0' to exit."))
space()
x = int(raw_input("Action : "))
if(x == 1) :
flag = 0
call_defined_function(menu(flag))
elif(x == 0) :
clear()
else :
flag = 1
call_defined_function(menu(flag))
def menu(flag) :
"""menu for pystalker take option and call desired function"""
head()
puts(colored.magenta("Stalkers menu : "))
space()
notification(flag)
puts(colored.green("(1) Stalk for one input username. "))
puts(colored.green("(2) Add a username to data file. "))
puts(colored.green("(3) Delete a username from data file. "))
puts(colored.green("(4) View all data entry. "))
puts(colored.green("(5) Stalk for every data entry. "))
puts(colored.yellow("Doc : press '7' to see Documentation."))
puts(colored.red("Note : press '0' to exit!"))
space()
index = int(raw_input("Action : "))
return index
def call_defined_function(value) :
"""call the function that user requested"""
if(value == 1):
"""stalking some random remembered username ? go ahead!"""
head()
puts(colored.green("Fill out the username [anonymous stalking] : "))
username = raw_input()
space()
what_to_do = regex(username)
if what_to_do == 1 :
check_connection(username)
else :
flag = 3
call_defined_function(menu(flag))
elif(value == 2):
"""add a username to the data file"""
head()
puts(colored.green("Fill out the username : "))
username = raw_input()
add_name_to_data(username)
elif(value == 3) :
"""delete a username from the data file"""
head()
puts(colored.green("Fill out the username : "))
delete_node = raw_input()
delete_a_username(delete_node)
elif(value == 4):
"""display all the data present in the data file."""
head()
show_all_data()
elif(value == 5):
"""display all the data present in the data file."""
head()
full_play()
elif(value == 7):
"""display all the data present in the data file."""
head()
show_doc()
elif(value == 0):
clear()
else :
flag = 1
call_defined_function(menu(flag))
def main() :
"""everythings starts from here i.e. main()"""
flag = 0
clear()
call_defined_function(menu(flag))
if __name__ == "__main__" :
main()