Added tasks integration

This commit is contained in:
t3xhno 2024-02-06 21:17:49 +01:00
parent 1e56a84a4c
commit 97d613df58
2 changed files with 17 additions and 0 deletions

View File

@ -23,4 +23,7 @@ def command(msg, rcpt):
elif msg.startswith("!wiki"):
cmd, query = msg.split(" ", 1)
return sf.query_external_website("https://en.wikipedia.org", "/wiki/" + query)
elif msg.startswith("!tasks"):
content = sf.getDmzTasks()
return content

View File

@ -17,3 +17,17 @@ def query_external_website(base_url, query):
return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content.text + "\n\nFULL LINK:\n" + base_url + quote(query)
except Exception as e:
return e
def getDmzTasks():
try:
page = requests.get("https://todo.dmz.rs/")
soup = BeautifulSoup(page.content, "html.parser")
tasks = soup.find_all(class_="task")
result = "\nActive tasks:\n"
for task in tasks:
taskIndex = task.select("div")[0].text
taskTitle = task.select("div")[1].text
result += taskIndex + " " + taskTitle + "\n"
return result
except Exception as e:
return e