Itella tracking for parcel module
This commit is contained in:
parent
0c04ce466b
commit
926b0ba94c
@ -3,6 +3,7 @@ import webbrowser
|
||||
|
||||
import lxml.html
|
||||
from lxml.cssselect import CSSSelector
|
||||
from bs4 import BeautifulSoup as BS
|
||||
|
||||
from i3pystatus import IntervalModule
|
||||
from i3pystatus.core.util import internet, require
|
||||
@ -123,3 +124,54 @@ class ParcelTracker(IntervalModule):
|
||||
|
||||
def on_leftclick(self):
|
||||
webbrowser.open_new_tab(self.instance.get_url())
|
||||
|
||||
|
||||
class Itella(IntervalModule):
|
||||
|
||||
interval = 3600 # 1h
|
||||
|
||||
settings = (
|
||||
("lang", "fi, sv or en (default: fi)"),
|
||||
"name",
|
||||
"idcode",
|
||||
"format",
|
||||
"color",
|
||||
)
|
||||
required = ("idcode",)
|
||||
|
||||
color = "#FFFFFF"
|
||||
format = "{name}:{progress}"
|
||||
lang = "fi"
|
||||
name = ""
|
||||
|
||||
@require(internet)
|
||||
def run(self):
|
||||
try:
|
||||
page = BS(urlopen(
|
||||
"http://www.itella.fi/itemtracking/itella/search_by_shipment_id"
|
||||
"?lang={lang}&ShipmentId={s_id}".format(
|
||||
s_id=self.idcode, lang=self.lang)
|
||||
).read())
|
||||
events = page.find(id="shipment-event-table")
|
||||
newest = events.find(id="shipment-event-table-cell")
|
||||
status = newest.find(
|
||||
"div", {"class": "shipment-event-table-header"}
|
||||
).text.strip()
|
||||
time, location = [
|
||||
d.text.strip() for d in
|
||||
newest.find_all("span", {"class": "shipment-event-table-data"})
|
||||
][:2]
|
||||
progress = "{status} {time} {loc}".format(status=status, time=time, loc=location)
|
||||
|
||||
self.output = {
|
||||
"full_text": self.format.format(
|
||||
name=self.name,
|
||||
status=status,
|
||||
location=location,
|
||||
time=time,
|
||||
progress=progress,
|
||||
),
|
||||
"color": self.color
|
||||
}
|
||||
except Exception as e:
|
||||
self.output = {"full_text": str(e)}
|
||||
|
Loading…
Reference in New Issue
Block a user