def refreshFailedTotoResults(self): count = 0 try: data = sgPoolsModel.sgPoolsBL() with data.atomic() as txn: temp = list(data.get_failedtotoresult()) data.close() for num in temp: try: logger.info("Draw Number: " + str(num.DrawNumber) + " Processing") self.refreshTotoResult(num.DrawNumber, True) data = sgPoolsModel.sgPoolsBL() try: with data.atomic() as txn: data.delete_failedtotoresult(num.DrawNumber) except: pass finally: data.close() count += 1 except Exception as ex: logger.info("Draw Number: " + str(num.DrawNumber) + " Error") logger.error(ex, exc_info=True) logger.info("Completed RefreshingFailed Toto Result, Count: " + str(count)) except Exception as ex: logger.error(ex, exc_info=True) raise
def refreshTotoResult(self, DrawNumber, ThrowError=False): try: jsonObj = self.getTotoResults(DrawNumber) if jsonObj == []: pass else: if jsonObj["Status"] == True: data = sgPoolsModel.sgPoolsBL() try: with data.atomic() as txn: data.add_dicttotoresult(jsonObj) except ValueError: pass finally: data.close() else: logger.info("Draw Number: " + str(DrawNumber) + " Get Status: " + str(jsonObj["Status"])) except Exception as ex: logger.info("Draw Number: " + str(DrawNumber) + " Error. Failed to enter to DB, record skipped ") logger.error(ex, exc_info=True) data = sgPoolsModel.sgPoolsBL() try: with data.atomic() as txn: data.add_Failedtotoresult(DrawNumber) except ValueError: pass finally: data.close() if ThrowError: raise
def clearTotoResults(self): data = sgPoolsModel.sgPoolsBL() try: with data.atomic() as txn: data.clear_totoresults() except: logger.error(ex, exc_info=True) raise finally: data.close()
def updateOldTotoDrawDate(self): try: start_DrawNumber = 999 end_DrawNumber = 1194 for num in range(start_DrawNumber, end_DrawNumber): drawDate = self.calculateDrawDate(num) data = sgPoolsModel.sgPoolsBL() try: with data.atomic() as txn: logger.info("DrawNumber: " + str(num) + " DrawDate: " + str(drawDate)) data.update_totodrawdate(num, drawDate) except Exception as ex: logger.error(ex, exc_info=True) raise finally: data.close() except Exception as ex: logger.error(ex, exc_info=True) raise
def getGroupedTotoResult(self): strTemplate = "result.push({{CombinationNumber: '{0}', DrawNumber: [{1}]}});" try: with open('toto_result.js', 'w') as file: file.write("var result = [];" + "\n") data = sgPoolsModel.sgPoolsBL() try: with data.atomic() as txn: temp = list(data.get_groupedtotoresult()) for num in temp: #logger.info("Combination Number: " + str(num.CombinationNumber) + " Draw Numbers: " + str(num.DrawNumber)) #logger.info(strTemplate.format(str(num.CombinationNumber),str(num.DrawNumber))) with open('toto_result.js', 'a') as file: file.write( strTemplate.format(str(num.CombinationNumber), str(num.DrawNumber)) + "\n") except: pass finally: data.close() except Exception as ex: logger.error(ex, exc_info=True) raise
def ProcessTotoResult(self, **kwargs): DrawNumber = kwargs.get('DrawNumber', None) MaxCombinationLength = 7 count = 0 try: data = sgPoolsModel.sgPoolsBL() with data.atomic() as txn: if DrawNumber is None: temp = list(data.get_totoresults()) else: temp = [data.get_totoresult(DrawNumber)] data.close() for num in temp: try: logger.info("Draw Number: " + str(num.DrawNumber) + " Processing") DrawNumbers = [] DrawNumbers.append(num.Win1) DrawNumbers.append(num.Win2) DrawNumbers.append(num.Win3) DrawNumbers.append(num.Win4) DrawNumbers.append(num.Win5) DrawNumbers.append(num.Win6) DrawNumbers.append(num.AdditionalNumber) #logger.info("Draw Number: " + str(num.DrawNumber) + " DrawNumbers: " + str(DrawNumbers)) result = CreateAllCombination(DrawNumbers, MaxCombinationLength) temp = [] for item in result: temp2 = {} temp2['DrawNumber'] = num.DrawNumber temp2['CombinationNumber'] = ','.join(item) temp.append(temp2) #logger.info("Result: " + str(result)) data = sgPoolsModel.sgPoolsBL() try: with data.atomic() as txn: data.add_processedtotoresults(temp) count += 1 except Exception as ex: logger.error(ex, exc_info=True) pass finally: data.close() #for item in result: # try: # with data.atomic() as txn: # data.add_processedtotoresult(','.join(item), num.DrawNumber) # logger.info("Draw Number: " + str(num.DrawNumber) + " Combo:" + ','.join(item)) # count += 1 # except Exception as ex: # logger.error(ex, exc_info=True) # pass # finally: # data.close() except Exception as ex: #logger.info("Draw Number: " + str(num.DrawNumber) + " Error") logger.error(ex, exc_info=True) #break #logger.info("Completed RefreshingFailed Toto Result, Count: " + str(count)) except Exception as ex: logger.error(ex, exc_info=True) raise