def main(): print("Started collecting museum data") print("...") api = API() dbConnectionManager = DBConnectionManager() museumListJson = api.getMuseumList() museumTableAssembler = MuseumTableAssembler() museumTable = museumTableAssembler.assembleTable(museumListJson) museumTable.persist("Museums", dbConnectionManager.getDBConnection()) citiesTable = WikiTable(museumTable[['City', 'CityRef']]) citiesTableAssembler = CitiesTableAssembler() citiesTable = citiesTableAssembler.assemble(citiesTable, api) citiesTable.persist("Cities", dbConnectionManager.getDBConnection()) print(museumTable) print(citiesTable)
def getweather(lat, lon, numtrain, date): meteo = {} if numtrain and date: api = API() res = api.callweatherAPI(lat, lon) else: logger.warning("Missing arguments to properly make weather call") return meteo if res == 1 or res is None: return meteo else: meteoinfo = res["observations"]["location"][0]['observation'][0] meteo["skydescription"] = meteoinfo.get("skyDescription") meteo["temp"] = meteoinfo.get("temperature") meteo["precipitations"] = meteoinfo.get("precipitation3H") meteo["wind"] = meteoinfo.get("windSpeed") meteo["visibility"] = meteoinfo.get("visibility") meteo["snow"] = meteoinfo.get("snowCover") return meteo
def get_instances(self) -> list[Instance]: instances = [] # Docker instances (containers or services) if self.__docker is not None: for instance in self.__docker.containers.list( all=True, filters={"label": "bunkerweb.UI"}): env_variables = { x[0]: x[1] for x in [ env.split("=") for env in instance.attrs["Config"]["Env"] ] } apiCaller = ApiCaller() apiCaller._set_apis([ API( f"http://{instance.name}:{env_variables.get('API_HTTP_PORT', '5000')}", env_variables.get("API_SERVER_NAME", "bwapi"), ) ]) instances.append( Instance( instance.id, instance.name, instance.name, "container", "up" if instance.status == "running" else "down", instance, apiCaller, )) instances = sorted( instances, key=lambda x: x.name, ) # Local instance if os.path.exists("/usr/sbin/nginx"): instances.insert( 0, Instance( "local", "local", "127.0.0.1", "local", "up" if os.path.exists("/opt/bunkerweb/tmp/nginx.pid") else "down", ), ) return instances
def update_exchange_balances(exchange_accounts): has_errors = False errors = [] for exchange_account in exchange_accounts: api = API(exchange_account) balances, error = api.getBalances() if error: has_errors = True errors.append(error) else: reset_most_recent_field(exchange_account) for currency in balances: exchange_balance = ExchangeBalance( exchange_account=exchange_account, currency=currency, amount=balances[currency], most_recent=True ) exchange_balance.save() return (has_errors, errors)
def getTrainInfo(trainNumber): res = OrderedDict([('trainNumber', trainNumber)]) api = API() # "cercaNumeroTrenoTrenoAutocomplete is the viaggiatreno API call that returns the starting station # for the train number specified as its argument. # Unfortunately that could return more than one station. departures = api.callviaggiatreno('cercaNumeroTrenoTrenoAutocomplete', trainNumber) if departures != 1: if len(departures) == 0: logger.info("Train {0} not found on date.".format(trainNumber)) res["status"] = "NotRunningOnDate" return json.dumps(res) elif len(departures) > 1: departures = departures[0] res = callApiAndGetResults(trainNumber, departures, res, api) return json.dumps(res).encode('utf-8')
def run_emulator(): controller = Controller() controller.add_sound("stub", SoundStub()) controller.add_gfx("poor", PoorGraphics()) # controller.add_gfx("stub", GraphicsStub()) controller.add_controls("stub", ControlsStub()) api = API(controller) # controller.add_init_hook("helloworld", api.create_hook(HelloWorldHook)) # controller.add_pre_cycle_hook("opcode", api.create_hook(OpcodeHook)) # controller.add_pre_frame_hook("opcode", api.create_hook(OpcodeHook)) controller.load_rom("ROMs/TETRIS.bin") for i in range(0, 300): controller.next_frame()
def main(): print("Started collecting additional museum data") print("...") api = API() dbConnectionManager = DBConnectionManager() museumTableAssembler = MuseumTableAssembler() museumTable = WikiTable.load("Museums", dbConnectionManager.getDBConnection()) print(museumTable) properties_configuration = "properties_configuration.json" with open(properties_configuration, 'r') as propertiesFile: propertiesJson = json.load(propertiesFile) print(propertiesJson) for property in propertiesJson: print("{}: {}".format(property, propertiesJson[property])) museumTableAssembler.addMuseumProperties(museumTable, propertiesJson, api) museumTable.persist("Museums", dbConnectionManager.getDBConnection())
def __init__(self): self.api = API() self.migration_pw = "COSInu11"
class Bot: EXCESS_TRAFFIC_SLEEP_TIME = 11 def __init__(self): self.api = API() self.migration_pw = "COSInu11" def login_account(self, account: PlayerInformation): pass def create_new_account(self, activate_farming=False): self.api.login(new_registration=True) self.api.POST__api_user_get_user_data() self.api.POST__api_config_get_config() self.api.POST__api_tutorial_get_next_tutorial_mst_id() self.api.POST__api_tutorial_agree_legal_document() self.api.POST__api_tutorial_get_user_mini_tutorial_data() self.api.POST__api_tutorial_get_tutorial_gacha() # TODO implement better farm logic wip if activate_farming: num_ssrare = 0 while num_ssrare < TUTORIAL_OVERRIDE_SS_MIN: time.sleep(self.EXCESS_TRAFFIC_SLEEP_TIME) num_ssrare, item_ids, character_ids = self.api.POST__api_tutorial_fxm_tutorial_gacha_drawn_result( ) logging.info("Rolled") if set( character_ids ) & TUTORIAL_CHAR_MUST_HAVE_IDS and num_ssrare >= TUTORIAL_SS_MIN: logging.info(f"New Account {character_ids}") break else: time.sleep(self.EXCESS_TRAFFIC_SLEEP_TIME) num_ssrare, item_ids, character_ids = self.api.POST__api_tutorial_fxm_tutorial_gacha_drawn_result( ) self.api.POST__api_tutorial_fxm_tutorial_gacha_exec() name = random.choice(common_names) self.api.POST__api_tutorial_set_user_name(name) self.api.POST__api_tutorial_set_character(2) # Missions self.api.POST__api_cleaning_check() self.api.POST__api_cleaning_start() self.api.POST__api_cleaning_end_wave(25, 1, 5, 5, 5) self.api.POST__api_cleaning_end_wave(20, 2, 4, 4, 4) self.api.POST__api_cleaning_end_wave(17, 3, 6, 6, 6) self.api.POST__api_cleaning_end_wave(14, 4, 6, 6, 6) self.api.POST__api_cleaning_end_wave(11, 5, 7, 7, 7) self.api.POST__api_cleaning_end_wave(11, 6, 7, 16, 7) self.api.POST__api_cleaning_end_wave(6, 7, 0, 16, 7) self.api.POST__api_cleaning_end_wave(3, 8, 0, 7, 7) self.api.POST__api_cleaning_end_wave(0, 9, 0, 4, 4) self.api.POST__api_cleaning_end(10) self.api.POST__api_user_get_user_data() self.api.POST__api_tutorial_get_next_tutorial_mst_id() self.api.POST__api_cleaning_retire() # First quest self.api.POST__api_quest_get_attention() self.api.POST__api_quest_get_alice_area_map() self.api.POST__api_quest_get_alice_stage_list() self.api.POST__api_quest_get_stage_reward() self.api.POST__api_quest_get_stage_data() self.api.POST__api_quest_get_tutorial_result() def get_all_presents(self): present_list = self.api.POST__api_present_get_present_data() self.api.POST__api_present_gain_present(present_list) def play_gacha(self, gacha_id=23): self.api.POST__api_gacha_gacha_exec(gacha_id) self.api.POST__api_gacha_gacha_exec(gacha_id) self.api.POST__api_gacha_gacha_exec(gacha_id) self.api.POST__api_gacha_gacha_exec(gacha_id) self.api.POST__api_gacha_gacha_exec(gacha_id) def set_player_info_dict(self, character_ids_param, item_ids_param): ss_rare = 0 item_names = "" nightmare_names = "" character_names = "" item_ids = "" character_ids = "" for char_id in character_ids_param: id = str(char_id) character_ids += id + ", " character_names += character_dict[id]["name"] + ", " for item_id in item_ids_param: id = str(item_id) item_ids += id + ", " rarity = str(card_dict[id]["rarity"]) card_type = card_dict[id]["cardType"] to_save = rarity + ":" + card_dict[id]["name"] + ", " if rarity == "5": ss_rare += 1 if int(rarity) > 4 or card_type == NIGHTMARE_TYPE: if card_type == NIGHTMARE_TYPE: nightmare_names += to_save else: item_names += to_save self.api.player_information.ss_rare = ss_rare self.api.player_information.item_names = item_names self.api.player_information.nightmare_names = nightmare_names self.api.player_information.character_names = character_names self.api.player_information.item_ids = item_ids self.api.player_information.character_ids = character_ids logging.info( f"Nightmares:{nightmare_names} Items:{item_names} Character:{character_names}" ) # Todo move part of the logic to FarmLogic def is_good_account(self): char_names, chars_ids = self.api.POST__api_character_get_character_data_list( ) item_names, nightmare_names, ids = self.api.POST__api_card_info_get_card_data_by_user_id( ) self.set_player_info_dict(chars_ids, ids) if GACHA_MUST_HAVE_NIGHTMARE_IDS & set(ids): if GACHA_MUST_HAVE_ITEM_IDS & set(ids): logging.info( f"Adding 1x Nightmare and Item account to database {ids} {chars_ids}" ) return True if len(GACHA_MUST_HAVE_NIGHTMARE_IDS & set(ids)) > 1: logging.info( f"Adding 2x Nightmare account to database {ids} {chars_ids}") return True if len(TUTORIAL_CHAR_MUST_HAVE_IDS & set(chars_ids)) > 1: if GACHA_MUST_HAVE_NIGHTMARE_IDS & set(ids): logging.info( f"Adding 2x Class and Nightmare account to database {ids} {chars_ids}" ) return True return False def migrate(self): self.api.get_migrate_information(self.migration_pw)
from api.API import API import os ################################################################################ # # Call app based on deployment environment; # endpoints = API(os.environ["ENV"]) application = endpoints.getApp() if __name__ == "__main__": if os.environ["ENV"] == "dev": application.run(debug=True) elif os.environ["ENV"] == "staging": application.run(debug=True) elif os.environ["ENV"] == "production": application.run()
################################################################################ from flask import Flask from api.API import API ################################################################################ api = API("config.json") api_config = api.config.data api_output = api.output["json"] ################################################################################ if api_config["output"] == "server": app = Flask(__name__) @app.route("/") def output(): return api_output if __name__ == "__main__": app.run() else: print(api_output) if api_config["debug"] != False:
import os, sys curPath = os.path.abspath(os.path.dirname(__file__)) rootPath = os.path.split(curPath)[0] # 先引入目录的上级 sys.path.append(rootPath) import config.config as CONFIG from api.API import API '''生成结果''' api_instance = API() class GenerateResult(object): def __init__(self): self.threshold = CONFIG.PRICE_THRESHOLD self.upper_threshold = CONFIG.CHARGE_RATE_UPPER_THRESHOLD self.bottom_threshold = CONFIG.CHARGE_RATE_BOTTOM_THRESHOLD self.buff_vs_steam = CONFIG.BUFF_VS_STEAM ''' @Description:扔求购比例计算 ''' def generate_beg_result(self, items): result_array = [] for item in items: good_id = item['id'] # 商品ID sell_num = item['sell_num'] # 在售数量 name = item['name'] # 商品名称
def preparing(self): # Load AI modules spec = importlib.util.spec_from_file_location("AI", self.__script_1_path) self.__ai_1_script = importlib.util.module_from_spec(spec) spec.loader.exec_module(self.__ai_1_script) spec = importlib.util.spec_from_file_location("AI", self.__script_2_path) self.__ai_2_script = importlib.util.module_from_spec(spec) spec.loader.exec_module(self.__ai_2_script) hq_1 = HQ("HQ_1", self.map_info["HQ_1"], 1) self.map[hq_1.coordinates[0]][hq_1.coordinates[1]] = hq_1 hq_2 = HQ("HQ_2", self.map_info["HQ_2"], 2) self.map[hq_2.coordinates[0]][hq_2.coordinates[1]] = hq_2 self.player_1_units.append(hq_1) self.player_2_units.append(hq_2) m_1 = None m_2 = None for i in range(4): try: if i <= 1: m_1 = Magnus(f"M_1@{i+1}", self.map_info["M_1"][i], 1) self.map[m_1.coordinates[0]][m_1.coordinates[1]] = m_1 m_2 = Magnus(f"M_2@{i+1}", self.map_info["M_2"][i], 2) self.map[m_2.coordinates[0]][m_2.coordinates[1]] = m_2 t_1 = Turret(f"T_1@{i+1}", self.map_info["T_1"][i], 1) self.map[t_1.coordinates[0]][t_1.coordinates[1]] = t_1 t_2 = Turret(f"T_2@{i + 1}", self.map_info["T_2"][i], 2) self.map[t_2.coordinates[0]][t_2.coordinates[1]] = t_2 self.player_1_units.extend([m_1, t_1]) self.player_2_units.extend([m_2, t_2]) except IndexError: pass # TODO: Rozmieszczenie flag for i in range(self.map_info["MAX_UNIT_NUMBER"]): while True: x = randint(0, self.map_info["size"][0] - 1) y = 0 if self.map[x][y] == "-": robot_1 = Robot(f"R_1@{i}", [x, y], 1) self.map[robot_1.coordinates[0]][ robot_1.coordinates[1]] = robot_1 break while True: x = randint(0, self.map_info["size"][0] - 1) y = self.map_info["size"][1] - 1 if self.map[x][y] == "-": robot_2 = Robot(f"R_2@{i}", [x, y], 2) self.map[robot_2.coordinates[0]][ robot_2.coordinates[1]] = robot_2 break self.player_1_units.append(robot_1) self.player_2_units.append(robot_2) # Load API (create class instances) api_1 = API(self, self.player_1_units, 1) api_2 = API(self, self.player_2_units, 2) self.apis.extend([api_1, api_2]) self.main_loop()