You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
7.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. # %%
  2. import requests
  3. from bs4 import BeautifulSoup as bs
  4. base_url = 'http://family.wanhai.com'
  5. loginURL = base_url + '/Login.jsp'
  6. account = 'M1933'
  7. password = '1933whlM'
  8. payload = {'Account': account, 'Password': password}
  9. meeting_rooms = None
  10. massage_rooms = None
  11. session_req = None
  12. # session_req.post(loginURL,data=payload)
  13. # %%
  14. def login(id, pw):
  15. global session_req
  16. if session_req == None:
  17. session_req = requests.Session()
  18. res = session_req.post(
  19. loginURL, data={'Account': account, 'Password': password})
  20. print(res.request.headers['Cookie'])
  21. # %%
  22. def isLogin():
  23. global session_req
  24. if session_req == None:
  25. session_req = requests.Session()
  26. route_url = base_url + '/MainPage.jsp'
  27. res = session_req.get(route_url, allow_redirects=False)
  28. if res.status_code == 200:
  29. print(res.request.headers['Cookie'])
  30. return True
  31. else:
  32. return False
  33. # %%
  34. def getEquipList(type='MEETING'):
  35. equipList_url = base_url + '/LeaseEquip/equipListOnePage.jsp'
  36. result = session_req.get(
  37. equipList_url+'?file_num=61621&account_id=' + account + '&equip_type='+type)
  38. print(result.request.headers['Cookie'])
  39. soup = bs(result.text, 'html.parser')
  40. elements = soup.find_all('input', {'id': 'check2', 'name': 'ID_keyD'})
  41. equipDict = dict()
  42. for v1, v2 in [(e['value'], e.find_parent().find_next_sibling().text) for e in elements]:
  43. equipDict[v1] = {'id': v1, 'type': type, 'name': v2}
  44. # print(equipDict)
  45. return equipDict
  46. # %%
  47. def getEquipName(equipId):
  48. if equipId in meeting_rooms.keys():
  49. return meeting_rooms[equipId]['name']
  50. elif equipId in massage_rooms.keys():
  51. return massage_rooms[equipId]['name']
  52. else:
  53. return None
  54. # %%
  55. # 查詢設備是否已被占用(by 特定日期/時段)
  56. def isEquipInUsed(b_date, b_time, e_time, equip_type, equip_id):
  57. if equip_type == 'MASSAGE':
  58. print('Not Support Now!!!')
  59. return False
  60. equipUsageURL = base_url+'/LeaseEquip/equipUsage.jsp'
  61. payload = [('q_from_date', b_date),
  62. ('q_from_time', b_time),
  63. ('q_to_date', b_date),
  64. ('q_to_time', e_time),
  65. ('q_equip_type', equip_type),
  66. ('ID_keyD', equip_id)]
  67. result = session_req.post(equipUsageURL, data=payload)
  68. soup = bs(result.text, 'html.parser')
  69. elements = soup.select('td > b')
  70. if (len(elements) > 1) and (not '目前無人預約' in elements[1].text):
  71. return True
  72. else:
  73. return False
  74. return False
  75. # %%
  76. # 查詢設備可用時段(by 特定日期)
  77. def search_available_time(equip_type, equip_id, strDate):
  78. if equip_type == 'MASSAGE':
  79. print('Not Support Now!!!')
  80. return
  81. from interval import Interval
  82. equipUsageURL = base_url+'/LeaseEquip/equipUsage.jsp'
  83. payload = [('q_from_date', strDate),
  84. ('q_from_time', ''),
  85. ('q_to_date', strDate),
  86. ('q_to_time', ''),
  87. ('q_equip_type', equip_type),
  88. ('ID_keyD', equip_id)]
  89. result = session_req.post(equipUsageURL, data=payload)
  90. soup = bs(result.text, 'html.parser')
  91. # print(soup.prettify())
  92. print('{}:\n{}'.format(equip_id, soup.select('td[nowrap]')[0].text))
  93. # %%
  94. # 查詢可用設備(by 特定日期/時段)
  95. def search_available_equips(equip_type, strDate, b_time, e_time):
  96. if equip_type == 'MASSAGE':
  97. print('Not Support Now!!!')
  98. return
  99. from interval import Interval
  100. equipUsageURL = base_url+'/LeaseEquip/equipUsage.jsp'
  101. payload = [('q_from_date', strDate),
  102. ('q_from_time', ''),
  103. ('q_to_date', strDate),
  104. ('q_to_time', ''),
  105. ('q_equip_type', equip_type)]
  106. payload.extend([('ID_keyD', e) for e in meeting_rooms.keys()])
  107. result = session_req.post(equipUsageURL, data=payload)
  108. soup = bs(result.text, 'html.parser')
  109. equips = [equip.text.strip() for equip in soup.select(
  110. 'div[id="equips"] td[align="center"]')]
  111. # print(equips)
  112. availList = list()
  113. for index, elem in enumerate(soup.select('td[nowrap]')):
  114. availList.insert(index, 1)
  115. if '目前無人預約' in elem.text:
  116. continue
  117. target = Interval(int(b_time), int(e_time), closed=False)
  118. periods = [x.text.split('~') for x in elem.select('b')]
  119. periodIntvs = [Interval(x[0], x[1]) for x in list(
  120. map(lambda bb:[int(x) for x in bb], periods))]
  121. # print(equips[index])
  122. # for pp in periodIntvs:
  123. # print(pp,'\n')
  124. for periodIntv in periodIntvs:
  125. if target.overlaps(periodIntv):
  126. availList[index] = 0
  127. break
  128. # print(availList)
  129. for index, avail in enumerate(availList):
  130. if avail == 1:
  131. print('{}\n'.format(equips[index]))
  132. # %%
  133. # 預約設備
  134. def bookingEquip(equip_id, equip_type, strDate, b_time, e_time):
  135. if equip_type == 'MASSAGE':
  136. print('Not Support Now!!!')
  137. bookingURL = base_url + '/LeaseEquip/equipBooking_db.jsp'
  138. payload = {
  139. 'item_choice1': 'F',
  140. 'equipment_id1': equip_id,
  141. 'lease_action1': 'book',
  142. 'str_yymmdd': strDate,
  143. 'f_rent_fm1': b_time,
  144. 'f_rent_to1': e_time,
  145. 'equip_count': '1',
  146. 'f_str_remark1': '#7253',
  147. 'contactor_mail1': 'x'
  148. # 'lease_time_code_1': '',
  149. # 'term_time_code1': '',
  150. # 'equip_name_c1': '<5F>台北廳 【可容納90人】',
  151. # 'lease_time_code1': 'enter_rent_time',
  152. # 'tea1': '0',
  153. # 'water1': '0',
  154. # 'coffee1': '0',
  155. # 'meeting_type1': 'IN',
  156. # 'selected_year': '2019',
  157. # 'selected_month': '06',
  158. # 'selected_day': '06',
  159. # 'equip_type': 'MEETING',
  160. # 'fm_date': '20190606',
  161. # 'to_date': '20190606',
  162. # 'select_equips': equip_id
  163. }
  164. soup = bs(session_req.post(bookingURL, data=payload).text, 'html.parser')
  165. print(soup.select('table tr:nth-child(2) td:nth-child(5)')[0].text)
  166. # print(soup.prettify())
  167. # %%
  168. # 取消預約設備
  169. def cancalBookingEquip(equip_type, rent_no):
  170. if equip_type == 'MASSAGE':
  171. print('Not Support Now!!!')
  172. bookingURL = base_url + '/LeaseEquip/userBooking_db.jsp'
  173. payload = {
  174. # 'ID_key': '0u',
  175. # 'action_type_0u': 'U',
  176. 'action_type': 'D',
  177. 'ID_keyDD': rent_no,
  178. # 'i_rent_no_0u': rent_no
  179. # 'ID_key': '1u',
  180. # 'action_type_1u': 'U',
  181. # 'i_rent_no_1u': '350438',
  182. # 'q_equip_id':'',
  183. # 'q_rent_date':'',
  184. # 'q_rent_no':'',
  185. # 'q_su_id':''
  186. }
  187. soup = bs(session_req.post(bookingURL, data=payload).text, 'html.parser')
  188. print(soup.prettify())
  189. # %%
  190. # 列出個人設備預約紀錄
  191. def listRentedEquips():
  192. equipList_url = base_url + '/LeaseEquip/equipListOnePage.jsp'
  193. result = session_req.get(
  194. equipList_url+'?file_num=61621&account_id=' + account + '&equip_type=MEETING')
  195. soup = bs(result.text, 'html.parser')
  196. elements = soup.select('form[name="dataForm1"] input[name^="i_rent_no"]')
  197. elements = [x.find_parent().select('td[align="center"]') for x in elements]
  198. rentedList = [(x[0].input['value'], x[1].text, x[2].text, x[3].text)
  199. for x in elements]
  200. return rentedList
  201. # %%
  202. listRentedEquips()
  203. # %%
  204. equipId = 'CF15-10F-DN-01'
  205. print(getEquipName(equipId))
  206. inUsed = isEquipInUsed('20190606', '1900', '2000', 'MEETING', equipId)
  207. print('Equip in used? {}'.format(inUsed))
  208. # %%
  209. search_available_equips('MEETING', '20190624', '0900', '1200')
  210. # %%
  211. search_available_time('MEETING', 'CF01-9F', '20190624')
  212. # %%
  213. if not isLogin():
  214. login(account, password)
  215. meeting_rooms = getEquipList('MEETING')
  216. massage_rooms = getEquipList('MASSAGE')
  217. for x in meeting_rooms:
  218. print(x, meeting_rooms.get(x))
  219. print('\n')
  220. for x in massage_rooms:
  221. print(x, massage_rooms.get(x))
  222. # %%
  223. if __name__ == '__main__':
  224. pass