News:

The moderation team is holding a poll on the topic of the site's connection to Scratch. More details can be found here. Your feedback is appreciated.

Main Menu

If this gets a post ID of 65536, we advance! (The cooler version)

Started by Incendiary, Dec 13, 2023, 02:56:31 PM

Previous topic - Next topic

Luigis_Pizza

bored bored bored bored bred boredb ored bored breod broe dnfjkasndjgkhbwknsm
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Imma try python anywhere, let's see how it goes at 12:00
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Bored bored bored boed bored noredb orbed orbeod bajkwdbfgadsiujkn
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

The only reason i see it not working is the random.json file not being recognized by the site, even though it is stored in the same place...
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

oh well, trial and error, I could run it now but nah
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

I got just offered a scholarship to pay for my schooling....
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

bored bored bored bored bired boed broedbreo 3beddsljnKHSASJK
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)



Luigis_Pizza

Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


realicraft

Quote from: Luigis_Pizza on Aug 09, 2024, 11:40:31 AM
Quote from: realicraft on Aug 09, 2024, 11:35:55 AM
Quote from: Luigis_Pizza on Aug 09, 2024, 10:03:38 AM@realicraft how's the framework going?
it isn't (as usual)
I can help if you want
maybe
can you understand this:
Code ("Python 3.9") Select
def logIn(headers: dict, username: str, password: str) -> bool:
    global loggedin
    requireInit("Tried to login without initializing the forum module.")
    session.get(forum_url) # "initialize" the PHPSESSID cookie
    loginPage = session.get(f"{forum_url}index.php?action=login", headers=headers)
    hidden_val = lxml.etree.HTML(loginPage.text.encode()).xpath('//*[@id="frmLogin"]/input') # borrowed from Lithium (https://replit.com/@ByronInc/Lithium-20)
    formdata = {"user": username, "passwrd": password, "cookielength": 3153600}
    for v in hidden_val: # also borrowed from Lithium (https://replit.com/@ByronInc/Lithium-20)
        formdata[v.get("name")] = v.get("value")
    loginReq = session.post(f"{forum_url}index.php?action=login2", headers=headers, data=formdata)
    if (loginReq.url.endswith("index.php")):
        print("Successfully logged in.")
        time.sleep(1)
        loggedin = True
        return True
    elif (loginReq.url.endswith("?action=agreement")):
        raise RuntimeError("Login succeeded, but account hasn't agreed to the Registration Agreement and thus cannot continue.")
    else:
        raise RuntimeError("Failed to login; double-check your password and try again.")

Luigis_Pizza

Quote from: realicraft on Aug 09, 2024, 11:44:44 AM
Quote from: Luigis_Pizza on Aug 09, 2024, 11:40:31 AM
Quote from: realicraft on Aug 09, 2024, 11:35:55 AM
Quote from: Luigis_Pizza on Aug 09, 2024, 10:03:38 AM@realicraft how's the framework going?
it isn't (as usual)
I can help if you want
maybe
can you understand this:
Code ("Python 3.9") Select
def logIn(headers: dict, username: str, password: str) -> bool:
    global loggedin
    requireInit("Tried to login without initializing the forum module.")
    session.get(forum_url) # "initialize" the PHPSESSID cookie
    loginPage = session.get(f"{forum_url}index.php?action=login", headers=headers)
    hidden_val = lxml.etree.HTML(loginPage.text.encode()).xpath('//*[@id="frmLogin"]/input') # borrowed from Lithium (https://replit.com/@ByronInc/Lithium-20)
    formdata = {"user": username, "passwrd": password, "cookielength": 3153600}
    for v in hidden_val: # also borrowed from Lithium (https://replit.com/@ByronInc/Lithium-20)
        formdata[v.get("name")] = v.get("value")
    loginReq = session.post(f"{forum_url}index.php?action=login2", headers=headers, data=formdata)
    if (loginReq.url.endswith("index.php")):
        print("Successfully logged in.")
        time.sleep(1)
        loggedin = True
        return True
    elif (loginReq.url.endswith("?action=agreement")):
        raise RuntimeError("Login succeeded, but account hasn't agreed to the Registration Agreement and thus cannot continue.")
    else:
        raise RuntimeError("Failed to login; double-check your password and try again.")

