Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/forumparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,11 @@
titleLine = xml.title.string.replace(" - openATV Forum", "") # "LCD4linux - Seite 150"
foundpos = titleLine.rfind("Seite")
threadTitle = titleLine[:foundpos - 3] if foundpos != -1 else titleLine
active = xml.find("li", {"class": "active"}) # <li class="active"><span>2</span></li>
if active:
active = active.span.get_text()
currPage = convert2int(active, 1) if active and active.isdigit() else 1
button = xml.find("a", {"class": "button", "role": "button"}).get_text("button") # <a class="button" href="./viewtopic.php?t=69626&amp;start=20" role="button">2</a>
maxPages = convert2int(button, 1) if button and button.isdigit() else currPage
threadId = xml.find("input", {"name": "t", "type": "hidden"}).get("value")

Check warning on line 122 in src/forumparser.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable "threadId" to match the regular expression ^[_a-z][a-z0-9_]*$.

See more on https://sonarcloud.io/project/issues?id=openatv_enigma2-plugin-extensions-openatv-community-reader&issues=AZzTtTKlNYLULcTcwRQU&open=AZzTtTKlNYLULcTcwRQU&pullRequest=42
button = xml.find("a", {"class": "button button-icon-only dropdown-trigger"})
if button:
pages = button.get_text().strip("Seite ").split(" von ")
currPage, maxPages = (convert2int(pages[0], 1), convert2int(pages[1], 1)) if pages and len(pages) > 1 else (1, 1)

Check warning on line 126 in src/forumparser.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable "currPage" to match the regular expression ^[_a-z][a-z0-9_]*$.

See more on https://sonarcloud.io/project/issues?id=openatv_enigma2-plugin-extensions-openatv-community-reader&issues=AZzTtTKlNYLULcTcwRQS&open=AZzTtTKlNYLULcTcwRQS&pullRequest=42

Check warning on line 126 in src/forumparser.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable "maxPages" to match the regular expression ^[_a-z][a-z0-9_]*$.

See more on https://sonarcloud.io/project/issues?id=openatv_enigma2-plugin-extensions-openatv-community-reader&issues=AZzTtTKlNYLULcTcwRQT&open=AZzTtTKlNYLULcTcwRQT&pullRequest=42
else:
currPage, maxPages = 1, 1
threadList, threadUser = [], []
Expand All @@ -150,7 +149,11 @@
setThreadKey("postTime", postBody.find("time").get_text())
setThreadKey("shortContent", postBody.find("div", {"class": "content"}).get_text(separator=" ", strip=True)[:300]) # limit content as preview
threadList.append(threadDict)
return errMsg, {"threadTitle": threadTitle, "currPage": currPage, "maxPages": maxPages, "posts": threadList, "user": list(set(threadUser))}
return errMsg, {
"threadTitle": threadTitle, "threadId": threadId,
"currPage": currPage, "maxPages": maxPages,
"posts": threadList, "user": list(set(threadUser))
}

def checkServerStatus(self):
atvpglobals.BASEURL = bytes.fromhex("687474703A2F2F7265616465722E6F70656E612E7476E"[:-1]).decode()
Expand Down Expand Up @@ -179,7 +182,7 @@
xml = BeautifulSoup(htmlData, features="lxml") # .replace('&amp;', '&') # work around BeautifulSoup bug
except Exception as errMsg:
print(f"[{MODULE_NAME}] ERROR in module 'parseThread': {errMsg}")
for post in xml.find_all("div", class_=compile("post has-profile (.*?)")):
for post in xml.find_all("div", class_=compile("post has-profile .*?")):
pId = post.get("id", "").strip("profile")
if postId != pId:
continue
Expand All @@ -188,6 +191,7 @@
postProfile = post.find("dl", {"class": "postprofile"})
if postProfile:
setPostKey("userName", postProfile.find("a", {"class": compile("username(.*?)")}))
setPostKey("online", "online" if "online" in str(post) else "")
avatar = postProfile.find("img", {"class": "avatar"})
if avatar:
avatarUrl = avatar.get("src", "").strip(".")
Expand All @@ -214,7 +218,6 @@
postBody = post.find("div", {"class": "postbody"})
if postBody:
setPostKey("postNumber", postBody.find("p", {"class": "author post-number post-number-phpbb post-number-bold"}), replacements=["\n"])
setPostKey("online", "online" if postBody.find("div", {"class": compile("post .*? online")}) else "")
setPostKey("postTime", postBody.find("time").get_text())
fullContent = postBody.find("div", {"class": "content"}).get_text()
while "\n\n\n" in fullContent: # remove multiple '\n\
Expand Down