This repository was archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvote_elections.py
More file actions
62 lines (54 loc) · 2.05 KB
/
vote_elections.py
File metadata and controls
62 lines (54 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import asyncio
from datetime import datetime
try:
import pytz
game_time = True
except:
print("We recommend installing pytz (pip install pytz) in order to get e-sim time")
game_time = False
from login import get_content
async def elect(server, your_candidate):
"""Voting in congress / president elections."""
# Functions in use: login, pytz, datetime (datetime)
your_candidate = your_candidate.lower()
URL = f"https://{server}.e-sim.org/"
if game_time:
today = int(datetime.now().astimezone(pytz.timezone('Europe/Berlin')).strftime("%d")) # game time
else:
today = int(datetime.now().strftime("%d"))
if today == 5:
president = True
link = "presidentalElections.html"
elif today == 25:
president = False
link = "congressElections.html"
else:
print("There are not elections today")
return
tree = await get_content(URL + link, login_first=True)
payload = ""
for tr in range(2, 43):
try:
name = tree.xpath(f'//*[@id="esim-layout"]//tr[{tr}]//td[2]/a/text()')[0].strip().lower()
except:
print(f"No such candidate ({your_candidate})")
return
if name == your_candidate:
if president:
candidateId = tree.xpath(f'//*[@id="esim-layout"]//tr[{tr}]/td[4]/form/input[2]')[0].value
payload = {'action': "VOTE", 'candidate': candidateId, "submit": "Vote"}
else:
candidateId = tree.xpath(f'//*[@id="esim-layout"]//tr[{tr}]//td[5]//*[@id="command"]/input[2]')[0].value
payload = {'action': "VOTE", 'candidateId': candidateId, "submit": "Vote"}
break
if payload:
url = await get_content(URL + link, data=payload)
print(url)
if __name__ == "__main__":
print(elect.__doc__)
server = input("Server: ")
candidate = input("I want to vote for this candidate: ")
loop = asyncio.get_event_loop()
loop.run_until_complete(
elect(server, candidate))
input("Press any key to continue")