Yes, I believe gaul also used similar login code to byrons lithium project, just a sec let me grab it.

def login():
    global main_session
    obtain_login = main_session.get(FORUM_URL + "index.php?action=login")
    hidden_val = lxml.etree.HTML(obtain_login.text.encode()).xpath('//*[@id="frmLogin"]/input')
    form = {"user": NAME, "passwrd": PASS, "cookielength": 31536000}
    for v in hidden_val:
        form[v.get("name")] = v.get("value")
    login_req = main_session.post(
        FORUM_URL + "index.php?action=login2",
        data=form)
    if login_req.status_code == 200:
        print("Login successful")
    else:
        print("Failed to login")
    return login_req.status_code
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Quote from: Luigis_Pizza on Aug 09, 2024, 11:52:07 AM
Quote from: realicraft on Aug 09, 2024, 11:44:44 AM
Quote from: Luigis_Pizza on Aug 09, 2024, 11:40:31 AM
Quote from: realicraft on Aug 09, 2024, 11:35:55 AM
Quote from: Luigis_Pizza on Aug 09, 2024, 10:03:38 AM@realicraft how's the framework going?
it isn't (as usual)
I can help if you want
maybe
can you understand this:
Code ("Python 3.9") Select
def logIn(headers: dict, username: str, password: str) -> bool:
    global loggedin
    requireInit("Tried to login without initializing the forum module.")
    session.get(forum_url) # "initialize" the PHPSESSID cookie
    loginPage = session.get(f"{forum_url}index.php?action=login", headers=headers)
    hidden_val = lxml.etree.HTML(loginPage.text.encode()).xpath('//*[@id="frmLogin"]/input') # borrowed from Lithium (https://replit.com/@ByronInc/Lithium-20)
    formdata = {"user": username, "passwrd": password, "cookielength": 3153600}
    for v in hidden_val: # also borrowed from Lithium (https://replit.com/@ByronInc/Lithium-20)
        formdata[v.get("name")] = v.get("value")
    loginReq = session.post(f"{forum_url}index.php?action=login2", headers=headers, data=formdata)
    if (loginReq.url.endswith("index.php")):
        print("Successfully logged in.")
        time.sleep(1)
        loggedin = True
        return True
    elif (loginReq.url.endswith("?action=agreement")):
        raise RuntimeError("Login succeeded, but account hasn't agreed to the Registration Agreement and thus cannot continue.")
    else:
        raise RuntimeError("Failed to login; double-check your password and try again.")

Yes, I believe gaul also used similar login code to byrons lithium project, just a sec let me grab it.

def login():
    global main_session
    obtain_login = main_session.get(FORUM_URL + "index.php?action=login")
    hidden_val = lxml.etree.HTML(obtain_login.text.encode()).xpath('//*[@id="frmLogin"]/input')
    form = {"user": NAME, "passwrd": PASS, "cookielength": 31536000}
    for v in hidden_val:
        form[v.get("name")] = v.get("value")
    login_req = main_session.post(
        FORUM_URL + "index.php?action=login2",
        data=form)
    if login_req.status_code == 200:
        print("Login successful")
    else:
        print("Failed to login")
    return login_req.status_code
I believe I used your login code that you got from byron to build gaul, and then went from there
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


realicraft

what about this (function name, string passed to requireInit, and comments removed)
Code ("Python 3.9") Select
def ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")
    if (not bypassCache):
        try:
            post = loadPostFromCache(pID)
        except NotInCacheException:
            pass
        else:
            return post
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
    postTree = html.fromstring(postPage.content)
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
    post = Post(pID, message, user, thread, subject, icon, date)
    return post

