-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwistalk.py
167 lines (127 loc) · 3.83 KB
/
wistalk.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
import sys
from bs4 import BeautifulSoup
import requests
import urllib.parse as urlparse
from urllib.parse import parse_qs
import datetime
import lxml
import signal
def sizeof_fmt(num, suffix='B'):
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
uname = sys.argv[1]
if uname == "-i":
print("https://YY.wikipedia.org/wiki/User:XXXX")
uname = input("Enter Wikipedia Username (XXXX) : ")
subwiki = input("Enter Wikipedia Language (en/id) : ")
iloop = True
else:
iloop = False
try:
subwiki = sys.argv[2]
except Exception as e:
subwiki = 'id'
stillOn = True
topart = dict()
def signal_handler(sig,frame):
for i in sorted(topart,key=topart.get,reverse=False):
print(str(i) +" : "+ str(topart[i]))
print()
sys.exit(0)
signal.signal(signal.SIGINT,signal_handler)
while stillOn:
if subwiki == 'en':
url = "https://en.wikipedia.org/w/index.php?title=Special:Contributions/"+str(uname)+"&dir=prev&limit=5000"
baseurl = "https://en.wikipedia.org"
else:
url = "https://id.wikipedia.org/w/index.php?title=Istimewa:Kontribusi_pengguna/"+str(uname)+"&dir=prev&limit=5000"
baseurl = "https://id.wikipedia.org"
stop = False
wikiarticle = set()
byte_add = 0
byte_rem = 0
stage = 0
topart = dict()
while not stop:
stage += 500
#print("Edit count : "+str(stage))
parsed = urlparse.urlparse(url)
try:
x = parse_qs(parsed.query)['offset']
dobj = datetime.datetime.strptime(x[0],'%Y%m%d%H%M%S')
print(str(dobj) + " " +str(stage) +" [+"+sizeof_fmt(byte_add)+"] ["+sizeof_fmt(byte_rem)+"]" )
except Exception as e:
None
#print(url)
actualPayload = bytearray()
response = requests.get(url)
actualPayload = response.text
soup = BeautifulSoup(actualPayload,'lxml')
titles = soup.find_all("a",{"class":"mw-contributions-title"})
titles_time = soup.find_all("a",{"class":"mw-changeslist-date"})
bytescontrib = soup.find_all("span",{"class":"mw-diff-bytes"})
next_url = soup.find("a",{"class":"mw-prevlink"})
theList = soup.findAll("li",{"data-mw-revid":True})
theList.reverse()
for i in theList:
c_title = i.find("a",{"class":"mw-contributions-title"})
c_time = i.find("a",{"class":"mw-changeslist-date"})
c_ctr = i.find("span",{"class":"mw-diff-bytes"})
c_ctrX = i.find("strong",{"class":"mw-diff-bytes"})
c_diff = i.find("a",{"class":"mw-changeslist-diff"})
try:
if c_ctr is None:
c_ctr = c_ctrX
a = c_ctr.text.replace("−","-")
a = c_ctr.text.replace(".","")
a = int(a)
if c_title.text not in topart:
topart[c_title.text] = a
else:
topart[c_title.text] += a
print(c_time.text +" : "+c_title.text + " (" + c_ctr.text +" / "+str(topart[c_title.text]) +")")
except Exception as e:
try:
print(c_time.text +" : "+c_title.text)
except Exception as d:
print(c_title.text)
try:
print(baseurl+c_diff.attrs["href"])
except Exception as e:
try:
print(baseurl+c_time.attrs["href"]+" (B)")
except Exception as e:
continue
print()
for i in bytescontrib:
#print(i.text)
a = i.text.replace("−","-")
contrib = int(a)
if contrib >= 0:
byte_add += contrib
else:
byte_rem += contrib
try :
next_url = next_url.attrs["href"]
url = baseurl + next_url
except Exception as e:
stop = True
'''
for i in wikiarticle:
print(i)
'''
for i in sorted(topart,key=topart.get,reverse=False):
print(str(i) +" : "+ str(topart[i]))
print()
print("Addition "+sizeof_fmt(byte_add))
print("Deletion "+sizeof_fmt(byte_rem))
if iloop:
print()
print("https://YY.wikipedia.org/wiki/User:XXXX")
uname = input("Enter Wikipedia Username (XXXX) : ")
subwiki = input("Enter Wikipedia Language (en/id) : ")
else:
stillOn = False