From 621967f485e13ee4fc72cf60aebdfcc9c3b7db86 Mon Sep 17 00:00:00 2001 From: Huji Date: Sat, 4 Jan 2025 14:31:08 -0500 Subject: [PATCH] Add new weekly-en script --- HujiBot/stats.py | 5 ++- HujiBot/weekly-en.py | 97 ++++++++++++++++++++++++++++++++++++++++++ HujiBot/weekly-slow.py | 37 ---------------- 3 files changed, 101 insertions(+), 38 deletions(-) create mode 100644 HujiBot/weekly-en.py diff --git a/HujiBot/stats.py b/HujiBot/stats.py index f084de0..6da15bb 100755 --- a/HujiBot/stats.py +++ b/HujiBot/stats.py @@ -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. @@ -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") @@ -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 ...") @@ -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) diff --git a/HujiBot/weekly-en.py b/HujiBot/weekly-en.py new file mode 100644 index 0000000..0019afc --- /dev/null +++ b/HujiBot/weekly-en.py @@ -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 + or + python pwb.py weekly-en + or + python pwb.py weekly-en +parameters: + : (optinal) integer Used to run specifice queries + : (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, '—') 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) diff --git a/HujiBot/weekly-slow.py b/HujiBot/weekly-slow.py index 8e1e4e5..3f7ee52 100755 --- a/HujiBot/weekly-slow.py +++ b/HujiBot/weekly-slow.py @@ -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, '—') 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: