diff --git a/public_html/repteGEC/repteGEC.py b/public_html/repteGEC/repteGEC.py new file mode 100644 index 0000000..4a015f6 --- /dev/null +++ b/public_html/repteGEC/repteGEC.py @@ -0,0 +1,89 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +''' +Copyright 2019 Carles Paredes Lanau +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +''' + +import urllib2 +import codecs +import json +import datetime +import pywikibot +from bs4 import BeautifulSoup + +INIT_TABLE = {u"Jey":7673, u"Joutbis":6140, u"Magnus Manske":6027, u"Davidpar":4483, u"Auxiliary data matcher":4382, u"Kippelboy":4216, u"KRLS":3085, u"Llumeureka":2000, u"ÀlexHinojo":671, u"DavidMar86hdf":553, u"Mahir256":526, u"Paucabot":464, u"Adam Harangozó":398, u"Andre Engels":343, u"Escudero":333, u"Tiputini":286, u"Nono314":239, u"Pere prlpz":160, u"Spinster":149, u"AttoRenato":144, u"Wikidelo":140, u"Charles Matthews":104, u"Papapep":101, u"Micru":73, u"HCShannon":73, u"Sjoerddebruin":60, u"Jheald":60, u"Jssfrk":54, u"Paulbe":50, u"Thierry Caro":48, u"FallingGravity":47, u"Lymantria":45, u"Sadads":41, u"Kareyac":39, u"ESM":39, u"Vriullop":37, u"Nikosguard":35, u"Heron":35, u"Frettie":34, u"Automatic name/date matcher":31, u"Amadalvarez":31, u"Blademasterx":30, u"Innotata":29, u"Cavaliere grande":28, u"Uncommon fritillary":26, u"Gerwoman":22, u"Bodhisattwa":21, u"Epìdosis":20, u"Pigsonthewing":19, u"Kam Solusar":17, u"Movses":17, u"Pfadintegral":17, u"PKM":17, u"MisstressD":17, u"Runner1928":16, u"Unapersona":16, u"AlessioMela":16, u"Joy Agyepong":16, u"Salgo60":15, u"-1": 14, u"Andrew Gray":14, u"Widar of zolo":13, u"NMaia":13, u"Anvilaquarius":12, u"Ayack":12, u"Barcex":12, u"TomT0m":12, u"Coentor":11, u"Nonoxb":11, u"Fralambert":10, u"CameoJewel":10, u"Arcadialib":10, u"Gymel":10, u"Daask":10, u"Andreasmperu":10, u"ShinePhantom":10, u"PMG":10, u"Dorades":9, u"Matiras":9, u"Dcflyer":9, u"Townie":8, u"Trivialist":8, u"William Graham":8, u"Tagishsimon":8, u"HeavyTony":8, u"Oop":7, u"Mr.Ajedrez":7, u"????????? ???????":7, u"Strakhov":7, u"LadyData":7, u"Lluis tgn":7, u"ASchedulingError":6, u"Gamaliel":6, u"INS Pirat":5, u"Marchitelli":5, u"Gabbe":5, u"Sannita":5, u"MistressData":4, u"Dhx1":4, u"Rashinseita":4, u"Docosong":4, u"Trade":4, u"Aervin":4, u"Netoholic":4, u"AVRS":4, u"Zugubugu":4, u"Mcampany":4, u"Billinghurst":4, u"Nurni":4, u"Anna Voig":3, u"Smb1001":3, u"Waldir":3, u"Ionutzmovie":3, u"??????? ??????????":3, u"Donarreiskoffer":3, u"Jamie Tubers":3, u"Mushroom":3, u"Jean-Frédéric":3, u"Einebillion":3, u"Uomovariabile":3, u"Xmlizer":3, u"LadiesMakingComics":3, u"Valentina.Anitnelav":3, u"Mat?j Suchánek":3, u"Vesihiisi":3, u"Teolemon":3, u"Jordi Roqué":3, u"Exilexi":3, u"Delirium":3, u"Floscher":3, u"Jura1":3, u"Olea":2, u"Queryzo":2, u"Wenal14":2, u"ArtShannon":2, u"jane023":2, u"Parikan":2, u"Kvardek du":2, u"Sukkoria":2, u"Convallaria majalis":2, u"Elenyyy":2, u"Hadae":2, u"Masegand":2, u"Hadi":2, u"Ninovolador":2, u"Petronas":2, u"Alex Cohn":2, u"Scewing":2, u"BeatrixBelibaste":2, u"Vidal Santos":2, u"Hazmat2":2, u"Tinm":2, u"Mike Peel":2, u"Powerek38":2, u"LuisVilla":2, u"Ijon":2, u"Rachel Helps (BYU)":1, u"BohemianRhapsody":1, u"Totodu74":1, u"Waggers":1, u"Dinoguy1000":1, u"QZanden":1, u"555": 1, u"Rock drum":1, u"Kergourlay":1, u"SparkleSparkle":1, u"Tpt":1, u"Oriciu":1, u"Fundriver":1, u"Rosernvs":1, u"MrLinkinPark333":1, u"Kiwigirl3850":1, u"Sporti":1, u"Markus.suhr":1, u"CheChe":1, u"Papuass":1, u"Russian Rocky":1, u"Koxinga":1, u"StackSqrrl":1, u"Marsupium":1, u"Cjordahl":1, u"Nashona":1, u"Edhral":1, u"MartinPoulter":1, u"Neko-chan":1, u"Wostr":1, u"Jeanjung212":1, u"Airon90":1, u"Marv1N":1, u"Aleksander2018":1, u"Symac":1, u"YukioSanjo":1, u"Salvador alc":1, u"Daniel Mietchen":1, u"Eru":1, u"Zar.rehn":1, u"Halibutt":1, u"Jklamo":1, u"LBE":1, u"Teiron":1, u"Danielt998":1, u"Victor LP":1, u"Ham II":1, u"Jonathan Groß":1, u"Lexid523":1, u"Zzme123":1, u"ShadessKB":1, u"Vidariv":1, u"Migrant":1, u"Viscontino":1, u"Norwegianblue":1, u"Simon Villeneuve":1, u"Luccnoir":1, u"Blervis":1, u"Vladimir Alexiev":1, u"Andrew J.Kurbiko":1, u"Sisyph":1, u"Deuterium360":1, u"Ohmyerica":1, u"FocalPoint":1, u"QTHCCAN":1, u"Sabas88": 0} +URL_CATALOGUE = "https://tools.wmflabs.org/mix-n-match/api.php?query=catalog_details&catalog=109" +URL_OVERVIEW = "https://tools.wmflabs.org/mix-n-match/overview.json" +DEBUG_MODE = False +INIT_MATCHED_ELEMENTS = 44108 + +def count_points(users): + result_table = {} + for user_info in users: + username = user_info.get("username") + if username not in INIT_TABLE: + result_table[username] = int(user_info.get("cnt")) + elif username != u"Auxiliary data matcher" and \ + username != u"-1" and \ + (int(user_info.get("cnt")) - int(INIT_TABLE.get(username))) > 0: + result_table[username] = int(user_info.get("cnt")) - int(INIT_TABLE.get(username)) + return result_table + +def print_results(results, gec_overview): + output_table = u"''La classificació s'anirà actualitzant periòdicament i automàticament. No l'editeu, per favor.''
\n" \ + u" ''Darrera actualització {0}). Font:'' https://tools.wmflabs.org/mix-n-match/#/catalog/109:\n"\ + u"
\n".format(datetime.datetime.now()) + output_table += u"
\n{|\n| width=50% |\n{| class='wikitable sortable'\n|+\n!Nom d'usuari\n! style='width:35%' | Articles enllaçats\n|-\n" + + sorted_rank = sorted(results.iteritems(), key=lambda x: x[1], reverse=True) + + countdown = datetime.datetime(2019, 9, 17) - datetime.datetime.today() + days_elapsed = datetime.datetime.today() - datetime.datetime(2019, 8, 16) + + total = int(gec_overview.get("manual")) - INIT_MATCHED_ELEMENTS + for elem in sorted_rank: + output_table += u"| {{{{utot|{0}}}}}\n| {1}\n|-\n".format(elem[0], elem[1]) + output_table += u"|}\n" + output_table += u"| width=5% |\n| align=center |\n
'''{0}'''" \ + u"
emparellaments
totals fets

\n
" \ + u"'''{1}%'''
assolit
fins ara

\n
" \ + u"'''{2}'''
emparellaments fets/dia
\n| align=center |\n
'''{3}'''
voluntaris
participants

\n
'''{4}'''
emparellaments restants

\n
'''{5}'''
dies
restants
\n|}}
".format(\ + total, \ + round((total * 1.0 / (100000 - INIT_MATCHED_ELEMENTS)) * 100, 2), \ + total / days_elapsed.days, \ + len(sorted_rank), \ + 100000 - total - INIT_MATCHED_ELEMENTS, \ + countdown.days) + return output_table + +def save(output): + if DEBUG_MODE: + print output + else: + site = pywikibot.Site("ca", "wikipedia") + page = pywikibot.Page(site, u"Viquiprojecte:Viquirepte/GEC/Participants auto") + page.put(output, u'Actualitzant la classificació del Viquirepte') + print page + +def main(): + + json_content_overview = urllib2.urlopen(URL_OVERVIEW).read() + json_object_overview = json.loads(json_content_overview) + + json_content_catalogue = urllib2.urlopen(URL_CATALOGUE).read() + json_object_catalogue = json.loads(json_content_catalogue) + + if json_object_catalogue.get("status") == "OK" and json_object_overview.get("status") == "OK": + results = count_points(json_object_catalogue.get("data").get("user")) + output = print_results(results, json_object_overview.get(u"data").get(u"109")) + save(output) + +if __name__ == '__main__': + main() \ No newline at end of file