Repository navigation
Expand file tree
/
Copy pathtest.py
More file actions
58 lines (47 loc) · 1.61 KB
/
Copy pathtest.py
File metadata and controls
58 lines (47 loc) · 1.61 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
import datetime
import mwclient
import pymysql
from displayTable import display_report
from .config import credentials, cttbot
def forgotten_articles():
db = pymysql.connect(
host="enwiki.labsdb",
user=credentials["user"],
passwd=credentials["pass"],
db="enwiki_p",
)
site = mwclient.Site("en.wikipedia.org")
site.login(cttbot["user"], cttbot["pass"])
print("initiated")
# Make the query
cur = db.cursor()
query = """SELECT p.page_title, p.page_namespace, p.page_is_redirect, p.page_touched, r.editcount FROM page p
LEFT JOIN ( SELECT COUNT(*) AS editcount, rev_page FROM revision GROUP BY rev_page ) r ON r.rev_page = p.page_id
WHERE page_is_redirect = 0 AND page_namespace = 0
ORDER BY page_touched
LIMIT 500"""
cur.execute(query)
# Extract the data into a Python nested list
content = []
content.append(
[
"forgotten-articles-title",
"forgotten-articles-last-edited",
"forgotten-articles-editcount",
]
)
for row in cur.fetchall():
content.append(
[
"[[" + row[0] + "]]",
datetime.datetime.strptime(row[3], "%Y%m%d%H%M%S"),
row[4],
]
)
# Format the data as wikitext
text = display_report("en", content, "forgotten-articles-desc")
# May as well do something with this variable..
print(text)
page = site.Pages["Wikipedia:Database reports/Forgotten_articles"]
page.save(content, summary="bot test edit")
forgotten_articles()