Luigis_Pizza

I think i named gauls task wrong so imma try again at 02:30 UTC
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Quote from: realicraft on Aug 09, 2024, 12:05:10 PMwhat about this (function name, string passed to requireInit, and comments removed)
Code ("Python 3.9") Select
def ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")
    if (not bypassCache):
        try:
            post = loadPostFromCache(pID)
        except NotInCacheException:
            pass
        else:
            return post
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
    postTree = html.fromstring(postPage.content)
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
    post = Post(pID, message, user, thread, subject, icon, date)
    return post

This looks as if it is a parsing system for each post? Used to grab and parse the information?
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


realicraft

Quote from: Luigis_Pizza on Aug 09, 2024, 12:10:45 PM
Quote from: realicraft on Aug 09, 2024, 12:05:10 PMwhat about this (function name, string passed to requireInit, and comments removed)
Code ("Python 3.9") Select
def ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")
    if (not bypassCache):
        try:
            post = loadPostFromCache(pID)
        except NotInCacheException:
            pass
        else:
            return post
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
    postTree = html.fromstring(postPage.content)
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
    post = Post(pID, message, user, thread, subject, icon, date)
    return post

This looks as if it is a parsing system for each post? Used to grab and parse the information?
yes

but can you add comments to it explaining the different parts

Luigis_Pizza

def ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")

#Check if post can be retrieved from cache
    if (not bypassCache):
        try:
#Attempt loading of post from cache
            post = loadPostFromCache(pID)
        except NotInCacheException:
#If not from cache, fetch the post from the web
            pass
        else:
#if found in cache, then return the results
            return post
#Fetch contents of page
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
#Parse the HTML content to create an XML tree structure
    postTree = html.fromstring(postPage.content)
#Fetch user page
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
#Fetch the thread link element via XPath
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
#Fetch Date (timestamp) of post
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
#fetch any icon elements that represent the post
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
#Fetch the content of the post in XML format
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
#Fetch message content from the previously extracted XML format
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
#Fetch user ID from previusly found user link
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
#Fetch topic thread id from previously found thread link
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
#fetching and parsing the title (or subject) of the post
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
#Fetch the date in string form, and then change it to an object
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
#check validity of post icon to find which is used, and then extract the name
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
#Create a post object
    post = Post(pID, message, user, thread, subject, icon, date)
#Return the post
    return post

I added the comments above each line

May have done a bit much, but I got as much down as I could
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Quote from: Luigis_Pizza on Aug 09, 2024, 12:25:36 PMdef ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")

#Check if post can be retrieved from cache
    if (not bypassCache):
        try:
#Attempt loading of post from cache
            post = loadPostFromCache(pID)
        except NotInCacheException:
#If not from cache, fetch the post from the web
            pass
        else:
#if found in cache, then return the results
            return post
#Fetch contents of page
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
#Parse the HTML content to create an XML tree structure
    postTree = html.fromstring(postPage.content)
#Fetch user page
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
#Fetch the thread link element via XPath
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
#Fetch Date (timestamp) of post
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
#fetch any icon elements that represent the post
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
#Fetch the content of the post in XML format
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
#Fetch message content from the previously extracted XML format
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
#Fetch user ID from previusly found user link
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
#Fetch topic thread id from previously found thread link
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
#fetching and parsing the title (or subject) of the post
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
#Fetch the date in string form, and then change it to an object
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
#check validity of post icon to find which is used, and then extract the name
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
#Create a post object
    post = Post(pID, message, user, thread, subject, icon, date)
#Return the post
    return post

I added the comments above each line

May have done a bit much, but I got as much down as I could
Very impressive amount of elements, last time I had gaul try something like this (The fisb incident) I looked solely at page and post contents, thus why it was basic and doomed to fail
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


Luigis_Pizza

