This repository was archived by the owner on Jun 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjte.py
More file actions
64 lines (58 loc) · 2.21 KB
/
jte.py
File metadata and controls
64 lines (58 loc) · 2.21 KB
1
2
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
#!/usr/bin/env python3
__author__ = "Md. Minhazul Haque"
__license__ = "GPLv3"
"""
Copyright (c) 2018 Md. Minhazul Haque
This file is part of mdminhazulhaque/bd-mrp-api
(see https://github.com/mdminhazulhaque/banglalionwimaxapi).
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import requests
import tabulate
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
from bs4 import BeautifulSoup
def jte_info(billcode):
session = requests.Session()
response = session.get("https://www.jtexpress.my/track")
soup = BeautifulSoup(response.text, "html.parser")
token = soup.find('input', {'name': '_token'}).get('value')
headers = {
'content-type': 'application/x-www-form-urlencoded',
'accept': 'text/html,application/xhtml+xml,application/xml'
}
data = {
'_token': token,
'billcode': billcode
}
response = session.post('https://www.jtexpress.my/track', headers=headers, data=data)
soup = BeautifulSoup(response.text, "html.parser")
timeline = soup.find('div', {'class': 'timeline'})
data = []
for entry in timeline:
try:
date = entry.find("h3").text
others = entry.find_all("p")
time = others[0].text
desc = others[1].text
city = others[2].text.replace("City : ", "")
state = others[3].text
data.append([date, time, desc, city, state])
except Exception as e:
pass
t_headers = "Date Time Description City State".split(" ")
print(tabulate.tabulate(data, headers=t_headers))
if __name__ == "__main__":
import sys
billcode = sys.argv[1]
jte_info(billcode)