Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit d64943f

Browse files
fixed
1 parent aee27a7 commit d64943f

File tree

6 files changed

+69
-38
lines changed

6 files changed

+69
-38
lines changed

Fight/fight.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from login import login
22
import __init__
33
from Basic.fly import fly
4+
from Help_functions._bot_functions import send_fight_request
45

56
import requests
67
from lxml.html import fromstring
78
import time
89

10+
911
def fight(link, side, weaponQuality="0", dmg_or_hits="100kk", ticketQuality="5", session=""):
1012
"""
1113
Dumping limits in specific battle.
@@ -23,13 +25,13 @@ def fight(link, side, weaponQuality="0", dmg_or_hits="100kk", ticketQuality="5",
2325
session = login(server)
2426
r = session.get(link)
2527
print(r.url)
26-
tree = fromstring(r.content)
27-
food_limit = tree.xpath('//*[@id="sfoodQ5"]/text()')[0]
28-
gift_limit = tree.xpath('//*[@id="sgiftQ5"]/text()')[0]
29-
food = int(float(tree.xpath('//*[@id="foodLimit2"]')[0].text))
30-
gift = int(float(tree.xpath('//*[@id="giftLimit2"]')[0].text))
28+
main_tree = fromstring(r.content)
29+
food_limit = main_tree.xpath('//*[@id="sfoodQ5"]/text()')[0]
30+
gift_limit = main_tree.xpath('//*[@id="sgiftQ5"]/text()')[0]
31+
food = int(float(main_tree.xpath('//*[@id="foodLimit2"]')[0].text))
32+
gift = int(float(main_tree.xpath('//*[@id="giftLimit2"]')[0].text))
3133
if weaponQuality != "0":
32-
wep = tree.xpath(f'//*[@id="Q{weaponQuality}WeaponStock"]/text()')[0]
34+
wep = main_tree.xpath(f'//*[@id="Q{weaponQuality}WeaponStock"]/text()')[0]
3335
else:
3436
wep = "unlimited"
3537

@@ -54,8 +56,7 @@ def fight(link, side, weaponQuality="0", dmg_or_hits="100kk", ticketQuality="5",
5456
start = time.time()
5557
update = 1
5658
Damage = 0
57-
hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value
58-
Health = int(float(tree.xpath('//*[@id="actualHealth"]')[0].text))
59+
Health = int(float(main_tree.xpath('//*[@id="actualHealth"]')[0].text))
5960
while 1:
6061
if time.time() - start > int(start_time):
6162
break # round is over
@@ -77,8 +78,7 @@ def fight(link, side, weaponQuality="0", dmg_or_hits="100kk", ticketQuality="5",
7778
session.post(f"{URL}{use}.html", data={'quality': 5})
7879
for _ in range(5):
7980
try:
80-
post_hit = session.post(
81-
f"{URL}fight.html?weaponQuality={weaponQuality}&battleRoundId={hidden_id}&side={side}&value=Berserk")
81+
post_hit = send_fight_request(session, URL, main_tree, weaponQuality, side)
8282
tree = fromstring(post_hit.content)
8383
Damage = int(str(tree.xpath('//*[@id="DamageDone"]')[0].text).replace(",", ""))
8484
Health = float(tree.xpath("//*[@id='healthUpdate']")[0].text.split()[0])

Fight/hunt.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from login import login, get_nick_and_pw
22
import __init__
33
from Basic.fly import fly
4+
from Help_functions._bot_functions import send_fight_request
45

56
from lxml.html import fromstring
67
import requests
@@ -55,23 +56,23 @@ def hunt(server, maxDmgForBh="500000", startTime="30", weaponQuality="5"):
5556

5657
def fight(side, DamageDone, session):
5758
battle = session.get(f'{URL}battle.html?id={battle_id}')
58-
tree = fromstring(battle.content)
59-
Health = int(float(str(tree.xpath("//*[@id='actualHealth']")[0].text)))
60-
hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value
61-
food = int(tree.xpath('//*[@id="foodLimit2"]')[0].text)
62-
gift = int(tree.xpath('//*[@id="giftLimit2"]')[0].text)
59+
Main_tree = fromstring(battle.content)
60+
Health = int(float(str(Main_tree.xpath("//*[@id='actualHealth']")[0].text)))
61+
hidden_id = Main_tree.xpath("//*[@id='battleRoundId']")[0].value
62+
food = int(Main_tree.xpath('//*[@id="foodLimit2"]')[0].text)
63+
gift = int(Main_tree.xpath('//*[@id="giftLimit2"]')[0].text)
6364
if Health < 50:
6465
use = "eat" if food else "gift"
6566
session.post(f"{URL}{use}.html", data={'quality': 5})
6667
battleScore = session.get(f'{URL}battleScore.html?id={hidden_id}&at={apiCitizen["id"]}&ci={apiCitizen["citizenshipId"]}&premium=1').json()
6768
Damage = 0
6869
if server in dead_servers:
69-
value = "&value=Berserk" if battleScore["spectatorsOnline"] != 1 and Health >= 50 else ""
70+
value = "Berserk" if battleScore["spectatorsOnline"] != 1 and Health >= 50 else ""
7071
else:
71-
value = "&value=Berserk"
72+
value = "Berserk"
7273
for _ in range(5):
7374
try:
74-
f = session.post(f"{URL}fight.html?weaponQuality={weaponQuality}&battleRoundId={hidden_id}&side={side}{value}")
75+
f = send_fight_request(session, URL, Main_tree, weaponQuality, side, value)
7576
tree = fromstring(f.content)
7677
Damage = int(str(tree.xpath('//*[@id="DamageDone"]')[0].text).replace(",", ""))
7778
time.sleep(0.3)

Fight/hunt_specific_battle.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from login import login
2-
31
from random import randint
42
import requests
53
from lxml.html import fromstring
64
import time
75

6+
from login import login
7+
import __init__
8+
from Help_functions._bot_functions import send_fight_request
9+
10+
811
def hunt_specific_battle(link, side, max_dmg_for_bh="1", weapon_quality="0"):
912
"""
1013
Hunting BH at specific battle.
@@ -25,22 +28,21 @@ def hunt_specific_battle(link, side, max_dmg_for_bh="1", weapon_quality="0"):
2528
time.sleep(time_till_round_end)
2629
session = login(server)
2730
r = session.get(link)
28-
tree = fromstring(r.content)
31+
Main_tree = fromstring(r.content)
2932
DamageDone = 0
3033
while DamageDone < int(max_dmg_for_bh):
3134
for _ in range(5):
3235
try:
3336
r = session.get(link)
34-
tree = fromstring(r.content)
37+
Main_tree = fromstring(r.content)
3538
if r.status == 200:
3639
break
3740
except:
3841
time.sleep(1)
39-
Health = int(float(str(tree.xpath("//*[@id='actualHealth']")[0].text)))
40-
hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value
41-
food = tree.xpath('//*[@id="foodLimit2"]')[0].text
42-
food_limit = tree.xpath('//*[@id="sfoodQ5"]/text()')[0]
43-
gift = tree.xpath('//*[@id="giftLimit2"]')[0].text
42+
Health = int(float(str(Main_tree.xpath("//*[@id='actualHealth']")[0].text)))
43+
food = Main_tree.xpath('//*[@id="foodLimit2"]')[0].text
44+
food_limit = Main_tree.xpath('//*[@id="sfoodQ5"]/text()')[0]
45+
gift = Main_tree.xpath('//*[@id="giftLimit2"]')[0].text
4446
if Health < 50:
4547
if int(food) and int(food_limit):
4648
session.post(f"{URL}eat.html?quality=5")
@@ -49,7 +51,7 @@ def hunt_specific_battle(link, side, max_dmg_for_bh="1", weapon_quality="0"):
4951
Damage = 0
5052
for _ in range(5):
5153
try:
52-
r = session.post(f"{URL}fight.html?weaponQuality={weapon_quality}&battleRoundId={hidden_id}&side={side}")
54+
r = send_fight_request(session, URL, Main_tree, weapon_quality, side, value='')
5355
tree = fromstring(r.content)
5456
Damage = int(str(tree.xpath('//*[@id="DamageDone"]')[0].text).replace(",", ""))
5557
break

