Skip to content

Instantly share code, notes, and snippets.

@gtsatsis
Last active May 1, 2021 10:29
Show Gist options
  • Save gtsatsis/ac1c5687babc0ea0895eaab497c0c5e2 to your computer and use it in GitHub Desktop.
Save gtsatsis/ac1c5687babc0ea0895eaab497c0c5e2 to your computer and use it in GitHub Desktop.
This is a commandline application to track packages from courier.gr (made specifically for Windows, but should work with *NIX with a slight modification to L53).
import os
import time
import requests
from datetime import datetime
from bs4 import BeautifulSoup
tracking_number = input("Tracking Number? => ")
while True:
soup = BeautifulSoup(
requests.post(
"https://www.courier.gr/track/result/", {"tracknr": tracking_number}
).text,
"html.parser",
)
details = {
"id": BeautifulSoup(
soup.find("div", {"class": "id"}).contents[3].text, "html.parser"
),
"status": BeautifulSoup(
soup.find("div", {"class": "status"}).contents[3].text, "html.parser"
),
"send_from": BeautifulSoup(
soup.find("div", {"class": "send-from"}).contents[3].text, "html.parser"
),
"send_to": BeautifulSoup(
soup.find("div", {"class": "send-to"}).contents[3].text, "html.parser"
),
"station": BeautifulSoup(
soup.find("div", {"class": "station"}).contents[3].text, "html.parser"
),
"service": BeautifulSoup(
soup.find("div", {"class": "service"}).contents[3].text, "html.parser"
),
"items": BeautifulSoup(
soup.find("div", {"class": "items"}).contents[3].text, "html.parser"
),
"reference_1": BeautifulSoup(
soup.find("div", {"class": "reference.1"}).contents[3].text, "html.parser"
),
"current_action": BeautifulSoup(
soup.find("div", {"class": "track-result"}).prettify(), "html.parser"
)
.find("div", {"class": "action"})
.contents[0]
.replace("\n", "")
.replace(" ", ""),
}
os.system("cls") # Note toward *NIX users; Use `clear`!
print(
f"""
<--------------------------------------------------------->
Current Time: {datetime.now().strftime("%d/%m/%Y %H:%M:%S")}
Tracking Number: {details["id"]}
Current Status: {details["status"]}
Origin: {details["send_from"]}
Destination: {details["send_to"]}
Import Location: {details["station"]}
Items: {details["items"]}
Item Ref. 1: {details['reference_1']}
Current Action: {details['current_action']}
<--------------------------------------------------------->
"""
)
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment