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 pathmerge_storage.py
More file actions
65 lines (56 loc) · 2.66 KB
/
merge_storage.py
File metadata and controls
65 lines (56 loc) · 2.66 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
63
64
65
from login import login
import time
from lxml.html import fromstring
def merge(server, ids, session=""):
"""
Merge specific EQ IDs / all EQs in storage (good for non-premium players).
For all eqs under specific Q, write that Q.
Specific ids: separated them by a comma.
Examples:
merge("alpha", "Q6") -> Merge all Q1-6 eqs in your storage.
merge("alpha", "10, 15, 18") -> Merge eqs id 10, 15 and 18
"""
URL = f"https://{server}.e-sim.org/"
if not session:
session = login(server)
if "," in ids:
EQ1, EQ2, EQ3 = [eq.strip() for eq in ids.split(",")]
payload = {'action': "MERGE", f'itemId[{EQ1}]': EQ1, f'itemId[{EQ2}]': EQ2, f'itemId[{EQ3}]': EQ3}
merge_request = session.post(URL + "equipmentAction.html", data=payload)
print(merge_request.url)
else:
max_q_to_merge = int(ids.lower().replace("q", "")) # max_q_to_merge - including
for _ in range(5):
get_eqs = session.get(f'{URL}storage.html?storageType=EQUIPMENT')
tree = fromstring(get_eqs.content)
IDs = tree.xpath(f'//*[starts-with(@id, "cell")]/a/text()')
items = tree.xpath(f'//*[starts-with(@id, "cell")]/b/text()')
DICT = {}
for ID, item in zip(IDs, items):
Q = int(item.split()[0].replace("Q", ""))
if Q < max_q_to_merge + 1:
if Q not in DICT:
DICT[Q] = []
DICT[Q].append(int(ID.replace("#", "")))
for i in range(1, max_q_to_merge + 1):
if i in DICT and len(DICT[i]) > 2:
for z in range(int(len(DICT[i]) / 3)):
EQ1, EQ2, EQ3 = DICT[i][z*3:z*3 + 3]
payload = {'action': "MERGE", f'itemId[{EQ1}]': EQ1, f'itemId[{EQ2}]': EQ2,
f'itemId[{EQ3}]': EQ3}
merge_request = session.post(URL + "equipmentAction.html", data=payload)
print(merge_request.url)
time.sleep(1)
if str(merge_request.url) == "http://www.google.com/":
# e-sim error
time.sleep(5)
elif "?actionStatus=CONVERT_ITEM_OK" not in str(merge_request.url):
# no money etc
break
return session
if __name__ == "__main__":
print(merge.__doc__)
server = input("Server: ")
ids = input("EQs ids, or max Q to merge: ")
merge(server, ids)
input("Press any key to continue")