Jump to content

User:DreamRimmer/AwardsNOV24.py

From Wikipedia, the free encyclopedia
import pywikibot
from pywikibot import pagegenerators
import time

site = pywikibot.Site('en', 'wikipedia')

#participants list with their points
participants = [
    {"User": "JTtheOG", "Total": 1000.0},
    {"User": "MPGuy2824", "Total": 542.0},
    {"User": "Turtlecrown", "Total": 493.5},
    {"User": "Isaidnoway", "Total": 377.0},
    {"User": "Cielquiparle", "Total": 357.0},
    {"User": "Smallangryplanet", "Total": 355.5},
    {"User": "Apollo468", "Total": 310.0},
    {"User": "Fluorescent Jellyfish", "Total": 310.0},
    {"User": "Headhitter", "Total": 267.0},
    {"User": "Kazamzam", "Total": 257.0},
    {"User": "Suonii180", "Total": 254.5},
    {"User": "Nayyn", "Total": 230.0},
    {"User": "ResonantDistortion", "Total": 210.5},
    {"User": "Wozal", "Total": 208.5},
    {"User": "Anonymous1261", "Total": 201.0},
    {"User": "D-Flo27", "Total": 200.0},
    {"User": "Sam Sailor", "Total": 192.0},
    {"User": "SunloungerFrog", "Total": 160.0},
    {"User": "Coeusin", "Total": 135.0},
    {"User": "Ruud Buitelaar", "Total": 133.5},
    {"User": "Spiderpig662", "Total": 113.0},
    {"User": "The joy of all things", "Total": 105.0},
    {"User": "Mason7512", "Total": 97.0},
    {"User": "Liandrei", "Total": 91.0},
    {"User": "WeirdNAnnoyed", "Total": 101.0},
    {"User": "Feralcateater000", "Total": 85.0},
    {"User": "Gnisacc", "Total": 84.0},
    {"User": "Rosiestep", "Total": 78.0},
    {"User": "Demt1298", "Total": 76.0},
    {"User": "AlphaBetaGamma", "Total": 75.0},
    {"User": "Sleepytimecat", "Total": 66.0},
    {"User": "Riley1012", "Total": 63.0},
    {"User": "Significa liberdade", "Total": 61.0},
    {"User": "Lazman321", "Total": 57.0},
    {"User": "Toweli", "Total": 57.0},
    {"User": "Mrfoogles", "Total": 56.0},
    {"User": "MrLinkinPark333", "Total": 55.5},
    {"User": "GranCavallo", "Total": 52.0},
    {"User": "MSLQr", "Total": 52.0},
    {"User": "Jaguarnik", "Total": 50.0},
    {"User": "TheZoodles", "Total": 50.0},
    {"User": "Engrigg22", "Total": 46.0},
    {"User": "Bearian", "Total": 45.0},
    {"User": "Dumelow", "Total": 45.0},
    {"User": "Clarityfiend", "Total": 44.5},
    {"User": "TheBirdsShedTears", "Total": 39.0},
    {"User": "SonOfYoutubers", "Total": 38.0},
    {"User": "ARandomName123", "Total": 38.0},
    {"User": "SounderBruce", "Total": 37.0},
    {"User": "Wikibear47", "Total": 36.0},
    {"User": "SpookiePuppy", "Total": 35.0},
    {"User": "Lollipoplollipoplollipop", "Total": 35.0},
    {"User": "BaduFerreira", "Total": 34.0},
    {"User": "Engineerchange", "Total": 28.0},
    {"User": "TamsaVakaras", "Total": 28.0},
    {"User": "1AmNobody24", "Total": 27.0},
    {"User": "Reconrabbit", "Total": 27.0},
    {"User": "Another Believer", "Total": 26.0},
    {"User": "Reidgreg", "Total": 25.0},
    {"User": "Pichpich", "Total": 25.0},
    {"User": "Based5290", "Total": 25.0},
    {"User": "Donner60", "Total": 24.0},
    {"User": "Silver seren", "Total": 23.0},
    {"User": "Marcus Markup", "Total": 23.0},
    {"User": "GrabUp", "Total": 21.0},
    {"User": "Gazamp", "Total": 22.0},
    {"User": "TrademarkedTWOrantula", "Total": 20.0},
    {"User": "Ewhite31", "Total": 19.0},
    {"User": "Jengod", "Total": 15.0},
    {"User": "Semmendinger", "Total": 15.0},
    {"User": "Moriwen", "Total": 14.0},
    {"User": "GeorgeSonOfJohn", "Total": 14.0},
    {"User": "TheNuggeteer", "Total": 13.5},
    {"User": "Dan Leonard", "Total": 12.0},
    {"User": "R0paire-wiki", "Total": 11.0},
    {"User": "Conyo14", "Total": 11.0},
    {"User": "Voorts", "Total": 11.0},
    {"User": "Ayji", "Total": 11.0},
    {"User": "Darcyisverycute", "Total": 11.0},
    {"User": "Bo-3903", "Total": 10.0},
    {"User": "Joe Roe", "Total": 10.0},
    {"User": "Goldsztajn", "Total": 10.0},
    {"User": "Hog Farm", "Total": 10.0},
    {"User": "Ponyo", "Total": 8.0},
    {"User": "Dr vulpes", "Total": 8.0},
    {"User": "Cyanochic", "Total": 8.0},
    {"User": "Nnev66", "Total": 7.0},
    {"User": "CanonNi", "Total": 7.0},
    {"User": "Kline", "Total": 6.0},
    {"User": "Tea and Seed Cake", "Total": 6.0},
    {"User": "Hako9", "Total": 5.5},
    {"User": "Voidxor", "Total": 5.0},
    {"User": "Nil Nandy", "Total": 5.0},
    {"User": "ClaudineChionh", "Total": 5.0},
    {"User": "Jähmefyysikko", "Total": 5.0},
    {"User": "BeanieFan11", "Total": 5.0},
    {"User": "ThermodynamicLawyer", "Total": 5.0},
    {"User": "Sennecaster", "Total": 4.5},
    {"User": "Miminity", "Total": 4.0},
    {"User": "Contrawwftw", "Total": 4.0},
    {"User": "Mir Novov", "Total": 4.0},
    {"User": "Bpuddin", "Total": 4.0},
    {"User": "Hhmontanac", "Total": 4.0},
    {"User": "Garsh2", "Total": 3.0},
    {"User": "DreamRimmer", "Total": 3.0},
    {"User": "Tails Wx", "Total": 3.0},
    {"User": "Cremastra", "Total": 3.0},
    {"User": "HKRailEnthusiast", "Total": 3.0},
    {"User": "Veer27Gupta", "Total": 3.0},
    {"User": "DandelionAndBurdock", "Total": 2.0},
    {"User": "Rsrikanth05", "Total": 2.0},
    {"User": "Flounder fillet", "Total": 2.0},
    {"User": "Tvfunhouse", "Total": 2.0},
    {"User": "Knitsey", "Total": 2.0},
    {"User": "VastV0idInSpace0", "Total": 2.0},
    {"User": "Jlwoodwa", "Total": 2.0},
    {"User": "Pothos144", "Total": 2.0},
    {"User": "AddWittyNameHere", "Total": 2.0},
    {"User": "SL93", "Total": 1.0},
    {"User": "Kmccook", "Total": 1.0},
    {"User": "Clovermoss", "Total": 1.0},
    {"User": "GraziePrego", "Total": 1.0},
    {"User": "Tavantius", "Total": 1.0},
    {"User": "Myceteae", "Total": 1.0},
    {"User": "TyphoonAmpil", "Total": 1.0},
    {"User": "That Tired Tarantula", "Total": 1.0},
    {"User": "Calmkelp", "Total": 1.0},
    {"User": "Rusty Cat", "Total": 1.0},
    {"User": "Tooncool64", "Total": 1.0},
    {"User": "Syskerr91", "Total": 1.0},
    {"User": "Richard Nevell", "Total": 1.0},
    {"User": "EF5", "Total": 8.0}
]
badge_files = {
    1: "File:Citation badge 1.svg",
    5: "File:Citation badge 2.svg",
    10: "File:Citation badge 3.svg",
    25: "File:Citation badge 4.svg",
    50: "File:Citation badge 5.svg",
    100: "File:Citation badge 6.svg",
    200: "File:Citation badge 7.svg",
    300: "File:Citation badge 8.svg",
    500: "File:Citation badge 9.svg",
    750: "File:Citation badge 10.svg"
}

