Added more info for dmz tasks

This commit is contained in:
t3xhno 2024-02-06 22:06:06 +01:00
parent adb4a25d25
commit d08e8199f8

View File

@ -2,10 +2,14 @@ import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from urllib.parse import quote from urllib.parse import quote
def getSoup(base_url, query = ""):
page = requests.get(base_url + quote(query))
soup = BeautifulSoup(page.content, "html.parser")
return soup
def query_external_website(base_url, query): def query_external_website(base_url, query):
try: try:
page = requests.get(base_url + quote(query)) soup = getSoup(base_url, query)
soup = BeautifulSoup(page.content, "html.parser")
title = soup.find(id="firstHeading").text title = soup.find(id="firstHeading").text
mainContentElement = soup.find(id="mw-content-text") mainContentElement = soup.find(id="mw-content-text")
if "This page is a redirect" in mainContentElement.text: if "This page is a redirect" in mainContentElement.text:
@ -20,14 +24,26 @@ def query_external_website(base_url, query):
def getDmzTasks(url): def getDmzTasks(url):
try: try:
page = requests.get(url) soup = getSoup(url)
soup = BeautifulSoup(page.content, "html.parser")
tasks = soup.find_all(class_="task") tasks = soup.find_all(class_="task")
result = "\nActive tasks:\n" result = "\nActive tasks:\n"
for task in tasks: for task in tasks:
taskIndex = task.select("div")[0].text taskIndex = task.select("div")[0].text
taskTitle = task.select("div")[1].text taskTitle = task.select("div")[1].text
result += taskIndex + " " + taskTitle + " | " + "Link: " + url + task.find("a")["href"][1:] + "\n" result += taskIndex + " " + taskTitle
taskSoup = getSoup(url + task.find("a")["href"][1:])
description = taskSoup.find("main").select("section")[0].find("p").text
result += "\n\tDescription:\n" + "\t\t" + description + "\n"
result += "\tAssigned users:\n" + "\t\t"
assignedUsers = taskSoup.find_all(class_="user-info-wrap")
if len(assignedUsers) == 0:
result += "None! Be the first :)\n"
result += "\tLink: " + url + task.find("a")["href"][1:] + "\n\n"
continue
usersList = ""
for user in assignedUsers:
usersList += user.find("div").text.split(": ")[1] + ", "
result += usersList[:-2] + "\n\n"
return result return result
except Exception as e: except Exception as e:
return e return e