refactor code

main
Khiem Ton 2 years ago
parent fec4dc6d91
commit e16b51db74
Signed by: th4tkh13m
GPG Key ID: 4D9CF147DCADD05D

3
.gitignore vendored

@ -1,3 +1,4 @@
__pycache__ __pycache__
Pipfile Pipfile
Pipfile.lock Pipfile.lock
DeveloperDiskImage*

@ -1,4 +1,4 @@
from math import pi, sin, cos, atan2, sqrt from math import radians, sin, cos, asin, sqrt
class Location(): class Location():
def __init__(self, latitude, longitude): def __init__(self, latitude, longitude):
@ -6,15 +6,16 @@ class Location():
self.longitude = longitude self.longitude = longitude
def distance(self, other): def distance(self, other):
R = 6371e3 R = 6371
d_lat = (self.latitude - other.latitude) * pi/180
d_lon = (self.longitude - other.longitude) * pi/180 d_lat = radians(self.latitude - other.latitude)
d_lon = radians(self.longitude - other.longitude)
a = sin(d_lat/2) * sin(d_lat/2) +\ a = sin(d_lat/2) * sin(d_lat/2) +\
sin(d_lon/2) * sin(d_lon/2) * cos(self.latitude) * cos(other.latitude) sin(d_lon/2) * sin(d_lon/2) * cos(radians(self.latitude)) * cos(radians(other.latitude))
c = 2 * atan2(sqrt(a), sqrt(1-a)) c = 2 * asin(sqrt(a))
d = R * c / 1000 d = R * c
return d return d

@ -0,0 +1,3 @@
class Object():
def __init__(self):
self.location = None

