1- from login import login , get_nick_and_pw
2-
31import csv
42import os
3+ import time
54from datetime import datetime
65from random import randint , choice
7- import time
6+
87import requests
98from 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+
1115def _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+
3136def _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+
4046def _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+
7986def _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=""):
139146slots = ['Helmet' , 'Vision' , 'Personal Armor' , 'Pants' ,
140147 'Shoes' , 'Lucky charm' , 'Weapon upgrade' , 'Offhand' ]
141148
149+
142150def _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+
200215def _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+
224246def _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
0 commit comments