aboutsummaryrefslogtreecommitdiff
path: root/app/tasks/phpbbparser.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-05-13 23:31:42 +0100
committerrubenwardy <rw@rubenwardy.com>2018-05-13 23:33:05 +0100
commitff8bf992a9048e55b58ece46cf25cc3a43edcef7 (patch)
tree02a1a7198a9fd20539465a0ccd378f0dd02f8913 /app/tasks/phpbbparser.py
parent31615da169766087a35c104d6aa8797a6eaa7594 (diff)
downloadcheatdb-ff8bf992a9048e55b58ece46cf25cc3a43edcef7.tar.xz
Add user account claiming
Diffstat (limited to 'app/tasks/phpbbparser.py')
-rw-r--r--app/tasks/phpbbparser.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/app/tasks/phpbbparser.py b/app/tasks/phpbbparser.py
new file mode 100644
index 0000000..3932b94
--- /dev/null
+++ b/app/tasks/phpbbparser.py
@@ -0,0 +1,72 @@
+import urllib, socket
+from bs4 import *
+from urllib.parse import urljoin
+import urllib.request
+import os.path
+import time
+
+class Profile:
+ def __init__(self, username):
+ self.username = username
+ self.signature = ""
+ self.properties = {}
+
+ def set(self, key, value):
+ self.properties[key] = value
+
+ def get(self, key):
+ return self.properties[key] if key in self.properties else None
+
+ def __str__(self):
+ return self.username + "\n" + str(self.signature) + "\n" + str(self.properties)
+
+def __extract_properties(profile, soup):
+ el = soup.find(id="viewprofile")
+ if el is None:
+ return None
+
+ res = el.find_all("dl", class_ = "left-box details")
+ if len(res) != 1:
+ return None
+
+ catch_next_key = None
+
+ # Look through
+ for element in res[0].children:
+ if element.name == "dt":
+ if catch_next_key is None:
+ catch_next_key = element.text.lower()[:-1].strip()
+ else:
+ print("Unexpected dt!")
+
+ elif element.name == "dd":
+ if catch_next_key is None:
+ print("Unexpected dd!")
+ else:
+ if catch_next_key != "groups":
+ profile.set(catch_next_key, element.text)
+ catch_next_key = None
+
+ elif element and element.name is not None:
+ print("Unexpected other")
+
+def __extract_signature(soup):
+ res = soup.find_all("div", class_="signature")
+ if (len(res) != 1):
+ return None
+ else:
+ return res[0]
+
+def getProfile(url, username):
+ url = url + "/memberlist.php?mode=viewprofile&un=" + username
+
+ contents = urllib.request.urlopen(url).read().decode("utf-8")
+ soup = BeautifulSoup(contents, "lxml")
+ if soup is None:
+ return None
+ else:
+ profile = Profile(username)
+ profile.signature = __extract_signature(soup)
+ __extract_properties(profile, soup)
+
+ return profile