説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

D-2401.py 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. import concurrent.futures
  2. import requests
  3. from concurrent.futures import ThreadPoolExecutor, as_completed
  4. from sqlalchemy import Column,String,create_engine
  5. from sqlalchemy.orm import sessionmaker
  6. from sqlalchemy.ext.declarative import declarative_base
  7. import pyodbc
  8. import pandas as pd
  9. import csv
  10. import requests
  11. import json
  12. import rsa
  13. import binascii
  14. import json
  15. import csv
  16. import pandas as pd
  17. import datetime
  18. import random
  19. import sys
  20. import time
  21. from bs4 import BeautifulSoup
  22. import re
  23. from PyQt5.QtCore import QThread, pyqtSignal
  24. from PyQt5.QtWidgets import (QApplication, QDialog,
  25. QProgressBar, QPushButton,QLabel)
  26. from PyQt5 import QtWidgets
  27. from PyQt5.QtCore import *
  28. from sqlalchemy import Column,String,create_engine
  29. from sqlalchemy.orm import sessionmaker
  30. from sqlalchemy.ext.declarative import declarative_base
  31. import pyodbc
  32. import os
  33. import logging
  34. import traceback
  35. import atexit
  36. FORMAT = '%(asctime)s %(levelname)s: %(message)s'
  37. logging.basicConfig(level=logging.INFO, filename='myLog.log', filemode='w', format=FORMAT)
  38. Base = declarative_base()
  39. class Logdata(Base):
  40. __tablename__ = 'LOGDB'
  41. 資料庫 = Column(String(20), primary_key=True)
  42. IP位置 = Column(String(20))
  43. 帳號 = Column(String(20))
  44. 密碼 = Column(String(20))
  45. class User(Base):
  46. __tablename__ = '客戶資料表'
  47. 客戶 = Column(String(20), primary_key=True)
  48. 資料庫 = Column(String(20))
  49. IP位置 = Column(String(20))
  50. 帳號 = Column(String(20))
  51. 密碼 = Column(String(20))
  52. class DateF(Base):
  53. __tablename__ = '查詢時間'
  54. 開始=Column(String(20), primary_key=True)
  55. 結束=Column(String(20))
  56. 是否全導=Column(String(20))
  57. class Someoneupdate(Base):
  58. __tablename__ = '自動導入判斷'
  59. 正在自動導入中= Column(String(20), primary_key=True)
  60. def loadCSV():
  61. try:
  62. with open('000.csv', newline='') as csvfile:
  63. rows = csv.reader(csvfile)
  64. csvvrow=[]
  65. for row in rows:
  66. csvvrow.append(row)
  67. coustomtxt=(csvvrow[1][0])
  68. bdtxtcrypto=(csvvrow[2][0])
  69. PRIVATTTTT=693199020841184529005187339596013597950466957598599888793608033530271219415853952414609432155441426597962873618644988823224505129033188472492232565627111731743840442387622658441932249274048207290194890312931801018119336565101207159089093817844379836520246765598761731093447853178093855957965143730121353938159096214435813116478583463281838568325696377260624492699103838269489173425735163766515881745838239102851526971498900537039965925229366981233886305256752613857576375123305107336285923247046744901857058559811348110224118414002814652550587381981742663420856507553321403129123387307759852585845583253705194423896104474967966535066409675943348475929657759428664521337873475544406762447015072876289975051669953965932555224693025757002523361150649200905802416556626834350633483715061798581642291839762255979334372982156774414505811030453728205541010293992016524698689810201483053731487961892768615175941360043106707261541518852778287823654935902238415934276399863697899069150965902889645358960710613979521286008786269668237598187906056491031301559442316212834296436205439154886053776090316790598915161638161668892006476380622662058436463540372859165165728327478177043147902958378365406901451035507793539047616182219516942468776336379
  70. #PrivateKey
  71. A1=435136098972877768874748645248339158125703956065257805897130489515873898645785064137580564100320503666838498219287367368030775233887671705599248600291953393231454780648861079171195672717473628632853618453449217420455794237632155291175461656351373149436294485404694429947256530385791280349340495413483412113186857182441596591220416636342090069157129915377951859333634936029548424638926391232291634636038258059603109206715187896810765799441703590963590776385210580000409455669280693512175818186066741512695081131148497030784289903926969375944559780083722346620544362180693184053719440253987062360057770451705216722616373945761278697477867656454308042535057052004210508850990364826097246310462235289453838547367442863138161099765610183693493835956264409463595891562624222255540841617618186384919177648960630843478742501992844305124096538648231123014949030890404247398161443680124720970242595119682693770042136274011065565273819531541118246115073819134261046370918950429149073365625538812772489582690787721407799409054150416184648077711942774002489730938839028835996373562349388498470086161265863994312489374464512279091382150353090705188164569282723516063722137626802108564462453248942121100848000690940344201632450119420978307322308945
  72. A2=9627714051932950193134188501742994592784042206914443459734438308841410040354738469881718445461422881776007294906803790685427277699734850787185938262102876531473114260174800542552232307443022494368143100728406826855674366796656059054215802558213346170105688323652674928367680251460924362233864869984871966783909100785712414620921144535418728448391075664442600744983428543175164409720230286595771434578391588137898216407341812591598354427012529961000712417819821596260309468611766323842906019082923549785615976305556417630687246871293866806059225782724368215141401076633953519395967986211659258251543120569378038365122086876706827618666557619122782700896147
  73. A3=72000374865933143340744306653169834428832683081115110740204100237805467875781399111076588189449270231784547205065314993551385284482420372845976820023615822918370850049018336485262561074750111640775157594829249815372287322731748252778906894672575675394415480712584447066603079224388770970172603768779881242086210954654794512868330782099170594476257989194451530266257956383540560124814995186866139904562390161487741092810396910518052928540664299189962055810713116703112503213279177866017925218355080344908808970420740591501342146164000394175136511345019472809580649061686926648057
  74. bdtxtcrypto=bdtxtcrypto.encode('utf8')
  75. print(bdtxtcrypto)
  76. print(type(bdtxtcrypto))
  77. bdtxtcrypto=binascii.a2b_hex(bdtxtcrypto)
  78. mmmmm=rsa.decrypt(bdtxtcrypto,rsa.PrivateKey(PRIVATTTTT,65537,A1,A2,A3))
  79. bdtxt=(mmmmm.decode('utf8'))
  80. return coustomtxt,bdtxt
  81. except:
  82. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  83. traceback.print_exc(file=open('log.txt', 'a'))
  84. logging.debug('debug message',exc_info=True)
  85. logging.info('info message',exc_info=True)
  86. logging.warning('warning message',exc_info=True)
  87. logging.error('error message',exc_info=True)
  88. logging.critical('critical message',exc_info=True)
  89. app1 = QtWidgets.QApplication([])
  90. error_dialog = QtWidgets.QErrorMessage()
  91. error_dialog.setWindowTitle('ERROR')
  92. error_dialog.showMessage('無法取得000.csv')
  93. app1.exec_()
  94. def connectEngine(coustomtxt,engine):
  95. try:
  96. DB_session = sessionmaker(engine)
  97. db_session = DB_session()
  98. comDbUserData=db_session.query(User).filter(User.客戶.like(coustomtxt)).all()
  99. UserDbName=comDbUserData[0].資料庫
  100. UserIPName=comDbUserData[0].IP位置
  101. UserAdName=comDbUserData[0].帳號
  102. UserPdName=comDbUserData[0].密碼
  103. engine3 = create_engine('mssql+pyodbc://'+UserAdName+':'+UserPdName+'@'+UserIPName+'/'+UserDbName+'?driver=SQL+Server+Native+Client+11.0')
  104. return engine3
  105. except:
  106. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  107. traceback.print_exc(file=open('log.txt', 'a'))
  108. logging.debug('debug message',exc_info=True)
  109. logging.info('info message',exc_info=True)
  110. logging.warning('warning message',exc_info=True)
  111. logging.error('error message',exc_info=True)
  112. logging.critical('critical message',exc_info=True)
  113. app1 = QtWidgets.QApplication([])
  114. error_dialog = QtWidgets.QErrorMessage()
  115. error_dialog.setWindowTitle('ERROR')
  116. error_dialog.showMessage('資料連線失敗')
  117. app1.exec_()
  118. def DateDataLoad(engine3,db_session2):
  119. try:
  120. #engine3=connectEngine()
  121. Datefind=db_session2.query(DateF).all()
  122. startdatekey=Datefind[0].開始
  123. enddatekey=Datefind[0].結束
  124. allpart=Datefind[0].是否全導
  125. return startdatekey,enddatekey,allpart
  126. except:
  127. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  128. traceback.print_exc(file=open('log.txt', 'a'))
  129. logging.debug('debug message',exc_info=True)
  130. logging.info('info message',exc_info=True)
  131. logging.warning('warning message',exc_info=True)
  132. logging.error('error message',exc_info=True)
  133. logging.critical('critical message',exc_info=True)
  134. app1 = QtWidgets.QApplication([])
  135. error_dialog = QtWidgets.QErrorMessage()
  136. error_dialog.setWindowTitle('ERROR')
  137. error_dialog.showMessage('導入日期資料失敗')
  138. app1.exec_()
  139. def LoadCustomData(engine3,allpart):
  140. try:
  141. if (allpart=="0"):
  142. text3="SELECT TOP(1000) 網址, 帳號, 密碼 FROM 商客基本資料表"
  143. else:
  144. text3="SELECT TOP(1000) 網址, 帳號, 密碼 FROM 商客資料暫存檔"
  145. loopper2=pd.read_sql(text3,engine3)
  146. contforloop=len(loopper2)
  147. loopper2=loopper2.values
  148. print(loopper2)
  149. return contforloop,loopper2
  150. except:
  151. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  152. traceback.print_exc(file=open('log.txt', 'a'))
  153. logging.debug('debug message',exc_info=True)
  154. logging.info('info message',exc_info=True)
  155. logging.warning('warning message',exc_info=True)
  156. logging.error('error message',exc_info=True)
  157. logging.critical('critical message',exc_info=True)
  158. app1 = QtWidgets.QApplication([])
  159. error_dialog = QtWidgets.QErrorMessage()
  160. error_dialog.setWindowTitle('ERROR')
  161. error_dialog.showMessage('無基本資料')
  162. app1.exec_()
  163. def CreateLogEngine():
  164. try:
  165. DB_session_log = sessionmaker(engine)
  166. db_session_log= DB_session_log()
  167. Log_database=db_session_log.query(Logdata).all()
  168. LogDbName=Log_database[0].資料庫
  169. LogIPName=Log_database[0].IP位置
  170. LogAdName=Log_database[0].帳號
  171. LogPdName=Log_database[0].密碼
  172. log_Engine=create_engine('mssql+pyodbc://'+LogAdName+':'+LogPdName+'@'+LogIPName+'/'+LogDbName+'?driver=SQL+Server+Native+Client+11.0')
  173. return log_Engine
  174. except:
  175. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  176. traceback.print_exc(file=open('log.txt', 'a'))
  177. logging.debug('debug message',exc_info=True)
  178. logging.info('info message',exc_info=True)
  179. logging.warning('warning message',exc_info=True)
  180. logging.error('error message',exc_info=True)
  181. logging.critical('critical message',exc_info=True)
  182. app1 = QtWidgets.QApplication([])
  183. error_dialog = QtWidgets.QErrorMessage()
  184. error_dialog.setWindowTitle('ERROR')
  185. error_dialog.showMessage('記錄連線失敗')
  186. app1.exec_()
  187. def LongFirstLogin(urlkey,adminkey,passkey):
  188. try:
  189. print(urlkey)
  190. pubkey="B0C1D0E12B47DA93A24C7422D433170A4D5B126A27CED6F3087652723562889803E2280041F02E6B24A251C928EBE5BA12501D466D63A43AD5D88A5809A09271F14FD220C0DAE272CAAF9F1CF09DAF52005272529071723C0CB87B5A6392860CA2E72B23A4652910DB87BAC31D89E4DD23B3C56AAE685D9A14C4CC89862AAA27"
  191. rsaPublickey = int(pubkey,16)
  192. key = rsa.PublicKey(rsaPublickey,65537)
  193. message='{\"Account\":\"'+adminkey+'\",\"Password\":\"'+passkey+'\"}'
  194. message=message.encode('utf8')
  195. #passwd = rsa.encrypt(message,key)
  196. passwd = binascii.b2a_hex(rsa.encrypt(message,key)).decode()
  197. Loginurl="http://"+urlkey+"/api/shared/login"
  198. headers1 = {
  199. 'Content-Length': '256',
  200. 'Content-Type': 'application/x-www-form-urlencoded'
  201. }
  202. response = requests.request("POST", Loginurl, headers=headers1, data=passwd, timeout=10)
  203. return response
  204. except:
  205. response="無法取得資料"
  206. return response
  207. def LongSecondLogin(LFLresponse):
  208. try:
  209. LFLresponseJson=json.loads(LFLresponse.text)
  210. print(LFLresponseJson)
  211. SecondLoginUrl=LFLresponseJson['Redirect']
  212. SecondLoginData=LFLresponseJson['Data']
  213. headers2 = {
  214. 'Content-Length': '514',
  215. 'Content-Type': 'application/x-www-form-urlencoded'
  216. }
  217. print(SecondLoginUrl)#debug
  218. GatewayUrl="http:"+SecondLoginUrl
  219. print(GatewayUrl)
  220. LoginGatewayPostData="+="+SecondLoginData
  221. response2 = requests.request("POST", GatewayUrl, headers=headers2, data=LoginGatewayPostData, timeout=10)
  222. return SecondLoginUrl,SecondLoginData,response2
  223. except:
  224. SecondLoginUrl=""
  225. SecondLoginData=""
  226. response2=""
  227. return SecondLoginUrl,SecondLoginData,response2
  228. def LongGetData(urlkey, adminkey, passkey, startDatekey, endDatekey):
  229. try:
  230. LFLresponse=LongFirstLogin(urlkey,adminkey,passkey)
  231. if LFLresponse=="無法取得資料":
  232. fordebugger="無法取得資料"
  233. allll=pd.DataFrame()
  234. return allll,fordebugger,urlkey,adminkey
  235. if LFLresponse.status_code==200:
  236. SecondLoginUrl,SecondLoginData,LSLresponse=LongSecondLogin(LFLresponse)
  237. if LSLresponse=="":
  238. fordebugger="無法取得資料"
  239. allll=pd.DataFrame()
  240. return allll,fordebugger,urlkey,adminkey
  241. else:
  242. cookie=LSLresponse.cookies
  243. cookie=dict(cookie)['ASP.NET_SessionId']
  244. #cookie=cookie['ASP.NET_SessionId']
  245. print(cookie)
  246. GetDataUrl="http:"+SecondLoginUrl[:-21]+"/api/AdminD02Report1/MainQuery"#-21=-(/Command/LoginGateway)
  247. cookstring="ASP.NET_SessionId="+cookie
  248. headers88 = {
  249. 'X-Requested-With': 'XMLHttpRequest',
  250. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
  251. 'Content-Type': 'application/x-www-form-urlencoded',
  252. 'Cookie': cookstring,
  253. }
  254. getData= "Account=&GameType%5B%5D=35&GameType%5B%5D=22&GameType%5B%5D=11&GameType%5B%5D=12&GameType%5B%5D=13&GroupType%5B%5D=118&GroupType%5B%5D=109&GroupType%5B%5D=108&GroupType%5B%5D=102&GroupType%5B%5D=160&GroupType%5B%5D=159&GroupType%5B%5D=158&GroupType%5B%5D=157&GroupType%5B%5D=156&GroupType%5B%5D=155&GroupType%5B%5D=154&GroupType%5B%5D=153&GroupType%5B%5D=107&GroupType%5B%5D=106&GroupType%5B%5D=105&GroupType%5B%5D=104&GroupType%5B%5D=103&GroupType%5B%5D=101&StartDate="+startDatekey+"&EndDate="+endDatekey+"&IsNotShowNow=true"#FPK375#jnn688
  255. #getData= "Account=&GameType%5B%5D=22&GameType%5B%5D=11&GameType%5B%5D=12&GameType%5B%5D=13&GroupType%5B%5D=118&GroupType%5B%5D=109&GroupType%5B%5D=108&GroupType%5B%5D=102&GroupType%5B%5D=160&GroupType%5B%5D=159&GroupType%5B%5D=158&GroupType%5B%5D=157&GroupType%5B%5D=156&GroupType%5B%5D=155&GroupType%5B%5D=154&GroupType%5B%5D=153&GroupType%5B%5D=107&GroupType%5B%5D=106&GroupType%5B%5D=105&GroupType%5B%5D=104&GroupType%5B%5D=103&GroupType%5B%5D=101&StartDate="+startDatekey+"&EndDate="+endDatekey+"&IsNotShowNow=true"#FPK375#jnn688
  256. response3 = requests.request("POST", GetDataUrl, headers=headers88, data=getData, timeout=10)
  257. print(response3)
  258. if response3.status_code==200:
  259. jsondata=json.loads(response3.text)
  260. #print(jsondata)
  261. if response3.text=="null":
  262. getData= "Account=&GameType%5B%5D=22&GameType%5B%5D=11&GameType%5B%5D=12&GameType%5B%5D=13&GroupType%5B%5D=118&GroupType%5B%5D=109&GroupType%5B%5D=108&GroupType%5B%5D=102&GroupType%5B%5D=160&GroupType%5B%5D=159&GroupType%5B%5D=158&GroupType%5B%5D=157&GroupType%5B%5D=156&GroupType%5B%5D=155&GroupType%5B%5D=154&GroupType%5B%5D=153&GroupType%5B%5D=107&GroupType%5B%5D=106&GroupType%5B%5D=105&GroupType%5B%5D=104&GroupType%5B%5D=103&GroupType%5B%5D=101&StartDate="+startDatekey+"&EndDate="+endDatekey+"&IsNotShowNow=true"#FPK375#jnn688
  263. response3 = requests.request("POST", GetDataUrl, headers=headers88, data=getData, timeout=10)
  264. if response3.text=="null":
  265. #getData= "Account=&GameType%5B%5D=22&GameType%5B%5D=11&GameType%5B%5D=12&GameType%5B%5D=13&GroupType%5B%5D=118&GroupType%5B%5D=109&GroupType%5B%5D=108&GroupType%5B%5D=102&GroupType%5B%5D=160&GroupType%5B%5D=159&GroupType%5B%5D=158&GroupType%5B%5D=157&GroupType%5B%5D=156&GroupType%5B%5D=155&GroupType%5B%5D=154&GroupType%5B%5D=153&GroupType%5B%5D=107&GroupType%5B%5D=106&GroupType%5B%5D=105&GroupType%5B%5D=104&GroupType%5B%5D=103&GroupType%5B%5D=101&StartDate="+startDatekey+"&EndDate="+endDatekey+"&IsNotShowNow=true"#FPK375#jnn688
  266. getData= "Account=&GameType%5B%5D=11&GameType%5B%5D=12&GameType%5B%5D=13&GroupType%5B%5D=109&GroupType%5B%5D=108&GroupType%5B%5D=102&GroupType%5B%5D=160&GroupType%5B%5D=159&GroupType%5B%5D=158&GroupType%5B%5D=157&GroupType%5B%5D=156&GroupType%5B%5D=155&GroupType%5B%5D=154&GroupType%5B%5D=153&GroupType%5B%5D=107&GroupType%5B%5D=106&GroupType%5B%5D=105&GroupType%5B%5D=104&GroupType%5B%5D=103&GroupType%5B%5D=101&StartDate="+startDatekey+"&EndDate="+endDatekey+"&IsNotShowNow=true"#FPK375#jnn688
  267. response3 = requests.request("POST", GetDataUrl, headers=headers88, data=getData, timeout=10)
  268. #responsetxt=response3.text
  269. #print(responsetxt)
  270. if response3.text=="null":
  271. getData="Account=&GameType%5B%5D=22&GameType%5B%5D=13&GroupType%5B%5D=160&GroupType%5B%5D=159&GroupType%5B%5D=158&GroupType%5B%5D=157&GroupType%5B%5D=156&GroupType%5B%5D=155&GroupType%5B%5D=154&GroupType%5B%5D=153&GroupType%5B%5D=118&GroupType%5B%5D=107&GroupType%5B%5D=106&GroupType%5B%5D=105&GroupType%5B%5D=104&GroupType%5B%5D=103&GroupType%5B%5D=101&StartDate="+startDatekey+"&EndDate="+endDatekey+"&IsNotShowNow=true"#KPC365
  272. response3 = requests.request("POST", GetDataUrl, headers=headers88, data=getData, timeout=10)
  273. if response3.text=="null":
  274. getData="Account=&GameType%5B%5D=13&GroupType%5B%5D=160&GroupType%5B%5D=159&GroupType%5B%5D=158&GroupType%5B%5D=157&GroupType%5B%5D=156&GroupType%5B%5D=155&GroupType%5B%5D=154&GroupType%5B%5D=153&GroupType%5B%5D=107&GroupType%5B%5D=106&GroupType%5B%5D=105&GroupType%5B%5D=104&GroupType%5B%5D=103&GroupType%5B%5D=101&StartDate="+startDatekey+"&EndDate="+endDatekey+"&IsNotShowNow=true" #UJK555
  275. response3 = requests.request("POST", GetDataUrl, headers=headers88, data=getData, timeout=10)
  276. jsondata=json.loads(response3.text)
  277. #print(jsondata['DataList'][0]['Account'])
  278. #print(len(jsondata['DataList']))
  279. allll=[]
  280. if len(jsondata['DataList'])>0:
  281. for i in range(len(jsondata['DataList'])):
  282. allll.append([])
  283. allll[i].append(jsondata['DataList'][i]['NickName']+"("+jsondata['DataList'][i]['Account']+")")
  284. #
  285. allll[i].append(jsondata['DataList'][i]['TotBet'])
  286. allll[i].append(jsondata['DataList'][i]['TotBetRebate'])
  287. allll[i].append(jsondata['DataList'][i]['TotBetWinLose'])
  288. allll[i].append(jsondata['DataList'][i]['SubtotalTotWinLose'])
  289. for j in range(len(jsondata['DataList'][i]['ContributionPaid'])):
  290. allll[i].append(jsondata['DataList'][i]['ContributionPaid'][j]['TotPaid'])
  291. if len(jsondata['DataList'][i]['ContributionPaid'])<6:
  292. ReAdd=6-len(jsondata['DataList'][i]['ContributionPaid'])
  293. for z in range(ReAdd):
  294. allll[i].append("")
  295. allll[i].append(jsondata['DataList'][i]['SubtotalTotDutyWinLose'])
  296. allll[i].append(jsondata['DataList'][i]['SubtotalRebateWinLoseDifference'])
  297. allll[i].append(jsondata['DataList'][i]['TotPaid'])
  298. allll[i].append(jsondata['DataList'][i]['SubtotalSelfTotWinLose'])
  299. allll[i].append(jsondata['DataList'][i]['PaidContributor'])
  300. allll[i].append(jsondata['DataList'][i]['TotContribution'])
  301. allll[i].append(jsondata['DataList'][i]['SubtotalContribution'])
  302. allll[i].append(jsondata['DataList'][i]['TotControl'])
  303. allll[i].append(jsondata['DataList'][i]['TotControlDuty'])
  304. print(allll)
  305. allll=pd.DataFrame(allll)
  306. allll.columns =["名稱","總量","退水","中獎","輸贏","會員","代理","總代理","股東","大股東","總監","佔成輸贏","水倍差","上繳金額","自已總輸贏","上繳貢獻額","貢獻額","貢獻度","調退實佔","上繳"]
  307. fordebugger="OK"
  308. else:
  309. allll=pd.DataFrame()
  310. fordebugger="查詢期間無資料"
  311. WEBURLTXT=[]
  312. ADMINTXT=[]
  313. StartDATETXT=[]
  314. EndDATETXT=[]
  315. TIMERAND=[]
  316. nowTime=datetime.datetime.now().strftime("%m%d%H%M%S")
  317. randomNum=random.randint(0,10000);
  318. if randomNum<10:
  319. randomNum=str(0)+str(0)+str(0)+str(randomNum)
  320. elif randomNum>10 and randomNum<100:
  321. randomNum=str(0)+str(0)+str(randomNum)
  322. elif randomNum>100 and randomNum<1000:
  323. randomNum=str(0)+str(randomNum)
  324. uniqueNum=str(nowTime)+str(randomNum)
  325. for i in range(len(allll)):
  326. WEBURLTXT.append(urlkey)
  327. ADMINTXT.append(adminkey)
  328. StartDATETXT.append(startDatekey)
  329. EndDATETXT.append(endDatekey)
  330. TIMERAND.append(uniqueNum)
  331. allll.insert(0,"開始日期",StartDATETXT)
  332. allll.insert(1,"結束日期",EndDATETXT)
  333. allll.insert(2,"網址",WEBURLTXT)
  334. allll.insert(3,"帳戶",ADMINTXT)
  335. allll.insert(4,"隨機碼",TIMERAND)
  336. print(allll)
  337. refind=pd.DataFrame(columns =["開始日期","結束日期","網址","帳戶","名稱","總量","退水","中獎","輸贏","佔成輸贏","水倍差","上繳金額","自已總輸贏","上繳貢獻額","貢獻額","貢獻度","下注明細","玩法明細","調盤退水","調退實佔","上繳","會員","代理","總代理","股東","大股東","總監","隨機碼"])
  338. allll=pd.concat([refind,allll],ignore_index = True)
  339. end = time.time()
  340. print("執行時間:%f 秒" % (end - start))
  341. return allll,fordebugger,urlkey,adminkey
  342. if response3.status_code!=200:
  343. fordebugger="無法取得資料"
  344. allll=pd.DataFrame()
  345. return allll,fordebugger,urlkey,adminkey
  346. if LFLresponse.status_code!=200:
  347. allll,fordebugger,urlkey,adminkey=ShortGetData(urlkey, adminkey, passkey, startDatekey, endDatekey)
  348. #print(allll)
  349. return allll,fordebugger,urlkey,adminkey
  350. except:
  351. fordebugger="無法取得資料"
  352. allll=pd.DataFrame()
  353. return allll,fordebugger,urlkey,adminkey
  354. def ShortGetData(urlkey, adminkey, passkey, startDatekey, endDatekey):
  355. try:
  356. sloginUrl = "https://"+urlkey+"/pub/SuperGateway.php?c=900%2C"+adminkey+"%2C"+passkey
  357. response = requests.request("POST", sloginUrl, timeout=10)
  358. #jsondata=json.loads(response.text)
  359. #SIDKey=rrr[2]
  360. print(response.status_code)
  361. if response.status_code==200:
  362. if len(response.text)>3:
  363. SIDKey=response.text.split(',')[2]
  364. if len(SIDKey)<5:
  365. SIDKey=response.text.split(',')[3]
  366. print(SIDKey)
  367. AMKey=SIDKey.split('_')[0]
  368. print(AMKey)
  369. LevelUrl="https://"+urlkey+"/hp/headmenu.php?si="+SIDKey
  370. LevelUrlresponse = requests.request("GET", LevelUrl, timeout=10)
  371. soup=BeautifulSoup(LevelUrlresponse.text,"lxml")
  372. pattern = re.compile(r'var lv(.*?)=(.*?);',re.MULTILINE|re.DOTALL )
  373. script = soup.find("script", text=pattern)
  374. if len(pattern.search(script.string).group())==11:
  375. Level=pattern.search(script.string).group(2)[1:]
  376. elif len(pattern.search(script.string).group())==9:
  377. Level=pattern.search(script.string).group(2)
  378. print(pattern.search(script.string).group())
  379. print(Level)
  380. #print(pattern.search(script.string).group(1))
  381. #Level=pattern.search(script.string).group(1)
  382. GetUrl="https://"+urlkey+"/func/report/rpt_allplus.php"
  383. # Level="2"
  384. payload='sacco=&data1='+startDatekey+'&data2='+endDatekey+'&checka=yes&check0=yes&check1=yes&check2=yes&check3=yes&check4=yes&check5=yes&check6=yes&check7=yes&check8=yes&check9=yes&check10=yes&check11=yes&cas1=yes&cas2=yes&cas3=yes&cas4=yes&am='+AMKey+'&l='+Level+'&sid='+SIDKey+'&master=%20&Submit=%25E7%25A2%25BA%25E5%25AE%259A'
  385. GetHeaders = {
  386. 'Content-Type': 'application/x-www-form-urlencoded'
  387. }
  388. GetResponse = requests.request("POST", GetUrl, headers=GetHeaders, data=payload, timeout=10)
  389. val=pd.DataFrame(pd.read_html(GetResponse.text)[2])[:-1]
  390. if len(val)>0:
  391. val.columns = val.loc[0].values.tolist()
  392. val=val.drop([0])
  393. print(val)
  394. WEBURLTXT=[]
  395. ADMINTXT=[]
  396. StartDATETXT=[]
  397. EndDATETXT=[]
  398. TIMERAND=[]
  399. nowTime=datetime.datetime.now().strftime("%m%d%H%M%S")
  400. randomNum=random.randint(0,10000);
  401. if randomNum<10:
  402. randomNum=str(0)+str(0)+str(0)+str(randomNum)
  403. elif randomNum>10 and randomNum<100:
  404. randomNum=str(0)+str(0)+str(randomNum)
  405. elif randomNum>100 and randomNum<1000:
  406. randomNum=str(0)+str(randomNum)
  407. uniqueNum=str(nowTime)+str(randomNum)
  408. for i in range(len(val)):
  409. WEBURLTXT.append(urlkey)
  410. ADMINTXT.append(adminkey)
  411. StartDATETXT.append(startDatekey)
  412. EndDATETXT.append(endDatekey)
  413. TIMERAND.append(uniqueNum)
  414. val.insert(0,"開始日期",StartDATETXT)
  415. val.insert(1,"結束日期",EndDATETXT)
  416. val.insert(2,"網址",WEBURLTXT)
  417. val.insert(3,"帳戶",ADMINTXT)
  418. val.insert(4,"隨機碼",TIMERAND)
  419. refind=pd.DataFrame(columns =["開始日期","結束日期","網址","帳戶","客戶","總量","中獎","輸贏","客戶小計","代理小計","總代理小計","股東小計","大股東小計","總監小計","個人所得","水差","下注明細","查看對帳","隨機碼"])
  420. val=pd.concat([refind,val],ignore_index = True)
  421. if len(val)>0:
  422. val.columns =["開始日期","結束日期","網址","帳戶","客戶s","總量s","中獎s","輸贏s","客戶小計s","代理小計s","總代理小計s","股東小計s","大股東小計s","總監小計s","個人所得s","水差s","下注明細s","查看對帳s","隨機碼"]
  423. fordebugger="OK"
  424. return val,fordebugger,urlkey,adminkey
  425. else:
  426. val=pd.DataFrame()
  427. fordebugger="查詢期間無資料"
  428. return val,fordebugger,urlkey,adminkey
  429. else:
  430. val=pd.DataFrame()
  431. fordebugger="無法取得資料"
  432. return val,fordebugger,urlkey,adminkey
  433. if response.status_code!=200:
  434. val=pd.DataFrame()
  435. fordebugger="無法取得資料"
  436. return val,fordebugger,urlkey,adminkey
  437. except:
  438. val=pd.DataFrame()
  439. fordebugger="無法取得資料"
  440. return val,fordebugger,urlkey,adminkey
  441. class External(QThread):
  442. """
  443. Runs a counter thread.
  444. """
  445. countChanged = pyqtSignal(int)
  446. urlChanged=pyqtSignal(str)
  447. def run(self):
  448. try:
  449. #-----------------------------------------------------------------------------------------------
  450. with ThreadPoolExecutor(max_workers=10) as executor:
  451. futures = []
  452. test=[]
  453. z=0
  454. x=len(UrlList)
  455. for urlkey,adminkey,passkey in zip(UrlList,AdminList,PasswordList):
  456. future=executor.submit(LongGetData,urlkey,adminkey,passkey, startDatekey, endDatekey)
  457. futures.append(future)
  458. for future in as_completed(futures):
  459. test.append(list(future.result()))
  460. MDF,MDC,MURL,ADMINNNNNN=list(future.result())
  461. MDCURL=MURL+"=>"+MDC
  462. percentvalues=((z+1)/x)*100
  463. self.countChanged.emit(percentvalues)
  464. self.urlChanged.emit(MDCURL)
  465. z=z+1
  466. #-----------------------------------------------------------------------------------------------
  467. ALLDataFrameList=[]
  468. DebugCodeList=[]
  469. ALLDataFrameList.append(refindlong)
  470. ALLDataFrameList.append(refindshort)
  471. ALLDataFrameList=pd.concat(ALLDataFrameList)
  472. ALLDataFrameList0,DebugCodeList,UrlDebugList,ADMINKEYLIST=zip(*test)
  473. ALLDataFrameList0=pd.concat(ALLDataFrameList0)
  474. neewDataFrmoe=pd.concat([ALLDataFrameList,ALLDataFrameList0])
  475. print(neewDataFrmoe)
  476. #-------------------------------------------------------------------------
  477. LOGGER=[]
  478. y=0
  479. for UrlDebugListlog,DebugCodeListlog,ADMINKEYLISTlog in zip(UrlDebugList,DebugCodeList,ADMINKEYLIST):
  480. if DebugCodeListlog=="OK":
  481. print("OK")
  482. else:
  483. LOGGER.append([])
  484. randomNum=random.randint(0,9)
  485. nowTime=datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
  486. nowTime=str(nowTime)+"---"+str(randomNum)
  487. LOGGER[y].append(coustomtxt)
  488. LOGGER[y].append(startDatekey+"-"+endDatekey)
  489. LOGGER[y].append(UrlDebugListlog)
  490. LOGGER[y].append(DebugCodeListlog)
  491. LOGGER[y].append(nowTime)
  492. LOGGER[y].append(ADMINKEYLISTlog)
  493. y=y+1
  494. LOGGER=pd.DataFrame(LOGGER)
  495. if len(LOGGER)>0:
  496. LOGGER.columns =["客戶","查詢區間","網址","狀態","查詢時間","帳號"]
  497. else:
  498. print("NO LOG")
  499. print(LOGGER)
  500. end = time.time()
  501. self.urlChanged.emit("已執行"+str(end - start)+"秒 處理中...")
  502. #------------------------------------------------------------------------
  503. neewDataFrmoe.to_sql('流水帳', con=engine3, if_exists='append')
  504. #neewDataFrmoe.to_csv("M0114UI.csv",encoding="utf_8_sig")#for debug
  505. LOGGER.to_sql('LOG', con=engine3, if_exists='append')
  506. closedatalodibg=LoadingYesorNo()
  507. end = time.time()
  508. print("執行時間:%f 秒" % (end - start))
  509. self.urlChanged.emit("已執行"+str(end - start)+"秒 處理完成")
  510. print("DONE.....................100%")
  511. #window.close()
  512. app.quit()
  513. except Exception:
  514. logging.debug('debug message',exc_info=True)
  515. logging.info('info message',exc_info=True)
  516. logging.warning('warning message',exc_info=True)
  517. logging.error('error message',exc_info=True)
  518. logging.critical('critical message',exc_info=True)
  519. app1 = QtWidgets.QApplication([])
  520. error_dialog = QtWidgets.QErrorMessage()
  521. error_dialog.setWindowTitle('ERROR')
  522. error_dialog.showMessage('連線資料錯誤')
  523. app1.exec_()
  524. finally:
  525. closedatalodibg=LoadingYesorNo()
  526. class Actions(QDialog):
  527. """
  528. Simple dialog that consists of a Progress Bar and a Button.
  529. Clicking on the button results in the start of a timer and
  530. updates the progress bar..
  531. """
  532. def __init__(self):
  533. super().__init__()
  534. self.initUI()
  535. def initUI(self):
  536. self.setWindowTitle('D0124')
  537. self.setWindowFlags(Qt.WindowStaysOnTopHint)
  538. self.progress = QProgressBar(self)
  539. self.progress.setGeometry(20, 20, 300, 25)
  540. self.progress.setMaximum(100)
  541. self.label=QLabel(self)
  542. #self.label.setFont(QtGui.QFont('Arial', 12))
  543. self.label.setGeometry(20, 50, 211, 31)
  544. # self.label.setTextFormat(QtCore.Qt.AutoText)
  545. self.label.setText("- 自動導入中請勿關閉視窗 - ")
  546. # self.button = QPushButton('Start', self)
  547. # self.button.move(0, 30)
  548. self.label2=QLabel(self)
  549. self.label2.setGeometry(20, 70, 211, 31)
  550. self.show()
  551. # self.button.clicked.connect(self.onButtonClick)
  552. # def onButtonClick(self):
  553. self.calc = External()
  554. self.calc.countChanged.connect(self.onCountChanged)
  555. self.calc.urlChanged.connect(self.onUrlChanged)
  556. self.calc.start()
  557. def onCountChanged(self, value):
  558. self.progress.setValue(value)
  559. def onUrlChanged(self, urlstr):
  560. self.label2.setText(urlstr)
  561. class Actions2(QDialog):
  562. """
  563. Simple dialog that consists of a Progress Bar and a Button.
  564. Clicking on the button results in the start of a timer and
  565. updates the progress bar.
  566. """
  567. def __init__(self):
  568. super().__init__()
  569. self.initUI()
  570. def initUI(self):
  571. self.setWindowTitle('連線中...')
  572. self.label=QLabel(self)
  573. #self.label.setFont(QtGui.QFont('Arial', 12))
  574. self.label.setGeometry(20, 20,120,30)
  575. #self.label.setTextFormat(QtCore.Qt.AutoText)
  576. self.label.setText("- 取得連線 請按開始 -")
  577. self.button = QPushButton('開始', self)
  578. self.button.move(50, 80)
  579. self.show()
  580. self.button.clicked.connect(self.onButtonClick)
  581. def onButtonClick(self):
  582. self.close()
  583. try:
  584. #app1 = QApplication(sys.argv)
  585. #window2 = Actions2()
  586. FIle="A.txt"
  587. FIle2="B.txt"
  588. def LoadingYesorNo():
  589. SUPDA=db_session2.query(Someoneupdate).filter_by(正在自動導入中='YES').first()
  590. SUPDAc=db_session2.query(Someoneupdate).filter_by(正在自動導入中='YES').count()
  591. print(SUPDAc)
  592. if (SUPDAc==1):
  593. SUPDA.正在自動導入中='NO'
  594. db_session2.commit()
  595. coustomtxt,bdtxt=loadCSV()
  596. engine = create_engine('mssql+pyodbc://'+bdtxt+'?driver=SQL+Server+Native+Client+11.0')
  597. print (coustomtxt)
  598. engine3=connectEngine(coustomtxt,engine)
  599. DB_session2 = sessionmaker(engine3)
  600. db_session2= DB_session2()
  601. log_Engine=CreateLogEngine()
  602. while True:
  603. if os.path.isfile(FIle)==True:
  604. os.remove(FIle)
  605. startDatekey,endDatekey,allpart=DateDataLoad(engine3,db_session2)
  606. contforloop,loopper2=LoadCustomData(engine3,allpart)
  607. UrlList,AdminList,PasswordList=zip(*loopper2)
  608. print(UrlList,AdminList,PasswordList)
  609. start = time.time()
  610. refindlong=pd.DataFrame(columns =["開始日期","結束日期","網址","帳戶","名稱","總量","退水","中獎","輸贏","佔成輸贏","水倍差","上繳金額","自已總輸贏","上繳貢獻額","貢獻額","貢獻度","下注明細","玩法明細","調盤退水","調退實佔","上繳","會員","代理","總代理","股東","大股東","總監"])
  611. refindshort=pd.DataFrame(columns =["開始日期","結束日期","網址","帳戶","客戶s","總量s","中獎s","輸贏s","客戶小計s","代理小計s","總代理小計s","股東小計s","大股東小計s","總監小計s","個人所得s","水差s","下注明細s","查看對帳s","隨機碼"])
  612. #window2.close()
  613. #app1.quit()
  614. #app1.exec_()
  615. print("uuuuuuuu")
  616. app = QtWidgets.QApplication(sys.argv)
  617. print("oooooooo")
  618. window = Actions()
  619. app.exec_()
  620. del app
  621. del window
  622. #sys.exit(app.exec_())
  623. continue
  624. if os.path.isfile(FIle2)==True:
  625. os.remove(FIle2)
  626. break
  627. time.sleep(1)
  628. #sys.exit()
  629. except:
  630. traceback.print_exc() # 捕捉異常,並將異常傳播資訊輸出控制檯
  631. traceback.print_exc(file=open('log.txt', 'a'))
  632. logging.debug('debug message',exc_info=True)
  633. logging.info('info message',exc_info=True)
  634. logging.warning('warning message',exc_info=True)
  635. logging.error('error message',exc_info=True)
  636. logging.critical('critical message',exc_info=True)
  637. app2 = QtWidgets.QApplication([])
  638. error_dialog = QtWidgets.QErrorMessage()
  639. error_dialog.setWindowTitle('ERROR')
  640. error_dialog.showMessage('網路DRIVER錯誤')
  641. app2.exec_()
  642. finally:
  643. closedatalodibg=LoadingYesorNo()