-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPL.py
103 lines (81 loc) · 3.2 KB
/
PL.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from PyQt5.QtCore import QTimer
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import *
import requests, sys
from bs4 import BeautifulSoup as BS
class PLTracker(QDialog):
def __init__(self):
super(PLTracker, self).__init__()
loadUi("PL Tracker.ui", self)
# Tables
self.tblTracking.setColumnWidth(0,170)
self.tblTracking.setColumnWidth(1,250)
self.tblTracking.setColumnWidth(2,300)
# Handles Button Track and Call Track
self.btnTrack.clicked.connect(self.Track)
def formatPL(self, tr):
status = False
length = 2
los = []
for i in range(0, len(tr), length):
los.append(tr[i:length])
if len(tr) == 14 and los[0] in ['EE','EH','EP','ER','EN','EM','PL']:
status = True
else:
status = False
return status
def loadTracking(self):
url = "https://sendparcel.poslaju.com.my/open/trace"
tracking = self.inTracking.text()
payload = {"tno":tracking}
header = {
'Connection':'keep-alive',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
}
res = requests.get(url,payload, headers = header)
html_data = res.content
# Get Table Row and Columns
table_data = [[cell.text for cell in row("td")]
for row in BS(html_data, features="lxml")("tr")]
curRow = 0
self.tblTracking.setRowCount(len(table_data)-1)
if len(table_data) > 0 and table_data[1][1] != "No record found":
del table_data[0] # Remove First Item - Contain Nothing
for date,status,place in table_data:
self.tblTracking.setItem(curRow, 0, QTableWidgetItem(date))
self.tblTracking.setItem(curRow, 1, QTableWidgetItem(place))
self.tblTracking.setItem(curRow, 2, QTableWidgetItem(status))
curRow += 1
else:
al = QMessageBox(self)
al.setText("Tracking Not Found!")
al.setWindowTitle("Warning!")
al.show()
def StopSpam(self):
QTimer.singleShot(5000, lambda: self.btnTrack.setDisabled(False))
def Track(self):
al = QMessageBox(self)
tmp = self.inTracking.text()
if tmp == "":
al.setText("Tracking Number is Empty!")
al.setWindowTitle("Warning!")
al.show()
elif self.formatPL(tmp) == False:
al.setText("Tracking Number Format is Invalid!")
al.setWindowTitle("Warning!")
al.show()
else:
if (requests.get("https://sendparcel.poslaju.com.my/open/trace")).status_code == 200:
# Clear Table
for i in reversed(range(self.tblTracking.rowCount())):
self.tblTracking.removeRow(i)
self.StopSpam()
self.loadTracking()
else:
al.setText("Poslaju Server is Unreachable!")
al.setWindowTitle("Error!")
al.show()
app = QApplication(sys.argv)
win = PLTracker()
win.show()
sys.exit(app.exec_())