top_badge_files = {
    1: "File:Citation badge N gold.svg",
    2: "File:Citation badge N silver.svg",
    3: "File:Citation badge N bronze.svg"
}

message_fmt = """
== November 2024 WikiProject Unreferenced articles backlog drive – award == 

{| style="border: 1px solid grey; background-color: #fdffe7;"
|rowspan="2" style="vertical-align:middle;" | [[{badge_file}|100px]] 
|rowspan="2" |
|style="font-size: x-large; padding: 0; vertical-align: middle; height: 1.1em;" |
'''Citation Barnstar'''
|-
|style="vertical-align: middle; border-top: 1px solid gray; width:100%;" | 
{message} ~~~~
|}
"""

participants.sort(key=lambda x: x["Total"], reverse=True)
log_file = open("awarded_users.txt", "a+")
awarded_users = set()

for i, user in enumerate(participants):
    if user["User"] in awarded_users:
        print(f"Skipping {user['User']}; already done.")
        continue

    talk_page = pywikibot.Page(site, f"User talk:{user['User']}")

    if talk_page.exists() and message_fmt in talk_page.text:
        continue

    if i < 3:
        badge_file = top_badge_files[i+1]
    else:
        badge_file = "File:Citation badge 1.svg"
        for threshold, file in badge_files.items():
            if user["Total"] >= threshold:
                badge_file = file
            else:
                break

    if i < 3:
        message = f"This award is given in recognition to {{{{BASEPAGENAME}}}} for achieving {['first', 'second', 'third'][i]} place with {user['Total']} point{'s' if user['Total'] != 1 else ''} during the [[Wikipedia:WikiProject Unreferenced articles|WikiProject Unreferenced articles]]'s [[WP:NOV24|NOV24]] backlog drive. Your contributions played a crucial role in sourcing over 8,000 unsourced articles during the drive. Thank you so much for participating and helping to reduce the backlog!"
    else:
        message = f"This award is given in recognition to {{{{BASEPAGENAME}}}} for collecting more than {user['Total']} point{'s' if user['Total'] != 1 else ''} during the [[Wikipedia:WikiProject Unreferenced articles|WikiProject Unreferenced articles]]'s [[WP:NOV24|NOV24]] backlog drive. Your contributions played a crucial role in sourcing over 8,000 unsourced articles during the drive. Thank you so much for participating and helping to reduce the backlog!"

    print(f"User: {user['User']}")
    print(message_fmt.replace("{badge_file}", badge_file).replace("{message}", message))
    print()
    new_text = talk_page.text + f"\n\n{message_fmt.replace('{badge_file}', badge_file).replace('{message}', message)}"
    
    #show diff of the change
    diff = pywikibot.showDiff(talk_page.text, new_text)
    print(diff)
    
    #enter small y and press enter to save message (supervised)
    confirm = input("Save changes? (y/n): ")
    if confirm.lower() == "y":
        talk_page.text = new_text
        talk_page.save("November 2024 WikiProject Unreferenced articles backlog drive – award", minor=False, force=True)
        awarded_users.add(user["User"])
        log_file.write(user["User"] + "\n")
        log_file.flush()
        time.sleep(5)

log_file.close()