added logged_users

This commit is contained in:
Amazed 2020-06-27 00:42:18 +02:00
parent 89bb4a68be
commit 3d3580fa42
2 changed files with 43 additions and 1 deletions

View File

@ -2,5 +2,6 @@
"username": "testuser",
"password": "testpassword",
"webhook": "https://discord.com/webhook/abc/def",
"logout": false
"logout": false,
"logged_users": true
}

41
main.py
View File

@ -34,13 +34,54 @@ def is_logged_in():
return b'<li id="username_logged_in" class="rightside " data-skip-responsive="true">\n\t\t\t\t\t\t<div class="header-profile dropdown-container">\n\t\t\t\t<a href="./ucp.php" class="header-avatar dropdown-trigger"> <span class="username">' + USERNAME.encode("utf8") in BROWSER.response().get_data()
connected = []
def loop():
global connected
homepage_url = "https://www.giantswd.org/forum/"
logout_url = "https://www.giantswd.org/forum/ucp.php?mode=logout"
newposts_url = "https://www.giantswd.org/forum/search.php?search_id=unreadposts"
if not is_logged_in():
login()
if config["logged_users"]:
# Send a webhook when people connect on GWD forums
print("Getting connected people...")
homepage_resp = BROWSER.open(homepage_url)
homepage_html = homepage_resp.get_data()
bs = BeautifulSoup(homepage_html, features="html5lib")
div_online = bs.find("div", attrs={"class": "online-list"})
div_username_online = div_online.find_all("a", attrs={"class": "username"})
new_users = []
for username_elem in div_username_online:
user = username_elem.contents[0]
if user not in connected:
new_users.append(user)
print("User connected: %s" % user)
webhook_data = {
"embeds": [
{
"title": "A user has logged in on GWD forums!",
"description": "**%s** has just logged in" % user,
"color": 55039,
"author": {
"name": "GiantsWD forums"
},
"footer": {
"text": ""
},
"timestamp": datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
}
]
}
requests.post(WEBHOOK_URL, json=webhook_data)
connected = new_users
# Get new posts
print("Getting new posts...")
has_newposts = False