-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlaupdate.py
87 lines (85 loc) · 3.64 KB
/
laupdate.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Distributed under the terms of MIT License (MIT)
import pywikibot
import time
from pywikibot.data.api import Request
import re
site = pywikibot.Site('fa', fam='wikipedia')
print "Fetching admins list"
data = Request(site=site, action="query", list="allusers", augroup="sysop", aulimit=500).submit()
adminsac = []
adminbots = ["Dexbot"]
adminsdiac = {}
for admin in data["query"]["allusers"]:
admin = admin["name"]
if admin in adminbots:
continue
acaction = []
dcaction = []
actions = "block, protect, rights, delete, upload, import, renameuser".split(
", ")
for adminaction in actions:
data1 = Request(site=site, action="query", list="logevents",
leuser=admin, letype=adminaction).submit()
for action in data1["query"]["logevents"]:
times = action["timestamp"].split("T")[0].split("-")
today = time.strftime('%Y/%m/%d').split("/")
diff = ((int(today[0]) - int(times[0])) * 365) + (
(int(today[1]) - int(times[1])) * 30) + (int(today[2]) - int(times[2]))
if diff < 90:
acaction.append(
action["timestamp"].split("T")[0].replace("-", ""))
else:
dcaction.append(
action["timestamp"].split("T")[0].replace("-", ""))
thmag = {"y": int(time.strftime('%Y')), "m": int(
time.strftime('%m')), "d": int(time.strftime('%d'))}
if (int(thmag["m"]) - 3) <= 0:
thmag["y"] = thmag["y"] - 1
thmag["m"] = thmag["m"] + 9
else:
thmag["m"] = thmag["m"] - 3
if thmag["m"] < 10:
thmag["m"] = "0" + str(thmag["m"])
if thmag["d"] < 10:
thmag["d"] = "0" + str(thmag["d"])
thmag1 = [str(thmag["y"]), str(thmag["m"]), str(thmag["d"])]
data2 = Request(site=site, action="query", list="usercontribs", ucuser=admin,
ucnamespace=8, ucend="%sT00:00:00Z" % "-".join(thmag1)).submit()
for actionmw in data2["query"]["usercontribs"]:
acaction.append(actionmw["timestamp"].split("T")[0].replace("-", ""))
if len(acaction) >= 10:
if re.search(ur"[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیآ]", admin[0]):
adminsac.append(u"!!!!!!!!!!!!!!!!!!!!!!!!!!!" + admin)
else:
adminsac.append(admin)
else:
acaction.sort()
dcaction.sort()
if re.search(ur"[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیآ]", admin[0]):
admin = u"!!!!!!!!!!!!!!!!!!!!!!!!!!!" + admin
try:
adminsdiac[admin] = acaction[-1]
except:
adminsdiac[admin] = dcaction[-1]
pywikibot.output(admin)
adminsac.sort()
activetext = u"\n{{ویکیپدیا:فهرست مدیران/سطرف|" + \
u"}}\n{{ویکیپدیا:فهرست مدیران/سطرف|".join(adminsac) + u"}}"
deactivetext = u"\n"
activetext = activetext.replace(u"!!!!!!!!!!!!!!!!!!!!!!!!!!!", u"")
ak = adminsdiac.keys()
ak.sort()
for admin in ak:
deactivetext = deactivetext + \
u"{{ویکیپدیا:فهرست مدیران/سطرغ|" + admin + \
u"|" + adminsdiac[admin] + u"}}\n"
deactivetext = deactivetext.replace(u"!!!!!!!!!!!!!!!!!!!!!!!!!!!", u"")
page = pywikibot.Page(site, u"ویکیپدیا:فهرست مدیران")
text = page.get()
pywikibot.output(deactivetext)
new_text = text.replace(text.split(u"<!-- Active -->")[1], activetext + u"\n")
new_text = new_text.replace(u"<!-- Deactive -->" + text.split(
u"<!-- Deactive -->")[1], u"<!-- Deactive -->" + deactivetext + u"\n")
page.put(new_text, u"ربات: بروزرسانی فهرست")