| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 
 | """auth: 二一袖
 desc: 汽车票监控
 
 run: get_bus_list("出发地", "到达地", "2023-11-09")
 """
 
 import requests
 import jmespath
 
 
 headers = {
 'Accept': 'application/json, text/javascript, */*; q=0.01',
 'Accept-Language': 'zh,en-US;q=0.9,en;q=0.8,zh-CN;q=0.7',
 'Cache-Control': 'no-cache',
 'Connection': 'keep-alive',
 'Content-Type': 'application/json;charset=UTF-8',
 'Origin': 'https://bus.ly.com',
 'Pragma': 'no-cache',
 'Referer': 'https://bus.ly.com/',
 'Sec-Fetch-Dest': 'empty',
 'Sec-Fetch-Mode': 'cors',
 'Sec-Fetch-Site': 'same-origin',
 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
 'X-Requested-With': 'XMLHttpRequest',
 'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
 'sec-ch-ua-mobile': '?0',
 'sec-ch-ua-platform': '"Windows"'
 }
 
 
 url = 'https://bus.ly.com/busresapi/schedule/getScheduleList?plateId=3'
 
 def get_bus_list(start, end, date):
 """
 :param start  出发地  成都
 :param end    目的地  金堂县
 :param date   时间  2024-09-15
 """
 data = {
 'departure': start,
 'destination': end,
 'departureDate': date,
 'depId': '',
 'desId': '',
 'page': 1,
 'pageSize': 25,
 'orderTime': 0,
 'orderPrice': 0,
 'dptTimeSpan': '',
 'departureStation': '',
 'arrivalStation': '',
 'hasCategory': True
 }
 
 try:
 response = requests.post(url,json=data,headers=headers)
 response.raise_for_status()
 result = jmespath.search("body.schedule[?bookingDesc==''].{dptDate:dptDate,dptTime:dptTime,start_station:dptStation,end_station:arrStation,bus_type:coachType,ticketPrice:ticketPrice,ticketLeft:ticketLeft}",response.json())
 
 send_msg(result)
 
 except requests.RequestException as e:
 print(e)
 
 def send_msg(data):
 """
 发送到企业微信机器人
 """
 msgs = ""
 for conf in data:
 msgs += "\n出发时间:{dptDate} {dptTime}\n出发车站:{start_station}\n到达车站:{end_station}\n车型:{bus_type}\n票价:{ticketPrice}\n剩余车票:<font color=\"warning\">{ticketLeft}</font>\n ".format(**conf)
 
 data = {
 "msgtype": "markdown",
 "markdown": {
 "content": msgs
 }
 }
 
 
 requests.post("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={企微机器人key}",
 json=data,
 headers={"Content-Type": "application/json"})
 
 
 if __name__ == "__main__":
 get_bus_list("成都", "金堂县", "2024-09-15")
 
 |