Skip to content

Commit

Permalink
Add new weekly-en script
Browse files Browse the repository at this point in the history
  • Loading branch information
Huji committed Jan 4, 2025
1 parent 64c98a1 commit 621967f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 38 deletions.
5 changes: 4 additions & 1 deletion HujiBot/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
python handles string formatting (i.e. %s will be replaced with a
given string and so on).
-maxtime Maximum execution time of SQL queries (in minutes). Default is 30.
-dbname Name of the database to run SQL queries on. Default is fawiki
This bot always stores the SQL query in an HTML comment (<!-- ... -->) at the
top of the page to allow reproducibility of the results by others.
Expand Down Expand Up @@ -117,6 +118,7 @@ def __init__(
sqlnum=None,
sign=True,
maxtime=None,
dbname='fawiki'
):
if not (sql and out and cols and summary):
raise ValueError("You must define sql, out, cols, and summary")
Expand All @@ -129,6 +131,7 @@ def __init__(
self.sign = sign
self.sqlnum = sqlnum
self.maxtime = 30 if maxtime is None else maxtime
self.dbname = dbname

def run(self):
print("Stats bot started ...")
Expand All @@ -148,7 +151,7 @@ def run(self):
for col in self.cols:
text += "!" + col + "\n"
query_start = time.time()
conn = toolforge.connect("fawiki", charset="utf8")
conn = toolforge.connect(self.dbname, charset="utf8")
cursor = conn.cursor()
max_time = "SET SESSION MAX_STATEMENT_TIME = 60 * %d;" % (self.maxtime)
cursor.execute(max_time)
Expand Down
97 changes: 97 additions & 0 deletions HujiBot/weekly-en.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
weekly-en.py - a wrapper for stats.py to be called every week.
usage:
python pwb.py weekly-en <sqlnum> <maxtime>
or
python pwb.py weekly-en <sqlnum>
or
python pwb.py weekly-en
parameters:
<sqlnum>: (optinal) integer Used to run specifice queries
<maxtime>: (optional) maximum execution time for the specified query
"""
#
# (C) Pywikibot team, 2006-2014
# (C) w:fa:User:Huji, 2015
#
# Distributed under the terms of the MIT license.
#


import sys
import stats


def main(sqlnum, maxtime):
tasks = [
{
"sqlnum": 1,
"sql": """
SELECT
page_title,
COUNT(ll.ll_lang) AS interwiki_count,
COALESCE(pp.pp_value, '&mdash;') AS description
FROM page p
JOIN langlinks ll
ON p.page_id = ll.ll_from
LEFT JOIN page_props pp
ON p.page_id = pp.pp_page
AND pp.pp_propname = 'wikibase-shortdesc'
LEFT JOIN langlinks ll2
ON p.page_id = ll2.ll_from
AND ll2.ll_lang = 'fa'
WHERE
p.page_namespace = 0
AND p.page_is_redirect = 0
AND ll2.ll_lang IS NULL
GROUP BY
p.page_title,
pp.pp_value
HAVING COUNT(ll.ll_lang) > 10
ORDER BY interwiki_count DESC
LIMIT 100
""",
"out": "ویکی‌پدیا:گزارش دیتابیس/"
+ "مقاله‌های مهم ایجادنشده بر پایه دیگر میان‌ویکی‌ها",
"cols": ["ردیف", "مقاله", "شمار میان‌ویکی‌ها", "توضیحات"],
"summary": "به روز کردن آمار",
"pref": "[[رده:گزارش‌های دیتابیس ویکی‌پدیا]]\n{{/بالا}}"
+ "\nآخرین به روز رسانی: ~~~~~",
"frmt": "| {{formatnum:%d}} || [[:en:%s]] || {{formatnum:%s}}"
+ " |dir=ltr| %s",
"sign": True,
},
]

for t in tasks:
if sqlnum:
if sqlnum != t["sqlnum"]:
continue
bot = stats.StatsBot(
t["sql"],
t["out"],
t["cols"],
t["summary"],
t["pref"],
t["frmt"],
t["sqlnum"],
t["sign"],
maxtime,
"enwiki",
)
bot.run()


if __name__ == "__main__":
if len(sys.argv) > 1:
sqlnum = int(sys.argv[1])
if len(sys.argv) > 2:
maxtime = int(sys.argv[2])
else:
maxtime = None
else:
sqlnum = 0
maxtime = None
main(sqlnum, maxtime)
37 changes: 0 additions & 37 deletions HujiBot/weekly-slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,43 +1180,6 @@ def main(sqlnum, maxtime):
"frmt": "| {{formatnum:%d}} || [[کاربر:%s]] || {{formatnum:%s}}",
"sign": True,
},
{
"sqlnum": 21,
"sql": """
SELECT
page_title,
COUNT(ll.ll_lang) AS interwiki_count,
COALESCE(pp.pp_value, '&mdash;') AS description
FROM page p
JOIN langlinks ll
ON p.page_id = ll.ll_from
LEFT JOIN page_props pp
ON p.page_id = pp.pp_page
AND pp.pp_propname = 'wikibase-shortdesc'
LEFT JOIN langlinks ll2
ON p.page_id = ll2.ll_from
AND ll2.ll_lang = 'fa'
WHERE
p.page_namespace = 0
AND p.page_is_redirect = 0
AND ll2.ll_lang IS NULL
GROUP BY
p.page_title,
pp.pp_value
HAVING COUNT(ll.ll_lang) > 10
ORDER BY interwiki_count DESC
LIMIT 100
""",
"out": "ویکی‌پدیا:گزارش دیتابیس/"
+ "مقاله‌های مهم ایجادنشده بر پایه دیگر میان‌ویکی‌ها",
"cols": ["ردیف", "مقاله", "شمار میان‌ویکی‌ها", "توضیحات"],
"summary": "به روز کردن آمار",
"pref": "[[رده:گزارش‌های دیتابیس ویکی‌پدیا]]\n{{/بالا}}"
+ "\nآخرین به روز رسانی: ~~~~~",
"frmt": "| {{formatnum:%d}} || [[:en:%s]] || {{formatnum:%s}}"
+ " |dir=ltr| %s",
"sign": True,
},
]

for t in tasks:
Expand Down

0 comments on commit 621967f

Please sign in to comment.