async def location(server): """getting current location""" URL = f"https://{server}.e-sim.org/" nick = get_nick_and_pw(server)[0] await asyncio.sleep(randint(1, 2)) apiCitizen = await get_content( f"{URL}apiCitizenByName.html?name={nick.lower()}") return apiCitizen['currentLocationRegionId']
async def get_battle_id(server, battle_id, priorize_my_country=False): URL = f"https://{server}.e-sim.org/" nick = get_nick_and_pw(server)[0] apiCitizen = await get_content( f"{URL}apiCitizenByName.html?name={nick.lower()}") for row in await get_content(f'{URL}apiMap.html'): if row['regionId'] == apiCitizen['currentLocationRegionId']: occupantId = row['occupantId'] break await login(server) try: if apiCitizen["level"] < 15: raise # PRACTICE_BATTLE if battle_id == "event": tree = await get_content( f"{URL}battles.html?countryId={apiCitizen['citizenshipId']}&filter=EVENT" ) for link in tree.xpath( "//tr[position()<12]//td[1]//div[2]//a/@href"): link_id = link.split('=')[1] apiBattles = await get_content( f"{URL}apiBattles.html?battleId={link_id}") if apiCitizen['citizenshipId'] in (apiBattles['attackerId'], apiBattles['defenderId']): battle_id = link_id break else: tree = await get_content( f"{URL}battles.html?countryId={occupantId}&filter=NORMAL") battle_id = tree.xpath('//tr//td[1]//div//div[2]//div[2]/a/@href') if not battle_id: tree = await get_content( f"{URL}battles.html?countryId={occupantId}&filter=RESISTANCE") battle_id = tree.xpath('//tr//td[1]//div//div[2]//div[2]/a/@href') except: tree = await get_content(f"{URL}battles.html?filter=PRACTICE_BATTLE") battle_id = tree.xpath('//tr[2]//td[1]//a/@href') if not battle_id: battle_id = [""] if priorize_my_country: sides = [ x.replace("xflagsMedium xflagsMedium-", "").replace("-", " ").lower() for x in tree.xpath('//tr//td[1]//div//div//div/@class') if "xflagsMedium" in x ] for _id, sides in zip(battle_id, sides): if apiCitizen["citizenship"].lower() in sides: return _id.replace("battle.html?id=", "") return battle_id[0].replace("battle.html?id=", "") or None
async def _get_friends_list(server): URL = f"https://{server}.e-sim.org/" nick = get_nick_and_pw(server)[0] apiCitizen = await get_content( f'{URL}apiCitizenByName.html?name={nick.lower()}') for page in range(1, 100): tree = await get_content( f'{URL}profileFriendsList.html?id={apiCitizen["id"]}&page={page}') for div in range(1, 21): friend = tree.xpath(f'//div//div[1]//div[{div}]/a/text()') if not friend: return yield friend[0].strip()
def _get_battle_id(server, battle_id): # Functions: requests, fromstring URL = f"https://{server}.e-sim.org/" nick = get_nick_and_pw(server)[0] apiCitizen = requests.get( f"{URL}apiCitizenByName.html?name={nick.lower()}").json() currentLocationRegionId = apiCitizen['currentLocationRegionId'] apiMap = requests.get(f'{URL}apiMap.html').json() for row in apiMap: if row['regionId'] == currentLocationRegionId: occupantId = row['occupantId'] break try: if apiCitizen["level"] < 15: int("a") # PRACTICE_BATTLE if battle_id == "event": battles = requests.get( f"{URL}battles.html?countryId={apiCitizen['citizenshipId']}&filter=EVENT" ) tree = fromstring(battles.content) links = tree.xpath("//tr[position()<12]//td[1]//div[2]//@href") for link in links: link_id = link.split('=', 1)[1] apiBattles = requests.get( f"{URL}apiBattles.html?battleId={link_id}").json()[0] if apiCitizen['citizenshipId'] in (apiBattles['attackerId'], apiBattles['defenderId']): battle_id = link_id break else: battles = requests.get( f"{URL}battles.html?countryId={occupantId}&filter=NORMAL") tree = fromstring(battles.content) battle_id = tree.xpath('//tr[2]//td[1]//div[2]//@href') if not battle_id: battles = requests.get( f"{URL}battles.html?countryId={occupantId}&filter=RESISTANCE") tree = fromstring(battles.content) battle_id = tree.xpath('//tr[2]//td[1]//div[2]//@href') except: battles = requests.get(f"{URL}battles.html?filter=PRACTICE_BATTLE") tree = fromstring(battles.content) battle_id = tree.xpath('//tr[2]//td[1]//@href') battle_id = battle_id[0].replace("battle.html?id=", "") or None return battle_id
async def hunt(server, maxDmgForBh="500000", startTime="30", weaponQuality="5"): """Auto hunt BHs (attack and RWs)""" dead_servers = ["primera", "secura", "suna"] URL = f"https://{server}.e-sim.org/" if "t" in startTime.lower(): startTime = float(startTime.lower().replace("t", "")) * 60 maxDmgForBh, startTime = int(maxDmgForBh.replace("k", "000")), int(startTime) print(f"Startint to hunt at {server}.") nick = get_nick_and_pw(server)[0] apiCitizen = await get_content( f"{URL}apiCitizenByName.html?name={nick.lower()}") apiRegions = await get_content(URL + "apiRegions.html") for _ in range(100): try: battles_time = {} apiMap = await get_content(f'{URL}apiMap.html') for row in apiMap: if "battleId" in row: apiBattles = await get_content( f'{URL}apiBattles.html?battleId={row["battleId"]}') round_ends = apiBattles[ "hoursRemaining"] * 3600 + apiBattles[ "minutesRemaining"] * 60 + apiBattles[ "secondsRemaining"] battles_time[row["battleId"]] = round_ends for battle_id, round_ends in sorted(battles_time.items(), key=lambda x: x[1]): apiBattles = await get_content( f'{URL}apiBattles.html?battleId={battle_id}') if apiBattles['frozen']: continue time_to_sleep = apiBattles[ "hoursRemaining"] * 3600 + apiBattles[ "minutesRemaining"] * 60 + apiBattles[ "secondsRemaining"] round_time = 7000 if server in ("primera", "secura", "suna") else 3400 if time_to_sleep > round_time: break print("Seconds till next battle:", time_to_sleep) try: await asyncio.sleep(time_to_sleep - startTime) except: pass apiFights = await get_content( f'{URL}apiFights.html?battleId={battle_id}&roundId={apiBattles["currentRound"]}' ) defender, attacker = {}, {} for hit in apiFights: side = defender if hit['defenderSide'] else attacker if hit['citizenId'] in side: side[hit['citizenId']] += hit['damage'] else: side[hit['citizenId']] = hit['damage'] neighboursId = [ region['neighbours'] for region in apiRegions if region["id"] == apiBattles['regionId'] ] if not neighboursId: continue # Not an attack / RW. aBonus = [ neighbour for region in apiMap for neighbour in neighboursId[0] if neighbour == region['regionId'] and region['occupantId'] == apiBattles['attackerId'] ] async def fight(side, DamageDone): tree = await get_content(f'{URL}battle.html?id={battle_id}' ) Health = int( float( str(tree.xpath("//*[@id='actualHealth']") [0].text))) hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value food = int(tree.xpath('//*[@id="foodLimit2"]')[0].text) gift = int(tree.xpath('//*[@id="giftLimit2"]')[0].text) if Health < 50: use = "eat" if food else "gift" await get_content(f"{URL}{use}.html", data={'quality': 5}) battleScore = await get_content( f'{URL}battleScore.html?id={hidden_id}&at={apiCitizen["id"]}&ci={apiCitizen["citizenshipId"]}&premium=1' ) Damage = 0 if server in dead_servers: value = "Berserk" if battleScore[ "spectatorsOnline"] != 1 and Health >= 50 else "" else: value = "Berserk" for _ in range(5): try: tree, _ = await send_fight_request( URL, tree, weaponQuality, side, value) Damage = int( str( tree.xpath('//*[@id="DamageDone"]') [0].text).replace(",", "")) await asyncio.sleep(0.3) break except: await asyncio.sleep(2) try: DamageDone += Damage except: print("Couldn't hit") if not food and not gift and not Health: print("done limits") DamageDone = 0 return DamageDone async def check(side, DamageDone, should_continue): tree = await get_content(f'{URL}battle.html?id={battle_id}' ) hidden_id = tree.xpath("//*[@id='battleRoundId']")[0].value try: top1Name = tree.xpath( f"//*[@id='top{side}1']//div//a[1]/text()" )[0].strip() top1dmg = int( str( tree.xpath(f'//*[@id="top{side}1"]/div/div[2]') [0].text).replace(",", "")) except: top1Name, top1dmg = "None", 0 battleScore = await get_content( f'{URL}battleScore.html?id={hidden_id}&at={apiCitizen["id"]}&ci={apiCitizen["citizenshipId"]}&premium=1' ) # condition - You are top 1 / did more dmg than your limit / refresh problem condition = (top1Name == nick or DamageDone > maxDmgForBh or DamageDone > top1dmg) if battleScore["remainingTimeInSeconds"] > startTime: return False elif battleScore['spectatorsOnline'] == 1: if top1dmg > maxDmgForBh or condition: return False else: return True else: if top1dmg < maxDmgForBh and condition: if not should_continue: food = int( tree.xpath('//*[@id="foodLimit2"]') [0].text) use = "eat" if food else "gift" await get_content(f"{URL}{use}.html", data={'quality': 5}) try: await asyncio.sleep( battleScore["remainingTimeInSeconds"] - 13) except: pass battleScore = await get_content( f'{URL}battleScore.html?id={hidden_id}&at={apiCitizen["id"]}&ci={apiCitizen["citizenshipId"]}&premium=1' ) if battleScore[f"{side.lower()}sOnline"]: await fight(side, DamageDone) return False return True async def hunting(side, side_dmg, should_continue): DamageDone = 0 c = await check(side.title(), DamageDone, should_continue) while c: DamageDone = await fight(side, DamageDone) if not DamageDone: # Done limits or error break if DamageDone > side_dmg: c = await check(side.title(), DamageDone, should_continue) try: aDMG = sorted(attacker.items(), key=lambda x: x[1], reverse=True)[0][1] except: aDMG = 0 try: dDMG = sorted(defender.items(), key=lambda x: x[1], reverse=True)[0][1] except: dDMG = 0 if aDMG < maxDmgForBh or dDMG < maxDmgForBh: print( f"Fighting at: {URL}battle.html?id={battle_id}&round={apiBattles['currentRound']}" ) await get_content(URL, login_first=True) if apiBattles['type'] == "ATTACK": if aDMG < maxDmgForBh: try: await fly(server, aBonus[0]) except: print("I couldn't find the bonus region") continue await hunting("attacker", aDMG, dDMG < maxDmgForBh) if dDMG < maxDmgForBh: await fly(server, apiBattles['regionId']) await hunting("defender", dDMG, aDMG < maxDmgForBh) elif apiBattles['type'] == "RESISTANCE": await fly(server, apiBattles['regionId']) if aDMG < maxDmgForBh: await hunting("attacker", aDMG, dDMG < maxDmgForBh) if dDMG < maxDmgForBh: await hunting("defender", dDMG, aDMG < maxDmgForBh) else: continue except Exception as error: print(error)
async def mm(server): """Sells all currencies in your account in the appropriate markets & edit current offers if needed.""" URL = f"https://{server}.e-sim.org/" api = await get_content(URL + "apiCountries.html") storage_tree = await get_content(URL + "storage.html?storageType=MONEY", login_first=True) for i in range(2, 20): try: CC = storage_tree.xpath( f'//*[@id="storageConteiner"]//div//div//div//div[{i}]/text()' )[-1].strip() cc = [i["id"] for i in api if i["currencyName"] == CC][0] value = storage_tree.xpath( f'//*[@id="storageConteiner"]//div//div//div//div[{i}]/b/text()' )[0] tree = await get_content( f'{URL}monetaryMarket.html?buyerCurrencyId={cc}&sellerCurrencyId=0' ) try: MM = str(tree.xpath("//tr[2]//td[3]/b")[0].text).strip() except: MM = 0.1 payload = { "offeredMoneyId": cc, "buyedMoneyId": 0, "value": value, "exchangeRatio": round(float(MM) - 0.0001, 4), "submit": "Post new offer" } send_monetary_market = await get_content( URL + "monetaryMarket.html?action=post", data=payload) print(send_monetary_market) except: break nick = get_nick_and_pw(server)[0] tree = await get_content(URL + "monetaryMarket.html") IDs = tree.xpath('//*[@id="command"]//input[1]') for i in range(2, 20): try: CC = tree.xpath( f'//*[@id="esim-layout"]//table[2]//tr[{i}]//td[1]/text()' )[-1].strip() cc = [i["id"] for i in api if i["currencyName"] == CC][0] tree = await get_content( f'{URL}monetaryMarket.html?buyerCurrencyId={cc}&sellerCurrencyId=0' ) seller = tree.xpath("//tr[2]//td[1]/a/text()")[0].strip() if seller != nick: try: MM = tree.xpath("//tr[2]//td[3]/b")[0].text except: MM = 0.1 payload = { "id": IDs[i - 2].value, "rate": round(float(MM) - 0.0001, 4), "submit": "Edit" } edit_offer = await get_content( URL + "monetaryMarket.html?action=change", data=payload) print(edit_offer) except: break