Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,3 @@ async def wikithought() -> JSONResponse:
"""
returned_page_data: dict[str, str] = await wikithoughts.get_next_display()
return JSONResponse(returned_page_data)

39 changes: 24 additions & 15 deletions src/core/wikithoughts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def clean_wikitext(text: str) -> str:

# ^^CSH Account^^ -> User CSH Account
text = re.sub(r"\^\^([^\]]+)\^\^", r"User \1", text)

# Remove templates {{...}}
text = re.sub(r"\{\{.*?\}\}", "", text, flags=re.DOTALL)

Expand Down Expand Up @@ -183,13 +183,17 @@ async def refresh_category_pages() -> list[str]:
last_modifed = response.headers.get("Last-Modified")

r_json: dict[str, str] = response.json()
for page in r_json["query"]["categorymembers"]:
titles.append(page["title"])

# Loop to keep everything going
if "continue" in r_json:
params["cmcontinue"] = r_json["continue"]["cmcontinue"]
if "query" in r_json:
for page in r_json["query"]["categorymembers"]:
titles.append(page["title"])

# Loop to keep everything going
if "continue" in r_json:
params["cmcontinue"] = r_json["continue"]["cmcontinue"]
else:
break
else:
logger.warning(f"Failure in obtaining info, JSON:\n{r_json}")
break
else:
logger.warning("Failed to update the CSH wiki page!")
Expand Down Expand Up @@ -233,17 +237,21 @@ async def refresh_page_dictionary() -> None:

for r in responses:
r_json = r.json()
for page in r_json["query"]["pages"].values():
wikitext = page["revisions"][0]["slots"]["main"]["*"]
if "query" in r_json:
for page in r_json["query"]["pages"].values():
wikitext = page["revisions"][0]["slots"]["main"]["*"]

cleaned_text = clean_wikitext(wikitext) # unfuck the text
cleaned_text = clean_wikitext(wikitext) # unfuck the text

paragraphs = cleaned_text.split("\n\n") # Cut the first line
first_paragraph = (
paragraphs[0].strip() if paragraphs else ""
) # Incase nick messes up?
paragraphs = cleaned_text.split("\n\n") # Cut the first line
first_paragraph = (
paragraphs[0].strip() if paragraphs else ""
) # Incase nick messes up?

results[page["title"]] = first_paragraph
results[page["title"]] = first_paragraph
else:
logger.warning(f"Failure in refreshing the wiki page dictionary, JSON:\n{r_json}")
results = {"ERROR":"ERROR"}

page_dict_cache = results

Expand Down Expand Up @@ -287,6 +295,7 @@ async def get_next_display() -> dict[str, str]:
"page": "ERROR GETTING PAGE",
"content": "ERROR FETCHING CONTENT",
}
return
elif queue_empty:
reset_queues()
queue_empty = False
Expand Down
Loading