Add old subtitles to issues

[edit]

The long list of retrieve_diff calls has to be filled in manually with issue dates and permalink URLs of Wikipedia:Wikipedia Signpost revisions that reflect what the issue was on that date. Why manually? Mostly, because it's impossible to tell without looking which is the canonical set of blurbs for an issue -- the first revision on that date might have typoes in it that later get fixed, et cetera. Hard to tell what the deal is. And the "new issue" edit summaries aren't consistent enough to use regex to figure it out algorithmically. So it is better to just do by hand.

The following script will give you an appropriate hunk of crap to slap into the individual issue page that adds sub= params to the articles in the issue, and even print an edit link.

Python script to fix old subtitles
import requests
# 2023 Dec 2

def retrieve_and_split_content(api_url):
    print(api_url)
    # Send a GET request to the Wikipedia API
    response = requests.get(api_url)

    # Check if the request was successful (status code 200)
    if response.status_code == 200:
        # Parse the JSON response
        result = response.json()

        # Extract the content from the JSON response
        content = result["query"]["pages"][0]["revisions"][0]["slots"]["main"]["content"]

        # Split the content into lines
        lines = content.split('\n')

        return lines

    else:
        # Print an error message if the request was not successful
        print(f"Error: Unable to retrieve data. Status code: {response.status_code}")

def retrieve_parsed(api_url):
    print(api_url)
    # Send a GET request to the Wikipedia API
    response = requests.get(api_url)

    # Check if the request was successful (status code 200)
    if response.status_code == 200:
        # Parse the JSON response
        result = response.json()

        # Extract the content from the JSON response
        content = result["parse"]["text"]["*"]
        return content

    else:
        # Print an error message if the request was not successful
        print(f"Error: Unable to retrieve data. Status code: {response.status_code}")

def retrieve_diff(revid, date):
    wikitext_api_url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&revids=" + revid + "&formatversion=2&rvprop=content&rvslots=*"

    # Retrieve and split the content
    lines = retrieve_and_split_content(wikitext_api_url)
    relevant_lines = []
    # Print the lines
    for line in lines:
        # print(line)
        if "signpost-snippet" in line.lower():
            relevant_lines.append(line)
    print(str(len(relevant_lines)) + " lines found")

    #parsed_api_url = "https://en.wikipedia.org/w/api.php?action=parse&oldid=" + revid + "&format=json"
    #print(parsed_api_url)
    #content = retrieve_parsed(parsed_api_url)
    # This won't work because it just uses the issue template to set the date, which won't be constant to what it was then. Uguu.

    thatdate_api_url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&titles=Wikipedia:Wikipedia_Signpost/" + date + "&formatversion=2&rvprop=content&rvslots=*"
    #print(thatdate_api_url)
    issuepage = retrieve_and_split_content(thatdate_api_url)
    #print(issuepage)

    incrementor = 0
    for line in issuepage:
        #print(line)
        if "{{{1}}}|0|" in line.lower():
            incrementor = -1
            # Incrementor should start at 0, not 1, if the page does:
            # this is what does the speshul formatting for the centered "from the editor" etc columns

    output = ""
    replace = "{{Wikipedia:Signpost/Template:Signpost-snippet|{{Wikipedia:Wikipedia Signpost/Issue|1}}|"
    replacewith = "{{Signpost/item|{{{1}}}|"
    for line in relevant_lines:
        # print(line)
        # {{Wikipedia:Signpost/Template:Signpost-snippet|{{Wikipedia:Wikipedia Signpost/Issue|1}}|Gallery|Love is in the air|Lovey-dovey stuff for Valentine's.|1.3 MB}}
        incrementor += 1;
        line = line.replace(replace, replacewith + str(incrementor) + "|" + date + "|")
        # print(line)
        l = line.split("|")

        if len(l) != 7:
            # {{Signpost/item|{{{1}}}|7|2023-02-20|Gallery|Love is in the air|Lovey-dovey stuff for Valentine's.|1.3 MB}}
            #   0             1       2 3          4       5                  6                                  7
            # {{Signpost/item|{{{1}}}|7|2023-02-20|Gallery|Love is in the air|1.3 MB|sub=Lovey-dovey stuff for Valentine's.}}
            #   0             1       2 3          4       5                  7               6
            line = l[0] + "|" + l[1] + "|" + l[2] + "|" + l[3] + "|" + l[4] + "|" + l[5] + "|" + l[7].replace("}}","") + "|sub=" + l[6] + "}}"
        else:
            line = l[0] + "|" + l[1] + "|" + l[2] + "|" + l[3] + "|" + l[4] + "|" + l[5] + "|sub=" + l[6]
        print(line.replace("<!-- ","").replace(" -->","").replace("<!--","").replace("-->",""))
    print("https://en.wikipedia.org/w/index.php?title=Wikipedia:Wikipedia_Signpost/" + date + "&action=edit")
    print("----------")