Fight/win_battle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from login import login
22
import __init__
33
from Basic.fly import fly
4+
from Help_functions._bot_functions import send_fight_request
45

56
import requests
67
from lxml.html import fromstring
@@ -88,7 +89,6 @@ def watch(link, side, start_time="60", keep_wall="3kk", let_overkill="10000000",
8889
if mySide-enemySide > int(keep_wall):
8990
time.sleep(10)
9091
continue
91-
hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value
9292
food = tree.xpath('//*[@id="foodLimit2"]')[0].text
9393
gift = tree.xpath('//*[@id="giftLimit2"]')[0].text
9494
Health = int(float(tree.xpath('//*[@id="actualHealth"]')[0].text))
@@ -101,7 +101,7 @@ def watch(link, side, start_time="60", keep_wall="3kk", let_overkill="10000000",
101101
print("Done limits")
102102
return
103103
else:
104-
session.post(f"{URL}fight.html?weaponQuality={weaponQuality}&battleRoundId={hidden_id}&side={side}&value=Berserk")
104+
send_fight_request(session, URL, tree, weaponQuality, side)
105105
if not int(food) and not int(gift) and not Health:
106106
print("Done limits")
107107
return

Help_functions/_bot_functions.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
from login import login, get_nick_and_pw
2-
31
import csv
42
import os
3+
import time
54
from datetime import datetime
65
from random import randint, choice
7-
import time
6+
87
import requests
98
from lxml.html import fromstring
109

10+
from login import login, get_nick_and_pw
11+
import __init__
12+
from Time_saver.utils import fight395791_
13+
14+
1115
def _fix_product_name(product):
1216
item = product.split()
1317
options = "iron, grain, oil, stone, wood, diamonds (diam), weapon (wep), house, gift, food, ticket, defense_system (DS), hospital, estate"
@@ -28,6 +32,7 @@ def _fix_product_name(product):
2832
else:
2933
return Q, item
3034

35+
3136
def _get_staff_list(URL):
3237
blacklist = set()
3338
i = requests.get(f"{URL}staff.html")
@@ -37,6 +42,7 @@ def _get_staff_list(URL):
3742
blacklist.add(nick.strip())
3843
return blacklist
3944

45+
4046
def _get_battle_id(server, battle_id, session):
4147
URL = f"https://{server}.e-sim.org/"
4248
nick = get_nick_and_pw(server)[0]
@@ -76,6 +82,7 @@ def _get_battle_id(server, battle_id, session):
7682
battle_id = battle_id[0].replace("battle.html?id=", "") or None
7783
return battle_id
7884

85+
7986
def _random_sleep(restores_left="100"):
8087
# Functions: datetime (datetime), randint (random), time
8188
if restores_left:
@@ -139,6 +146,7 @@ def _special_items_list(server, session=""):
139146
slots = ['Helmet', 'Vision', 'Personal Armor', 'Pants',
140147
'Shoes', 'Lucky charm', 'Weapon upgrade', 'Offhand']
141148

149+
142150
def _create_auctions_csv(file_name):
143151
with open(file_name, 'w', newline='') as csvFile:
144152
writer = csv.writer(csvFile)
@@ -197,6 +205,13 @@ def _prices_helper(file_name):
197205
if Help == "1":
198206
_auctions_csv_helper(file_name)
199207

208+
209+
def convert_to_dict(s):
210+
s_list = s.replace("'", '').split("&")
211+
s_list[0] = f"ip={s_list[0]}"
212+
return dict([a.split("=") for a in s_list])
213+
214+
200215
def _fighting(server, battle_id, side, wep, session=""):
201216
URL = f"https://{server}.e-sim.org/"
202217
if not session:
@@ -209,23 +224,30 @@ def _fighting(server, battle_id, side, wep, session=""):
209224
if not Health:
210225
break
211226
if Health >= 50:
212-
value = "&value=Berserk"
227+
value = "Berserk"
213228
else:
214229
value = ""
215-
hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value
216-
HIT = session.post(f"{URL}fight.html?weaponQuality={wep}&battleRoundId={hidden_id}&side={side}{value}")
230+
HIT = send_fight_request(session, URL, tree, wep, side, value)
217231
print(HIT.url)
218232
time.sleep(randint(1, 2))
219233
except Exception as e:
220234
print(e)
221235
time.sleep(randint(2, 5))
222236

223-
237+
238+
def send_fight_request(session, URL, tree, wep, side, value="Berserk"):
239+
hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value
240+
fight395791 = fight395791_(tree.text_content())
241+
data = {"weaponQuality": wep, "battleRoundId": hidden_id, "side": side, "value": value}
242+
data.update(convert_to_dict("".join(tree.xpath("//script[3]/text()")).split("&ip=")[1].split(";")[0]))
243+
return session.post(f"{URL}{fight395791}", data=data)
244+
245+
224246
def _location(server):
225247
"""getting current location"""
226248
URL = f"https://{server}.e-sim.org/"
227249
nick = get_nick_and_pw(server)[0]
228-
time.sleep(randint(1,2))
250+
time.sleep(randint(1, 2))
229251
apiCitizen = requests.get(f"{URL}apiCitizenByName.html?name={nick.lower()}").json()
230252
currentLocationRegionId = apiCitizen['currentLocationRegionId']
231253
return currentLocationRegionId

Time_saver/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import re
2+
3+
4+
def fight395791_(r: str):
5+
fg_re = 'url: (\".*fight.*.html\")'
6+
return re.sub("[\"\']*", "", re.findall(fg_re, r)[0])

0 commit comments

Comments
 (0)