def run(self): time_start = datetime.datetime.now() self.reporter.wowtokenscan["isWork"] = True while self.stopper.is_wowtoken_thread_must_stop is False: wtp_data = getJSON(WoWTokenScaner.wowtokenprice_API) for region in WoWTokenScaner.regions: if region[0] == "cn": blizz_data = getJSON(WoWTokenScaner.cn_API.format(self.token)) else: blizz_data = getJSON(WoWTokenScaner.API.format(region[0],region[0],self.token)) token = WowToken.query.filter(WowToken.region == region[0]).first() token.current_price_blizzard_api = int(blizz_data["price"]) / 10000, token.current_price_wowtokenprices_api = int(wtp_data[region[1]]["current_price"]) token.timestamp_blizzard_api = datetime.datetime.utcfromtimestamp(int(blizz_data["last_updated_timestamp"]) / 1000) token.timestamp_wowtokenprices_api = datetime.datetime.utcfromtimestamp(wtp_data[region[1]]["time_of_last_change_unix_epoch"]) token.last_change = int(wtp_data[region[1]]["last_change"]) token.one_day_low = int(wtp_data[region[1]]["1_day_low"]) token.one_day_high = int(wtp_data[region[1]]["1_day_high"]) token.seven_day_high = int(wtp_data[region[1]]["7_day_high"]) token.seven_day_low = int(wtp_data[region[1]]["7_day_low"]) token.month_low = int(wtp_data[region[1]]["30_day_low"]) token.month_high = int(wtp_data[region[1]]["30_day_high"]) print("Получена информация о токене: {}".format(token)) db.session.commit() self.reporter.wowtokenscan["number_of_cycles"] +=1 self.reporter.wowtokenscan["work_time"] = str((datetime.datetime.now() - time_start)) time.sleep(self.pause_time.total_seconds()) if int(self.reporter.wowtokenscan["number_of_cycles"])%30 == 0: updateToken() self.token = getToken()["access_token"] self.reporter.wowtokenscan["isWork"] = False
def __init__(self,reporter, stopper, pause_time = 10): Thread.__init__(self) updateToken() self.token = getToken()["access_token"] self.pause_time = datetime.timedelta(minutes=pause_time) self.reporter = reporter #type: Reporter self.stopper = stopper #type: ThreadStopper
def __init__(self, reporter, stopper, countOfThreads=12): Thread.__init__(self) updateToken() self.token = getToken()["access_token"] self.counter = ThredCounter() self.counOfThread = countOfThreads self.reporter = reporter #type: Reporter self.stopper = stopper #type: ThreadStopper self.apiMasterList = "https://us.api.blizzard.com/wow/pet/?locale=en_US&access_token={}".format( self.token)
def __init__(self, reporter, stopper, countOfThreads=12): Thread.__init__(self) updateToken() self.token = getToken()["access_token"] self.regions = ["us", "eu"] self.apiServers = "https://{}.api.blizzard.com/data/wow/realm/index?namespace=dynamic-{}&access_token={}" self.counter = ThredCounter() self.counOfThread = countOfThreads self.reporter = reporter #type: Reporter self.stopper = stopper #type: ThreadStopper
def __init__(self, reporter, stopper, cycle_time=40, countOfThreads=4, lot_limit=None): Thread.__init__(self) updateToken() self.token = getToken()["access_token"] self.counter = ThredCounter() self.counOfThread = countOfThreads self.reporter = reporter #type: Reporter self.stopper = stopper #type: ThreadStopper self.cycle_time = cycle_time self.lot_limit = lot_limit
def __init__(self,reporter, stopper, maxItemId, minItemId = 0, countOfThreads = 16, startFromLast = False): Thread.__init__(self) self.reporter = reporter #type: Reporter self.stopper = stopper #type: ThreadStopper self.maxItemId = maxItemId self.minItemId = minItemId self.countOfThreads = countOfThreads self.counter = ThredCounter() updateToken() self.token = getToken()["access_token"] if startFromLast is True: self.minItemId = int(AssistInfo.query.filter(AssistInfo.key == "LastItem").first().value) print("min id {}".format(self.minItemId)) if self.maxItemId < self.minItemId: self.maxItemId = self.maxItemId + 3 * self.countOfThreads print("max id {}".format(self.maxItemId))
def run(self): self.reporter.aucscan["isWork"] = True self.reporter.aucscan["star_time"] = datetime.datetime.now() while self.stopper.is_auc_thread_must_stop is False: time_start = datetime.datetime.now() cycle_time = datetime.timedelta(minutes=self.cycle_time) unique_server = Servers.query.with_entities( Servers.auc, Servers.timestamp).distinct().order_by( asc(Servers.timestamp)).all() #[0:10] stop = self.counOfThread start = 0 realms_count = len(list(unique_server)) self.reporter.aucscan["total"] = realms_count for i in range(0, math.ceil(realms_count / self.counOfThread)): if stop >= realms_count: stop = realms_count for server in unique_server[start:stop]: self.reporter.aucscan["auc_num"] += 1 thread = AucThread(lot_limit=self.lot_limit, auc_link=server.auc, token=self.token, is_must_add_new=True, counter=self.counter, reporter=self.reporter) thread.start() Log.write( "Запущен поток AucThread; Name: {}".format( thread.name), "AUC_INFO") while self.counter.num != 0: time.sleep(0.01) if self.stopper.is_auc_thread_must_stop is True: break self.reporter.aucscan["percent"] = round( float(stop / realms_count * 100), 1) self.reporter.aucscan["current"] = stop self.reporter.aucscan["avg_auc"] = round( float( int(self.reporter.aucscan["auc_summ"]) / int(self.reporter.aucscan["auc_num"]))) self.reporter.aucscan["avg_auc_time"] = str( time.strftime( '%H:%M:%S', time.gmtime( round( float( int(self.reporter.aucscan["auc_time_summ"]) / int(self.reporter.aucscan["auc_num"])))))) Log.write( "Среднее время скана 1 аука: {}".format( self.reporter.aucscan["avg_auc_time"]), "AUC_INFO") Log.write( "Среднее количество лотов на аукционах: {}".format( self.reporter.aucscan["avg_auc"]), "AUC_INFO") stop += self.counOfThread start += self.counOfThread if (datetime.datetime.now() - time_start) < cycle_time: Log.write( "Сон после цикла: {} сек.".format( (time_start + cycle_time - datetime.datetime.now())), "AUC_INFO") time.sleep((time_start + cycle_time - datetime.datetime.now()).total_seconds()) Log.write("Сон завершен", "AUC_INFO") if int(self.reporter.aucscan["number_of_cycles"]) % 10 == 0: updateToken() Log.write("Обновлен токен", "AUC_INFO") self.token = getToken()["access_token"] self.reporter.aucscan["cycle_time_summ"] += round( (datetime.datetime.now() - time_start).total_seconds()) self.reporter.aucscan["number_of_cycles"] += 1 self.reporter.aucscan["avg_cycle_time"] = str( time.strftime( '%H:%M:%S', time.gmtime( round( float( int(self.reporter.aucscan["cycle_time_summ"]) / int(self.reporter.aucscan["number_of_cycles"])) )))) Log.write( "Время цикла скана всех серверов {}".format( self.reporter.aucscan["avg_cycle_time"]), "AUC_INFO") self.reporter.aucscan["isWork"] = False