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 pathadd_friends.py
More file actions
48 lines (44 loc) · 1.97 KB
/
add_friends.py
File metadata and controls
48 lines (44 loc) · 1.97 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
from login import login
import time
from lxml.html import fromstring
import json
def friends(server, option="online", session=""):
"""Sending friend request to the entire server / all online citizens"""
URL = f"https://{server}.e-sim.org/"
if not session:
session = login(server)
if option == "online":
apiOnline = session.get(f"{URL}apiOnlinePlayers.html").json()
for row in apiOnline:
row = json.loads(row)
try:
send = session.get(f"{URL}friends.html?action=PROPOSE&id={row['id']}")
if "PROPOSED_FRIEND_OK" in str(send.url):
print("Sent to:", row['login'])
except Exception as error:
print("error:", error)
time.sleep(1)
else:
get_pages_count = session.get(URL + 'citizenStatistics.html?statisticType=DAMAGE&countryId=0')
tree = fromstring(get_pages_count.content)
last = tree.xpath("//ul[@id='pagination-digg']//li[last()-1]//@href")
last = last[0].split("page=")[1]
for page in range(1, int(last) + 1):
i = session.get(URL + 'citizenStatistics.html?statisticType=DAMAGE&countryId=0&page=' + str(page))
tree = fromstring(i.content)
links = tree.xpath("//td/a/@href")
for link in links:
try:
send = session.get(f"{URL}friends.html?action=PROPOSE&id={link.split('=', 1)[1]}")
if "PROPOSED_FRIEND_OK" in str(send.url):
print(send.url)
except Exception as error:
print("error:", error)
time.sleep(1)
return session
if __name__ == "__main__":
print(friends.__doc__)
server = input("Server: ")
option = input("Send friend request to all active players, or only to those who online right now? (online/all) ")
friends(server, option)
input("Press any key to continue")