Add parcel module (currently only suppotr for DHL)
Needs documentation, extension, some redesign/separation of concern, and lxml
This commit is contained in:
parent
93bfab1d7b
commit
0cd3e266c3
@ -40,4 +40,4 @@ class ConfigFinder:
|
|||||||
if path:
|
if path:
|
||||||
runpy.run_path(path, run_name="i3pystatus._config")
|
runpy.run_path(path, run_name="i3pystatus._config")
|
||||||
else:
|
else:
|
||||||
raise ImportError("Didn't find a config module, tried\n {mods}".format(mods="\n".join(failed)))
|
raise ImportError("Didn't find a config module, tried\n * {mods}".format(mods="\n * ".join(failed)))
|
||||||
|
47
i3pystatus/parcel.py
Normal file
47
i3pystatus/parcel.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
import lxml.html
|
||||||
|
from lxml.cssselect import CSSSelector
|
||||||
|
|
||||||
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
class DHL:
|
||||||
|
URL="http://nolp.dhl.de/nextt-online-public/set_identcodes.do?lang=en&idc={idcode}"
|
||||||
|
def __init__(self, idcode):
|
||||||
|
self.idcode = idcode
|
||||||
|
self.url = self.URL.format(idcode=self.idcode)
|
||||||
|
|
||||||
|
self.progress_selector = CSSSelector(".greyprogressbar > span")
|
||||||
|
self.last_status_selector = CSSSelector(".events .eventList tr")
|
||||||
|
self.intrarow_status_selector = CSSSelector("td.status div")
|
||||||
|
|
||||||
|
def status(self):
|
||||||
|
ret = {}
|
||||||
|
with urlopen(self.url) as page:
|
||||||
|
page = lxml.html.fromstring(page.read())
|
||||||
|
ret["progress"] = self.progress_selector(page)[0].text.strip()
|
||||||
|
last_row = self.last_status_selector(page)[-1]
|
||||||
|
ret["status"] = self.intrarow_status_selector(last_row)[0].text.strip()
|
||||||
|
return ret
|
||||||
|
|
||||||
|
class ParcelTracker(IntervalModule):
|
||||||
|
settings = (
|
||||||
|
("instance", "Tracker instance"),
|
||||||
|
"format",
|
||||||
|
"name",
|
||||||
|
)
|
||||||
|
required = ("instance",)
|
||||||
|
|
||||||
|
format = "{name}:{progress}"
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
fdict = {
|
||||||
|
"name": self.name,
|
||||||
|
}
|
||||||
|
fdict.update(self.instance.status())
|
||||||
|
|
||||||
|
self.output = {
|
||||||
|
"full_text": self.format.format(**fdict).strip(),
|
||||||
|
"instance": self.name,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user