User:Hkm/Rankings program: Difference between revisions

Hkm (talk | contribs)
No edit summary
Hkm (talk | contribs)
No edit summary
Line 9: Line 9:


def process_talk(url):
def process_talk(url):
    #pattern= r'^([^:]+):\s+([^.]*)\.\s+([0-9.]+)$'
     pattern = r'^([^:]+):\s+(.*)\.\s+([0-9.]+)$'
     pattern = r'^([^:]+):\s+(.*)\.\s+([0-9.]+)$'
     data = {}
     data = {}
Line 39: Line 40:
                 continue
                 continue
                  
                  
             if len(thing_a) > 40 or len(thing_b) > 70:
             if len(thing_a) > 40 or len(thing_b) > 100:
                 continue
                 continue


Line 79: Line 80:
         (before, after) = raw_text.split('{|', 1)
         (before, after) = raw_text.split('{|', 1)
         (raw_text, after) = after.split('|}', 1)
         (raw_text, after) = after.split('|}', 1)
        if after[0] == "\n":
            after = after[1:]
        # add "last updated by"
        index = after.find('\n')
        first_part = after[:index + 1]
        rest_part = after[index + 1:]
        if first_part.startswith("Last updated by"):
            new_first = "\nLast updated by ~~~~.\n"
            after = new_first + rest_part
        else:
            after = "\nLast updated by ~~~~.\n" + after


         # Preprocess the text: replace newline followed by | with ||, then split into entries
         # Preprocess the text: replace newline followed by | with ||, then split into entries
Line 172: Line 186:
clip = before
clip = before


clip += '''{| class="wikitable sortable" style="margin: auto;"
clip += '''{| class="wikitable sortable" style="margin: auto; max-width: 800px; width: 100%;"
! Creator !! Work !! Tuning !! Notes !! R !! #
! Creator !! Work !! Tuning !! Notes !! R !! #


'''
'''


# print from talk page
for (author, work), (rating, pop) in sorted(averages.items(), key=lambda a: -a[1][0]):
for (author, work), (rating, pop) in sorted(averages.items(), key=lambda a: -a[1][0]):
     tuning, notes, _, link = data.setdefault((author, work), ("", "", "", ""))
     tuning, notes, _, link = data.setdefault((author, work), ("", "", "", ""))
Line 184: Line 199:
         clip += (f"|-\n| {author} || {work} || {tuning} || {notes} || {rating:.2f} || {pop}\n")
         clip += (f"|-\n| {author} || {work} || {tuning} || {notes} || {rating:.2f} || {pop}\n")


# print main pages not in talk page
for i in data:
    if (i[0], i[1]) not in averages:
        (author, work) = i
        tuning, notes, _, link = data.setdefault((author, work), ("", "", "", ""))
        if link:
            clip += (f"|-\n| {author} || [{link} {work}] || {tuning} || {notes} || || \n")
        else:
            clip += (f"|-\n| {author} || {work} || {tuning} || {notes} || || \n")
       
clip += "|}"
clip += "|}"


clip += after
clip += after
pyperclip.copy(clip)
pyperclip.copy(clip)


‎</syntaxhighlight>
‎</syntaxhighlight>