Quote from: Luigis_Pizza on Aug 09, 2024, 12:28:46 PM
Quote from: Luigis_Pizza on Aug 09, 2024, 12:25:36 PMdef ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")

#Check if post can be retrieved from cache
    if (not bypassCache):
        try:
#Attempt loading of post from cache
            post = loadPostFromCache(pID)
        except NotInCacheException:
#If not from cache, fetch the post from the web
            pass
        else:
#if found in cache, then return the results
            return post
#Fetch contents of page
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
#Parse the HTML content to create an XML tree structure
    postTree = html.fromstring(postPage.content)
#Fetch user page
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
#Fetch the thread link element via XPath
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
#Fetch Date (timestamp) of post
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
#fetch any icon elements that represent the post
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
#Fetch the content of the post in XML format
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
#Fetch message content from the previously extracted XML format
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
#Fetch user ID from previusly found user link
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
#Fetch topic thread id from previously found thread link
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
#fetching and parsing the title (or subject) of the post
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
#Fetch the date in string form, and then change it to an object
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
#check validity of post icon to find which is used, and then extract the name
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
#Create a post object
    post = Post(pID, message, user, thread, subject, icon, date)
#Return the post
    return post

I added the comments above each line

May have done a bit much, but I got as much down as I could
Very impressive amount of elements, last time I had gaul try something like this (The fisb incident) I looked solely at page and post contents, thus why it was basic and doomed to fail
I did this mainly because I was being lazy and did not really care that much about the result as this was the suggestion:
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)


realicraft

Quote from: Luigis_Pizza on Aug 09, 2024, 12:25:36 PMdef ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")

#Check if post can be retrieved from cache
    if (not bypassCache):
        try:
#Attempt loading of post from cache
            post = loadPostFromCache(pID)
        except NotInCacheException:
#If not from cache, fetch the post from the web
            pass
        else:
#if found in cache, then return the results
            return post
#Fetch contents of page
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
#Parse the HTML content to create an XML tree structure
    postTree = html.fromstring(postPage.content)
#Fetch user page
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
#Fetch the thread link element via XPath
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
#Fetch Date (timestamp) of post
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
#fetch any icon elements that represent the post
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
#Fetch the content of the post in XML format
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
#Fetch message content from the previously extracted XML format
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
#Fetch user ID from previusly found user link
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
#Fetch topic thread id from previously found thread link
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
#fetching and parsing the title (or subject) of the post
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
#Fetch the date in string form, and then change it to an object
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
#check validity of post icon to find which is used, and then extract the name
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
#Create a post object
    post = Post(pID, message, user, thread, subject, icon, date)
#Return the post
    return post

I added the comments above each line