@ -0,0 +1,30 @@
from geopy.geocoders import Nominatim
from ..location import Location
from .object import Object
class Player(Object):
def __init__(self):
super().__init__()
self.current_cooldown = 0
def set_location_with_query(self, query):
loc = Nominatim(user_agent="GetLoc")
getLoc = loc.geocode(query)
self.location = Location(getLoc.latitude, getLoc.longitude)
def set_location(self, location, did_activity):
next_cd = self.get_cooldown_to(location)
if did_activity:
if next_cd + self.current_cooldown >= 120:
self.current_cooldown = 120
else:
self.current_cooldown += next_cd
self.location = location
def get_location(self):
return self.location
def get_cooldown_to(self, location):
# + 1 for map loading and activities
return self.location.get_cooldown(location) + 1

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from .object import Object
class Pokemon(): class Pokemon(Object):
def __init__(self, name, number, location, def __init__(self, name, number, location,
cp, level, attack, defense, hp, cp, level, attack, defense, hp,
iv, shiny, start_time, end_time, iv, shiny, start_time, end_time,
@ -24,5 +25,8 @@ class Pokemon():
return True return True
return False return False
def __repr__(self):
return f"{self.name}: {self.cp}, {self.level}, {self.attack}-{self.defense}-{self.hp}, shinable: {self.shiny}, end: {self.end_time}"

@ -1,4 +1,6 @@
class Raid(): from .object import Object
class Raid(Object):
def __init__(self, name, number, level, location, start_time, end_time, country): def __init__(self, name, number, level, location, start_time, end_time, country):
self.name = name self.name = name
self.number = number self.number = number

@ -1,21 +0,0 @@
from geopy.geocoders import Nominatim
from .location import Location
class Player():
def __init__(self):
self.location = None
def set_location_with_query(self, query):
loc = Nominatim(user_agent="GetLoc")
getLoc = loc.geocode(query)
self.location = Location(getLoc.latitude, getLoc.longitude)
def set_location(self, location):
self.location = location
def get_location(self):
return self.location
def cooldown_to(self, location):
return self.location.get_cooldown(location)

@ -0,0 +1,42 @@
from pathlib import Path
from pymobiledevice3.lockdown import LockdownClient
from pymobiledevice3.cli.mounter import MobileImageMounterService
from pymobiledevice3.cli.developer import DtSimulateLocation
from pymobiledevice3.services.diagnostics import DiagnosticsService
class Device():
def __init__(self):
self.lockdown = LockdownClient()
self.mounter = MobileImageMounterService(self.lockdown)
self.diagnostics = DiagnosticsService(self.lockdown)
self.is_mounted = False
self.location = None
def mount_image(self, image_path, signature_path):
image_type = "Developer"
image_path = Path(image_path)
image = image_path.read_bytes()
signature_path = Path(signature_path)
signature = signature_path.read_bytes()
self.mounter.upload_image(image_type, image, signature)
self.mounter.mount(image_type, signature)
self.is_mounted = True
self.location = DtSimulateLocation(self.lockdown)
return True
def spoof_gps(self, destination):
self.location = DtSimulateLocation(self.lockdown)
self.location.set(destination.latitude, destination.longitude)
return True
def stop_spoofing(self):
self.location.clear()
self.diagnostics.restart()

@ -0,0 +1,75 @@
from bs4 import BeautifulSoup
import requests
from ..objects.pokemon import Pokemon
from ..objects.raid import Raid
from ..location import Location
from datetime import datetime
class Scraper():
def __init__(self):
self.HUNDO_URL = "https://moonani.com/PokeList/index.php"
self.PVP_URL = "https://moonani.com/PokeList/raid.php"
def get_pokemons(self, url):
pokemon_lst = []
response = requests.get(url)
soup = BeautifulSoup(response.text, "lxml")
for row in soup.find_all("tr")[1:]:
data = row.find_all("td")[1:]
name = data[0].text.strip()
number = int(data[1].text)
coordinates = map(float, data[2].text.split(","))
location = Location(*coordinates)
cp = int(data[3].text)
level = int(data[4].text)
attack = int(data[5].text)
defense = int(data[6].text)
hp = int(data[7].text)
iv = int(data[8].text.rstrip("%"))
shiny = data[9].text == "Yes"
start_time = datetime.fromisoformat(data[10].text)
end_time = datetime.fromisoformat(data[11].text)
country = data[12].text
pokemon = Pokemon(name, number, location, cp, level, attack, defense, hp, iv, shiny, start_time, end_time, country)
pokemon_lst.append(pokemon)
return pokemon_lst
def get_hundos(self):
return self.get_pokemons(self.HUNDO_URL)
def get_pvp(self):
return self.get_pokemons(self.PVP_URL)
def get_raids(self):
raid_lst = []
response = requests.get("https://moonani.com/PokeList/raid.php")
soup = BeautifulSoup(response.text, "lxml")
for row in soup.find_all("tr")[1:]:
data = row.find_all("td")
name = data[0].text
number = int(data[1].text)
level = int(data[2].text)
coordinates = map(float, data[3].text.split(","))
location = Location(*coordinates)
start_time = datetime.fromisoformat(data[4].text)
end_time = datetime.fromisoformat(data[5].text)
country = data[6].text
raid = Raid(name, number, level, location, start_time, end_time, country)
raid_lst.append(raid)
return raid_lst

@ -1,63 +0,0 @@
from bs4 import BeautifulSoup
import requests
from .core.pokemon import Pokemon
from .core.raid import Raid
from .core.location import Location
from datetime import datetime
def get_pokemons(url):
pokemon_lst = []
response = requests.get(url)
soup = BeautifulSoup(response.text, "lxml")
for row in soup.find_all("tr")[1:]:
data = row.find_all("td")[1:]
name = data[0].text
number = int(data[1].text)
coordinates = map(float, data[2].text.split(","))
location = Location(*coordinates)
cp = int(data[3].text)
level = int(data[4].text)
attack = int(data[5].text)
defense = int(data[6].text)
hp = int(data[7].text)
iv = int(data[8].text.rstrip("%"))
shiny = data[9].text == "Yes"
start_time = datetime.fromisoformat(data[10].text)
end_time = datetime.fromisoformat(data[11].text)
country = data[12].text
pokemon = Pokemon(name, number, location, cp, level, attack, defense, hp, iv, shiny, start_time, end_time, country)
pokemon_lst.append(pokemon)
return pokemon_lst
def get_raids():
raid_lst = []
response = requests.get("https://moonani.com/PokeList/raid.php")
soup = BeautifulSoup(response.text, "lxml")
for row in soup.find_all("tr")[1:]:
data = row.find_all("td")
name = data[0].text
number = int(data[1].text)
level = int(data[2].text)
coordinates = map(float, data[3].text.split(","))
location = Location(*coordinates)
start_time = datetime.fromisoformat(data[4].text)
end_time = datetime.fromisoformat(data[5].text)
country = data[6].text
raid = Raid(name, number, level, location, start_time, end_time, country)
raid_lst.append(raid)
return raid_lst

@ -1,13 +1,48 @@
from bs4 import BeautifulSoup from ispoof.core.objects.player import Player
from ispoof.core.location import Location from ispoof.core.spoofer.scraper import Scraper
from ispoof.core.pokemon import Pokemon from ispoof.core.spoofer.device import Device
from datetime import datetime from pymobiledevice3.exceptions import AlreadyMountedError
import requests import traceback
from ispoof import scraper
from geopy.geocoders import Nominatim if __name__ == "__main__":
device = Device()
loc = Nominatim(user_agent="GetLoc") image_path = "DeveloperDiskImage.dmg"
getLoc = loc.geocode("12 Cao Son 7, Da Nang") signature_path = "DeveloperDiskImage.dmg.signature"
print(type(getLoc.latitude)) try:
device.mount_image(image_path, signature_path)
except Exception as e:
traceback.print_exc()
print("Already mounted. Continuing.")
player = Player()
query = input("Enter your location: ")
player.set_location_with_query(query)
scraper = Scraper()
while True:
pokemons = scraper.get_hundos()
pokemons.sort(key=lambda x: x.end_time, reverse=True)
print("Spoof to")
print(pokemons[10])
location = pokemons[10].location
device.spoof_gps(location)
did_activity = None
while True:
activity = input("Did you do any cooldown activities? [Y/N] ").lower()
if activity in ("y", "n"):
did_activity = activity == "y"
break
player.set_location(location, did_activity)
print(f"Current cooldown: {player.current_cooldown} min")
while True:
continue_prompt = input("Continue? [Y/N] ").lower()
if continue_prompt in ("y", "n"):
if continue_prompt == "n":
device.stop_spoofing()
exit(0)
else: break
# print(scraper.get_raids()) # print(scraper.get_raids())
Loading…
Cancel
Save