Difference between revisions of "Talk:Kelas Metoda Numerik 02 Sem. Gasal 2020/21"

From ccitonlinewiki
Jump to: navigation, search
m (Regarding the Revision from Lists to Tables)
m (Regarding the Revision from Lists to Tables)
 
Line 13: Line 13:
 
<syntaxhighlight lang="python3">
 
<syntaxhighlight lang="python3">
 
# Python code that transforms a Wiki markup text [single unordered list]
 
# Python code that transforms a Wiki markup text [single unordered list]
# into an alphabetized Wiki markup text [sortable table]
+
# into a Wiki markup text [alphabetized sortable table]
 
# Christopher S.E.
 
# Christopher S.E.
 
# November 2020
 
# November 2020

Latest revision as of 21:55, 11 November 2020

Regarding the Revision from Lists to Tables

Christopher Salendu Erwin recently edited the following page : Kelas Metoda Numerik 02 Sem. Gasal 2020/21

What was changed: converted the simple unordered list of [Nama] into an alphabetized sortable table of [Foto | NPM | Nama]

The following image was uploaded as a placeholder asset for the photo: Blankprofile.png

The names and their respective links remain unchanged. However, the NPM codes and photos have to be modified separately and manually.

A variation of the following Python code was used to transform the Wiki markup text into the current format.

# Python code that transforms a Wiki markup text [single unordered list]
# into a Wiki markup text [alphabetized sortable table]
# Christopher S.E.
# November 2020

def students_list():
    """Original Wiki markup text representing list of students, formatted as a string"""
    students = """*[[Calvin rahmat pratama]]
    *[[Abraham Mahendiartha Putra]]
    *[[Muhammad Rasyaad Dzaky]]
    *[[Reza Adyanto]]
    *[[Ethanael Hanusa]]
    *[[Fashal Firdaus Amarullah]]
    *[[John Patrick Anhar]]
    *[[Revaldy Putra Agatha]]
    *[[John Audrick]]
    *[[Oka Widiantara Suputra]]
    *[[Tri Aji Setyawan]]
    *[[JosiahEnrico]]
    *[[Cornelia Christiani Vianney]]
    *[[Moh Khairul Imam Assidiqqi]]
    *[[Hikaru Trinita Salsabila]]
    *[[Yogi Gunawan Atmawijaya]]
    *[[Faizal Rikaz Al Muntaqo]]
    *[[Fakhri Hawari Muhammad]]
    *[[Iman Herlana]]
    *[[Muhammad Faja Taufiqurrahman]]
    *[[Muhammad Helmy Yusuf]]
    *[[Rai Zulfikar Satriagama]]
    *[[Diyas Prawara Mahdi]]
    *[[Muhammad Fadhil Zuhdi]]
    *[[Diagy Alwan Irsyad]]
    *[[Tedi Veradino]]
    *[[Alvi Arya Ramadhan]]
    *[[Rezky Alfian Fatra]]
    *[[Umar]]
    *[[Norman Febrianto]]
    *[[Christopher Salendu Erwin]]
    *[[Musyafi Albar]]
    *[[Richardo Ariyanto]]
    *[[Eduardo Christ Soloman]]
    *[[M. Raja]]
    *[[Muhammad Hasfi Rizki Nur]]
    *[[Ardiya Prajna Hardianto]]
    *[[Farissthira Sahasrabhanu]]"""
    return students


def listparser(stringlist):
    """Parses through string to find names, and outputs names as a python list"""
    parsedlist = []
    name = ""
    i = 0       # i represents the character pointer
    while i < len(stringlist):
        char = stringlist[i]
        if char in ('*', '[', ']', ' ', '\n'):
            pass
        else:
            while True:
                char = stringlist[i]
                if char == ']':
                    parsedlist.append(name)
                    name = ""
                    break
                else:
                    name = name + char
                i += 1
        i += 1
    return parsedlist


def table_format(studentlist):
    """Sorts the python list alphabetically and prints out a string
        representing Wiki markup text for a sortable table"""
    studentlist.sort()

    # Wiki markup text for beginning and end of table
    top = """{| class=\"wikitable sortable\"
|-
! No !!  Photo  !!   NPM   !! Name
|-"""
    bottom = "|}"

    # Prints out the table containing the names within the student list
    print(top)
    for student in studentlist:
        i = studentlist.index(student) + 1
        print(f"| {i} || [[File:Blankprofile.png|100x100px]] || 0000000000 || [[{student}]]")
        print("|-")
    print(bottom)


def menu():
    """Main sequence of the program"""
    studentstring = students_list()
    studentlist = listparser(studentstring)
    print(studentlist)
    print()
    table_format(studentlist)


if __name__ == '__main__':
    menu()