utils.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. import datetime
  2. import time
  3. import json
  4. import requests
  5. from selenium.webdriver.support import expected_conditions as EC
  6. from selenium import webdriver
  7. from selenium.webdriver import ActionChains
  8. from selenium.webdriver.common.by import By
  9. from selenium.webdriver.support.wait import WebDriverWait
  10. from selenium.webdriver.chrome.options import Options
  11. class flight_list(object):
  12. def __init__(self):
  13. self.url = r"http://me.sichuanair.com/login.shtml"
  14. self.login_url = "https://login.sichuanair.com/idp/AuthnEngine?currentAuth=urn_oasis_names_tc_SAML_2.0_ac_classes_BAMUsernamePassword"
  15. self.flight_list_url = "https://me.sichuanair.com/api/v1/plugins/LM_FLIGHT_LIST"
  16. self.flight_list_third_url = "https://me.sichuanair.com/api/v1/plugins/LM_FLIGHT_THIRD_LIST"
  17. self.task_flight_list_url="https://me.sichuanair.com/api/v1/plugins/LM_TASK_ASSIGNMENT_LIST"
  18. self.LM_FJ_TASK_PG="https://me.sichuanair.com/api/v1/plugins/LM_FJ_TASK_PG"
  19. self.task_filght_third_list_url="https://cscsupplier.sichuanair.com/api/v1/plugins/LM_TASK_ASSIGNMENT_THIRD_LIST"
  20. self.LM_TSK_DINGDONG_url ="https://cscsupplier.sichuanair.com/api/v1/plugins/LM_TSK_DINGDONG"
  21. self.LM_TSK_SURE_PG_url="https://cscsupplier.sichuanair.com/api/v1/plugins/LM_TSK_SURE_PG"
  22. self.LM_TSK_EMP_PGLIST_url="https://cscsupplier.sichuanair.com/api/v1/plugins/LM_TSK_EMP_PGLIST"
  23. self.MM_GJJH_LIST="https://cscsupplier.sichuanair.com/api/v1/plugins/MM_GJJH_LIST"
  24. self.LM_TSK_HANDOVER_url="https://cscsupplier.sichuanair.com/api/v1/plugins/LM_TSK_HANDOVER"
  25. self.LM_FLIGHT_SEARCH_LIST='https://cscsupplier.sichuanair.com/api/v1/plugins/LM_FLIGHT_SEARCH_LIST'
  26. self.LM_TASK_ARCHIVE_LIST='https://cscsupplier.sichuanair.com/api/v1/plugins/LM_TASK_ARCHIVE_LIST'
  27. self.jobcard='https://cscsupplier.sichuanair.com'
  28. self.token = None
  29. #amro状态
  30. self.amro_status = 0
  31. self.flight_list_json = None
  32. self.flight_list_third_json = None
  33. def start(self, username, password):
  34. try:
  35. self.token = self.login(username, password)
  36. except Exception:
  37. pass
  38. return self.token
  39. def login(self, username, password):
  40. try:
  41. options = webdriver.EdgeOptions()
  42. options.use_chromium = True
  43. #options.add_experimental_option('excludeSwitches', ['enable-logging'])
  44. #options.add_argument("headless")
  45. #options.add_argument("disable-gpu")
  46. #options.add_argument('start-maximized')
  47. #options.add_argument('window-size=1920x1080')
  48. self.driver = webdriver.Edge(options=options)
  49. self.actions = ActionChains(self.driver)
  50. except:
  51. chrome_options = Options()
  52. chrome_options.add_argument("--headless")
  53. chrome_options.add_argument("window-size=1920x1080")
  54. chrome_options.add_argument("--start-maximized")
  55. chrome_options.add_argument('--disable-gpu') # 如果不加这个选项,有时定位会出现问题
  56. self.driver = webdriver.Chrome(executable_path=r'D:\flightinfo\Google\Chrome\Application\chromedriver.exe',
  57. # executable_path=path
  58. options=chrome_options)
  59. self.actions = ActionChains(self.driver)
  60. self.driver.get(self.url)
  61. WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'singleSubmit')))
  62. loginbtn = self.driver.find_element('id', 'singleSubmit')
  63. time.sleep(0.5)
  64. self.actions.click(loginbtn)
  65. self.actions.perform()
  66. WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "j_username"))).send_keys(
  67. username)
  68. time.sleep(0.5)
  69. self.driver.find_element('name', "j_password").send_keys(password)
  70. #time.sleep(0.5)
  71. time.sleep(0.5)
  72. self.driver.find_element_by_xpath("//button[@type='button']").click()
  73. time.sleep(1)
  74. for cookie in self.driver.get_cookies():
  75. if "_amro_sk" in cookie.values():
  76. self.amro_status = 1
  77. self.driver.quit()
  78. return "_amro_sk=" +cookie["value"]
  79. else:
  80. pass
  81. self.driver.quit()
  82. def get_cookie(self):
  83. if self.token!=None:
  84. return self.token
  85. else:
  86. return None
  87. def checkCookieSts(self,cookie):
  88. url = "https://me.sichuanair.com/api/v1/plugins/PROCESS_CLAIM_TASK_PRO_LIST"
  89. data = {
  90. 'user_id': '',
  91. 'userId': '',
  92. 'accountType': 'ARCHIVE',
  93. 'page': '1',
  94. 'rows': '11'
  95. }
  96. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  97. "Cookie": cookie}
  98. result = requests.post(url, data, headers=header).json()
  99. #print(result['code'], result['msg'], result['data'])
  100. return result['code']
  101. def checkWorkjob(self,taskids,acno,taskType,actype,startDate,endDate,cookie):
  102. data = {"taskids": taskids,
  103. "acno": acno,
  104. "taskType": taskType,
  105. "actype": actype,
  106. "startDate": startDate,
  107. "endDate": endDate
  108. }
  109. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  110. "Cookie": cookie}
  111. try:
  112. self.LM_FJ_TASK_PG_json = requests.post(url=self.LM_FJ_TASK_PG, data=data, headers=header).json()
  113. except Exception:
  114. self.LM_FJ_TASK_PG_json = None
  115. return self.LM_FJ_TASK_PG_json
  116. def request_jobcard(self, cookie, filename): # 需要自动逻辑白班夜班
  117. one_year_later = datetime.datetime.now() + datetime.timedelta(days=365)
  118. timestamp = int(one_year_later.timestamp()*1000)
  119. header = {
  120. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
  121. "Cookie": cookie}
  122. try:
  123. task_jobcard_json = requests.get(url=f'https://cscsupplier.sichuanair.com{filename}?_cache_timestamp={timestamp}',headers=header).content
  124. except Exception:
  125. task_jobcard_json = None
  126. return task_jobcard_json
  127. def request_MM_GJJH_LIST(self,cookie):
  128. yesterday=(datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
  129. today = datetime.date.today().strftime("%Y-%m-%d")
  130. data={"mfrpn":"",
  131. "zjcdats": yesterday,
  132. "zjcdate": today,
  133. "zwgh": "Y",
  134. "zlynam":"",
  135. "zbmtxt":"",
  136. "zkstxt":"",
  137. "zfdtxt":"",
  138. "zlgort": "TF20",
  139. "zghnam":"",
  140. "ghrbm":"",
  141. "ghrks":"",
  142. "ghrfd":"",
  143. "zghkcd":"",
  144. "sort": "ZBMTXT",
  145. "order": "asc"
  146. }
  147. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  148. "Cookie": cookie}
  149. try:
  150. self.MM_GJJH_LIST_json = requests.post(url=self.MM_GJJH_LIST, data=data, headers=header).json()
  151. except Exception:
  152. self.MM_GJJH_LIST_json = None
  153. return self.MM_GJJH_LIST_json
  154. def request_task_filght_list(self, flightDate:str,cookie): #需要自动逻辑白班夜班
  155. data = {"airportCode": "ZUTF",
  156. "ddate": flightDate,
  157. "notView":"",
  158. "baseCode": "TF01",
  159. "actype1":"(A319|A320|A321)",
  160. "aclocArea1": "()",
  161. "tasktype1": "()",
  162. "shift":"",
  163. "tasktype":"",
  164. "actype": "A319,A320,A321",
  165. "aclocArea":"",
  166. "isshiftex":"",
  167. "repush":"",
  168. "page": "1",
  169. "rows": "500"
  170. }
  171. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  172. "Cookie": cookie}
  173. try:
  174. self.task_flight_list_json = requests.post(url=self.task_flight_list_url, data=data, headers=header).json()
  175. except Exception:
  176. self.task_flight_list_json = None
  177. #with open('./temp/task_flight_list_json/fl{}.json'.format(int(time.time())), 'w') as f:
  178. #json.dump(self.task_flight_list_json, f, indent=4)
  179. return self.task_flight_list_json
  180. def request_task_filght_third_list(self, flightDate:str, cookie): #需要自动逻辑白班夜班
  181. data = {"airportCode": "ZUTF",
  182. "ddate": flightDate,
  183. "notView":"",
  184. "baseCode": "TF01",
  185. "isThird": "Y",
  186. "actype1":"",
  187. "aclocArea1": "()",
  188. "tasktype1": "()",
  189. "shift":"",
  190. "tasktype":"",
  191. "actype": "(A319|A320|A321|B737NG|B737MAX|C919)",
  192. "aclocArea":"",
  193. "isshiftex":"",
  194. "repush":"",
  195. "page": "1",
  196. "rows": "500"
  197. }
  198. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  199. "Cookie": cookie}
  200. try:
  201. self.task_filght_third_list = requests.post(url=self.task_filght_third_list_url, data=data, headers=header).json()
  202. except Exception:
  203. self.task_filght_third_list = None
  204. #with open('./temp/task_filght_third_list/fl{}.json'.format(int(time.time())), 'w') as f:
  205. # json.dump(self.task_filght_third_list, f, indent=4)
  206. return self.task_filght_third_list
  207. def request_LM_TASK_ARCHIVE_LIST(self, flightDate:str, cookie): #需要自动逻辑白班夜班
  208. startdatePlStart=flightDate+" 00:00:00"
  209. flightDate2=(datetime.datetime.strptime(flightDate, "%Y%m%d")+datetime.timedelta(days=1)).strftime("%Y%m%d")
  210. startdatePlEnd=flightDate2+" 09:00:00"
  211. data = {"startdatePlStart": startdatePlStart,
  212. "startdatePlEnd": startdatePlEnd,
  213. "airportCode":'ZUTF',
  214. "taskTypeDefault": "LM",
  215. "actype1": '(A319|A320|A321)',
  216. "actype": "A319,A320,A321",
  217. "baseCode": "TF01",
  218. "page":"1",
  219. "rows": "500"
  220. }
  221. header = {"Accept": "application/json, text/javascript, */*; q=0.01","Cookie": cookie}
  222. try:
  223. self.task_LM_TASK_ARCHIVE_LIST = requests.post(url=self.LM_TASK_ARCHIVE_LIST, data=data, headers=header).json()
  224. except Exception:
  225. self.task_LM_TASK_ARCHIVE_LIST = None
  226. #with open('./temp/task_LM_FLIGHT_SEARCH_LIST/fl{}.json'.format(int(time.time())), 'w') as f:
  227. # json.dump(self.task_LM_FLIGHT_SEARCH_LIST, f, indent=4)
  228. return self.task_LM_TASK_ARCHIVE_LIST
  229. def request_LM_FLIGHT_SEARCH_LIST(self, flightDate:str, cookie): #需要自动逻辑白班夜班
  230. data = {"base4code": "ZUTF",
  231. "flightDate": flightDate,
  232. "flightDate1":flightDate,
  233. "jcType": "",
  234. "actype1": '(A319|A320|A321)',
  235. "dep_4code": "",
  236. "arr_4code": "",
  237. "acno":'',
  238. "actype": "A319,A320,A321",
  239. "flightNo":"",
  240. "notView":"",
  241. "page":"1",
  242. "onlyAf":"",
  243. "rows": "500"
  244. }
  245. header = {"Accept": "application/json, text/javascript, */*; q=0.01","Cookie": cookie}
  246. try:
  247. self.task_LM_FLIGHT_SEARCH_LIST = requests.post(url=self.LM_FLIGHT_SEARCH_LIST, data=data, headers=header).json()
  248. except Exception:
  249. self.task_LM_FLIGHT_SEARCH_LIST = None
  250. #with open('./temp/task_LM_FLIGHT_SEARCH_LIST/fl{}.json'.format(int(time.time())), 'w') as f:
  251. # json.dump(self.task_LM_FLIGHT_SEARCH_LIST, f, indent=4)
  252. return self.task_LM_FLIGHT_SEARCH_LIST
  253. def request_filght_list(self, flightDate:str, cookie):
  254. data = {"base4code": "ZUTF",
  255. "flightDate": flightDate,#2023-06-02
  256. "tasktype": "",
  257. "notView": "",
  258. "jcType": "",
  259. "actype1": "(A319|A320|A321)",
  260. "actype": "A319,A320,A321",
  261. "acno": "",
  262. "dep_4code": "",
  263. "arr_4code": "",
  264. "flightNo": "",
  265. "repush": ""
  266. }
  267. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  268. "Cookie": cookie}
  269. try:
  270. self.flight_list_json = requests.post(url=self.flight_list_url, data=data, headers=header).json()
  271. except Exception:
  272. self.flight_list_json = None
  273. #with open('./temp/filght_list/fl{}.json'.format(int(time.time())), 'w') as f:
  274. # json.dump(self.flight_list_json, f, indent=4)
  275. return self.flight_list_json
  276. def request_LM_TSK_HANDOVER(self,dict:dict,cookie):
  277. data = {
  278. "taskids": dict["taskid"],
  279. "tasksts": dict["sts"], # 必须,可能需要修改,不知道影响不
  280. "FunctionCode": "LM_TSK_HANDOVER"
  281. }
  282. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  283. "Cookie": cookie}
  284. try:
  285. self.LM_TSK_HANDOVER = requests.post(url=self.LM_TSK_HANDOVER_url, data=data, headers=header).json()
  286. #print(self.LM_TSK_HANDOVER)
  287. except Exception:
  288. self.LM_TSK_HANDOVER = None
  289. return self.LM_TSK_HANDOVER
  290. def request_LM_TSK_DINGDONG(self,dict:dict,cookie):
  291. data = {"tasksts": "1", # 必须
  292. "taskid": "{}".format(dict["taskid"]),
  293. "acno": dict["acno"],
  294. "actype": dict["actype"],
  295. "tasktype": dict["tasktype"],
  296. "tatd": dict["tatd"],
  297. "msgInfo": dict["msgInfo"],
  298. "bay": dict["bay"],
  299. "wxemp": dict["wxemp"], # 必须dict["wxemp"]
  300. "fxemp": dict["fxemp"],
  301. "wx": dict["wx"],
  302. "fx": dict["fx"],
  303. "ecsj": dict["ecsj"],
  304. "ecsjEmp": "",
  305. "FunctionCode": "LM_TSK_DINGDONG"
  306. }
  307. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  308. "Cookie": cookie}
  309. try:
  310. self.LM_TSK_DINGDONG = requests.post(url=self.LM_TSK_DINGDONG_url, data=data, headers=header).json()
  311. except Exception:
  312. self.LM_TSK_DINGDONG = None
  313. return self.LM_TSK_DINGDONG
  314. def request_flight_third_list(self, flightDate: str, cookie):
  315. data = {"base4code": "ZUTF",
  316. "flightDate": flightDate,
  317. "flightDateStart": flightDate,
  318. "tasktype": "",
  319. "notView": "",
  320. "isThird":"Y",
  321. "actype1": "(21N|319|320|321|32N|332|738|73G|A21N|A319|A319|A320|A321|A32N|A738|A73G|AZZZ|B737|C919)",
  322. "actype": "B737NG,B737MAX,A319,A320,A321,C919"
  323. #"actype": "A319%2CA320%2CA321%2CB737MAX%2CB737NG"
  324. }
  325. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  326. "Cookie": cookie}
  327. try:
  328. self.flight_third_list = requests.post(url=self.flight_list_third_url, data=data, headers=header).json()
  329. except Exception:
  330. self.flight_third_list = None
  331. #with open('./temp/filght_list/fl{}.json'.format(int(time.time())), 'w') as f:
  332. # json.dump(self.flight_third_list, f, indent=4)
  333. return self.flight_third_list
  334. def request_LM_TSK_SURE_PG(self,dict:dict,cookie):
  335. empNos = dict["empNos"]
  336. taskid = dict["taskid"]
  337. type = dict["type"]
  338. shiftDate = dict["shiftDate"]
  339. shift = dict["shift"]
  340. data = {"empNos": empNos,
  341. "taskid": taskid,
  342. "type": type, #ECSJ 二次送机 WX FX
  343. "shiftDate": shiftDate, #夜班航前需要前一天
  344. "shift": shift,
  345. "FunctionCode": "LM_TSK_SURE_PG"
  346. }
  347. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  348. "Cookie": cookie}
  349. try:
  350. #print(data)
  351. self.LM_TSK_SURE_PG = requests.post(url=self.LM_TSK_SURE_PG_url, data=data, headers=header).json()
  352. #print(self.LM_TSK_SURE_PG )
  353. except Exception:
  354. self.LM_TSK_SURE_PG = None
  355. return self.LM_TSK_SURE_PG
  356. def request_LM_TSK_EMP_PGLIST(self,taskid:str,shiftDate:str,shift:str,cookie):
  357. data = {"flightDate": shiftDate,
  358. "shift": shift,
  359. "type": "WX",
  360. "taskid":taskid,
  361. "wx": "wx",
  362. "baseCode": "TF01", #EMP_NO,NAME,MAINLY_ROLE
  363. "deptNo": "",
  364. "fx": "fx",
  365. }
  366. header = {"Accept": "application/json, text/javascript, */*; q=0.01",
  367. "Cookie": cookie}
  368. try:
  369. self.LM_TSK_EMP_PGLIST = requests.post(url=self.LM_TSK_EMP_PGLIST_url, data=data, headers=header).json()
  370. except Exception:
  371. self.LM_TSK_EMP_PGLIST = None
  372. #with open('./temp/LM_TSK_EMP_PGLIST/fl{}.json'.format(int(time.time())), 'w') as f:
  373. # json.dump(self.LM_TSK_EMP_PGLIST, f, indent=4)
  374. return self.LM_TSK_EMP_PGLIST
  375. if __name__ == '__main__':
  376. fl = flight_list()
  377. #fl.start()
  378. nowDay = datetime.datetime.now().replace(microsecond=0)
  379. nowDayStr = nowDay.strftime("%Y-%m-%d")