utils.py 17 KB

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