May have done a bit much, but I got as much down as I could
you can put comments to the right of each line, comments should be indented the same as the code, and some lines don't need comments (such as the last one)
here's the real one
Code (Python 3.9) Select
def getPostFromID(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    """Requests and loads the post with the specified ID."""
    requireInit("Tried to get a post without initializing the forum module.")
    if (not bypassCache):
        try: # try to load the post from the cache
            post = loadPostFromCache(pID)
        except NotInCacheException: # if it fails, continue on to manually getting it
            pass
        else: # if it succeeds, return the post from the cache
            return post
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
    postTree = html.fromstring(postPage.content)
    # get user id, thread id, subject, icon, and date
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
    # get message via index.php?action=quotefast
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content # not using html.fromstring because this is xml, not html
    # finalize message
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
    # finalize user
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
    # finalize thread
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
    # finalize subject
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
    # finalize date
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
    # finalize icon
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
    # create Post object
    post = Post(pID, message, user, thread, subject, icon, date)
    return post

Luigis_Pizza

Quote from: realicraft on Aug 09, 2024, 12:34:07 PM
Quote from: Luigis_Pizza on Aug 09, 2024, 12:25:36 PMdef ???(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    requireInit("???")

#Check if post can be retrieved from cache
    if (not bypassCache):
        try:
#Attempt loading of post from cache
            post = loadPostFromCache(pID)
        except NotInCacheException:
#If not from cache, fetch the post from the web
            pass
        else:
#if found in cache, then return the results
            return post
#Fetch contents of page
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
#Parse the HTML content to create an XML tree structure
    postTree = html.fromstring(postPage.content)
#Fetch user page
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
#Fetch the thread link element via XPath
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
#Fetch Date (timestamp) of post
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
#fetch any icon elements that represent the post
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
#Fetch the content of the post in XML format
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content
#Fetch message content from the previously extracted XML format
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
#Fetch user ID from previusly found user link
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
#Fetch topic thread id from previously found thread link
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
#fetching and parsing the title (or subject) of the post
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
#Fetch the date in string form, and then change it to an object
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
#check validity of post icon to find which is used, and then extract the name
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
#Create a post object
    post = Post(pID, message, user, thread, subject, icon, date)
#Return the post
    return post

I added the comments above each line

May have done a bit much, but I got as much down as I could
you can put comments to the right of each line, comments should be indented the same as the code, and some lines don't need comments (such as the last one)
here's the real one
Code (Python 3.9) Select
def getPostFromID(headers: dict, pID: int, *, bypassCache: bool=False) -> Post:
    """Requests and loads the post with the specified ID."""
    requireInit("Tried to get a post without initializing the forum module.")
    if (not bypassCache):
        try: # try to load the post from the cache
            post = loadPostFromCache(pID)
        except NotInCacheException: # if it fails, continue on to manually getting it
            pass
        else: # if it succeeds, return the post from the cache
            return post
    postPage = session.get(f"{forum_url}index.php?msg={pID}", headers=headers)
    postTree = html.fromstring(postPage.content)
    # get user id, thread id, subject, icon, and date
    userA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[1]/h4/a')[0]
    threadA = postTree.xpath(f'//*[@id="inner_section"]/div[3]/ul/li[4]/a')[0]
    dateA = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/a')[0]
    iconImg1 = postTree.xpath(f'//*[@id="msg_icon_{pID}"]')
    iconImg2 = postTree.xpath(f'//*[@id="msg{pID}"]/div/div[2]/div[1]/div[2]/span[1]/img')
    # get message via index.php?action=quotefast
    quotePage = session.get(f"{forum_url}index.php?action=quotefast;quote={pID};xml", headers=headers)
    quoteContent = quotePage.content # not using html.fromstring because this is xml, not html
    # finalize message
    message = str(quoteContent, "utf-8").split("<quote>")[1].split("</quote>")[0]
    # finalize user
    user = int(html.tostring(userA).decode("utf-8").split("?action=profile;u=")[1].split("\" title=\"View the profile of")[0])
    # finalize thread
    thread = int(html.tostring(threadA).decode("utf-8").split("index.php?topic=")[1].split(".")[0])
    # finalize subject
    subject = html.tostring(dateA).decode("utf-8").split(" title=\"")[1].split("\"")[0]
    # finalize date
    dateString = dateA.text_content()
    date = convertStrToDate(dateString)
    # finalize icon
    if (len(iconImg1) == 1):
        iconImg = iconImg1[0]
    else:
        iconImg = iconImg2[0]
    icon = html.tostring(iconImg).decode("utf-8").split("/post/")[1].split(".png\"")[0]
    # create Post object
    post = Post(pID, message, user, thread, subject, icon, date)
    return post
Yeah I definitely went overboard on the comments
Nah I'd win
Status Message: Website Updated! Check It!
Join the Crisis!
Call me Luigi or Matt/Matthew. I like JJBA. I released a game on gamejolt under Ernie_Games_Official. Made the 666666th post and I used to be the most active because I have no life...
JoJo's Bizarre Adventure is awesome
My discord is phantomluigi, please contact me if you want to chat im bored (or send me an email)