Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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