if __name__ == "__main__":

    diffs = []

    # diffs.append(["820777324", "2018-01-16"])
    # diffs.append(["824078731", "2018-02-05"])
    # diffs.append(["826735918", "2018-02-20"])
    # diffs.append(["833127031", "2018-03-29"])
    # diffs.append(["838283983", "2018-04-26"])
    # diffs.append(["847193050", "2018-05-24"])
    # diffs.append(["848153543", "2018-06-29"])
    # diffs.append(["852964542", "2018-07-31"])
    # diffs.append(["857225081", "2018-08-30"])
    # diffs.append(["861926973", "2018-10-01"])
    # diffs.append(["866950939", "2018-10-28"])
    # diffs.append(["871451630", "2018-12-01"])
    # diffs.append(["875468955", "2018-12-24"])
    # diffs.append(["881499572", "2019-01-31"])
    # diffs.append(["886108487", "2019-02-28"])
    # diffs.append(["893675237", "2019-03-31"])
    # diffs.append(["894891613", "2019-04-30"])
    # diffs.append(["903814437", "2019-05-31"])
    # diffs.append(["904518301", "2019-06-30"])
    # diffs.append(["909048253", "2019-07-31"])
    # diffs.append(["914531563", "2019-08-30"])
    # diffs.append(["918801796", "2019-09-30"])
    # diffs.append(["923914090", "2019-10-31"])
    # diffs.append(["928760315", "2019-11-29"])
    # diffs.append(["933233310", "2019-12-27"])
    # diffs.append(["937756327", "2020-01-27"])
    # diffs.append(["946235363", "2020-03-01"])
    # diffs.append(["948036758", "2020-03-29"])
    # diffs.append(["953745575", "2020-04-26"])
    # diffs.append(["960157059", "2020-05-31"])
    # diffs.append(["965346020", "2020-06-28"])
    # diffs.append(["970837100", "2020-08-02"])
    # diffs.append(["975834550", "2020-08-30"])
    # diffs.append(["980699882", "2020-09-27"])
    # diffs.append(["980699882", "2020-11-01"])
    # diffs.append(["993043901", "2020-11-29"])
    # diffs.append(["996700532", "2020-12-28"])
    # diffs.append(["1005138548", "2021-01-31"])
    # diffs.append(["1009489391", "2021-02-28"])
    # diffs.append(["1014739821", "2021-03-28"])
    # diffs.append(["1020706834", "2021-04-25"])
    # diffs.append(["1033465399", "2021-06-27"])
    # diffs.append(["1035479760", "2021-07-25"])
    # diffs.append(["1041465735", "2021-08-29"])
    # diffs.append(["1046662909", "2021-09-26"])
    # diffs.append(["1054289016", "2021-10-31"])
    # diffs.append(["1057675523", "2021-11-29"])
    # diffs.append(["1062510735", "2021-12-28"])
    # diffs.append(["1068924896", "2022-01-30"])
    # diffs.append(["1074357607", "2022-02-27"])
    # diffs.append(["1083987625", "2022-03-27"])
    # diffs.append(["1084492205", "2022-04-24"])
    # diffs.append(["1090505125", "2022-05-29"])
    # diffs.append(["1095184567", "2022-06-26"])
    # diffs.append(["1101624049", "2022-08-01"])
    # diffs.append(["1107799905", "2022-08-31"])
    # diffs.append(["1113334346", "2022-09-30"])
    # diffs.append(["1119178263", "2022-10-31"])
    # diffs.append(["1124368652", "2022-11-28"])
    # diffs.append(["1130821218", "2023-01-01"])
    # diffs.append(["1133904318", "2023-01-16"])
    # diffs.append(["1137481351", "2023-02-04"])
    # diffs.append(["1140568603", "2023-02-20"])
    # diffs.append(["1143689119", "2023-03-09"])
    # diffs.append(["1145675251", "2023-03-20"])
    # diffs.append(["1148036183", "2023-04-03"])
    # diffs.append(["1151821801", "2023-04-26"])
    # diffs.append(["1153755153", "2023-05-08"])
    # diffs.append(["1156321293", "2023-05-22"])
    # diffs.append(["1158590270", "2023-06-05"])
    # diffs.append(["1160887554", "2023-06-19"])
    # diffs.append(["1163158814", "2023-07-03"])
    # diffs.append(["1165769449", "2023-07-17"])
    # diffs.append(["1168153610", "2023-08-01"])
    # diffs.append(["1170514187", "2023-08-15"])
    # diffs.append(["1173056112", "2023-08-31"])
    # diffs.append(["1175599041", "2023-09-16"])
    # diffs.append(["1178460319", "2023-10-03"])
    # diffs.append(["1181468695", "2023-10-23"])
    # diffs.append(["1183727590", "2023-11-06"])
    # diffs.append(["1186005807", "2023-11-20"])

    for diff in diffs:
        stwing = "https://en.wikipedia.org/w/index.php?title=Wikipedia:Wikipedia_Signpost/"
        stwing += diff[1]
        stwing += "&action=edit&summary=add%20subtitles%20with%20%5B%5BWikipedia%3AWikipedia%20Signpost%2FTechnical%2FSilly%20bespoke%20scripts%23Subtitler%7CSilly%20Bespoke%20Subtitler%5D%5D"
        print(stwing)

    for diff in diffs:
        retrieve_diff(diff[0], diff[1])



       

The Signpost · written by many · served by Sinepost V0.9 · 🄯 CC-BY-SA 4.0