Jump to content

User:DreamRimmer/rfdsubpage.py: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
cmt out (DR)
 
Line 12: Line 12:
if not today_page.exists():
if not today_page.exists():
pywikibot.output(f"Today's log page {today_title} does not exist. Creating...")
pywikibot.output(f"Today's log page {today_title} does not exist. Creating...")
yesterday = today - timedelta(days=1)
today_page.text = "{{subst:RfD subpage starter}}"
tomorrow = today + timedelta(days=1)
today_page.text = f"{{{{subst:RfD subpage starter|1={today.year}|2={today.strftime('%B')}|4={today.day}|7={yesterday.year}|8={yesterday.strftime('%B')}|10={yesterday.day}|13={tomorrow.year}|14={tomorrow.strftime('%B')}|16={tomorrow.day}}}}}"
today_page.save("Creating today's RfD log page (bot)")
today_page.save("Creating today's RfD log page (bot)")
pywikibot.output("Created today's log page.")
pywikibot.output("Created today's log page.")
Line 44: Line 46:
if not future_page.exists():
if not future_page.exists():
yesterday = future_date - timedelta(days=1)
future_page.text = "{{subst:RfD subpage starter}}"
tomorrow = future_date + timedelta(days=1)
future_page.text = f"{{{{subst:RfD subpage starter|1={future_date.year}|2={future_date.strftime('%B')}|4={future_date.day}|7={yesterday.year}|8={yesterday.strftime('%B')}|10={yesterday.day}|13={tomorrow.year}|14={tomorrow.strftime('%B')}|16={tomorrow.day}}}}}"
future_page.save(f"Creating RfD log page for {future_date.strftime('%Y-%m-%d')} (bot)")
future_page.save(f"Creating RfD log page for {future_date.strftime('%Y-%m-%d')} (bot)")
pywikibot.output(f"Created log page: {future_title}")
pywikibot.output(f"Created log page: {future_title}")

Latest revision as of 14:06, 10 September 2025

# [[:en:User:DreamRimmer]]

import pywikibot
from datetime import datetime, timedelta

site = pywikibot.Site("wikipedia:en")
today = datetime.now()
today_title = f"Wikipedia:Redirects for discussion/Log/{today.year} {today.strftime('%B')} {today.day}"
today_page = pywikibot.Page(site, today_title)

if not today_page.exists():
    pywikibot.output(f"Today's log page {today_title} does not exist. Creating...")
    yesterday = today - timedelta(days=1)
    tomorrow = today + timedelta(days=1)
    today_page.text = f"{{{{subst:RfD subpage starter|1={today.year}|2={today.strftime('%B')}|4={today.day}|7={yesterday.year}|8={yesterday.strftime('%B')}|10={yesterday.day}|13={tomorrow.year}|14={tomorrow.strftime('%B')}|16={tomorrow.day}}}}}"
    today_page.save("Creating today's RfD log page (bot)")
    pywikibot.output("Created today's log page.")

rfd_page = pywikibot.Page(site, "Wikipedia:Redirects for discussion")
main_content = rfd_page.text
today_entry = f"{{{{Wikipedia:Redirects for discussion/Log/{today.year} {today.strftime('%B')} {today.day}}}}}"

if today_entry in main_content:
    pywikibot.output("Today's entry already exists on rfd page")
else:
    lines = main_content.splitlines()
    insert_index = 0
    for idx, line in enumerate(lines):
        if line.strip().startswith("{{Wikipedia:Redirects for discussion/Log/"):
            insert_index = idx
            break
    
    new_lines = lines[:insert_index] + [today_entry] + lines[insert_index:]
    new_content = "\n".join(new_lines)
    
    #pywikibot.showDiff(main_content, new_content, context=3)
    rfd_page.text = new_content
    rfd_page.save("Adding today's RfD log page (bot)")
    pywikibot.output("Added today's entry to rfd page")

for i in range(1, 5):
    future_date = today + timedelta(days=i)
    future_title = f"Wikipedia:Redirects for discussion/Log/{future_date.year} {future_date.strftime('%B')} {future_date.day}"
    future_page = pywikibot.Page(site, future_title)
    
    if not future_page.exists():
        yesterday = future_date - timedelta(days=1)
        tomorrow = future_date + timedelta(days=1)
        future_page.text = f"{{{{subst:RfD subpage starter|1={future_date.year}|2={future_date.strftime('%B')}|4={future_date.day}|7={yesterday.year}|8={yesterday.strftime('%B')}|10={yesterday.day}|13={tomorrow.year}|14={tomorrow.strftime('%B')}|16={tomorrow.day}}}}}"
        future_page.save(f"Creating RfD log page for {future_date.strftime('%Y-%m-%d')} (bot)")
        pywikibot.output(f"Created log page: {future_title}")
    else:
        pywikibot.output(f"Log page already exists: {future_title}")

pywikibot.output("Bot run complete")