2017-09-19 20:50:19 +00:00
|
|
|
class Station:
|
|
|
|
def __init__(self, name, sttype, extid = None, xcoord = None, ycoord = None, prodclass = None):
|
|
|
|
self.name = name
|
2017-09-21 12:48:05 +00:00
|
|
|
self.sttype = sttype
|
2017-09-19 20:50:19 +00:00
|
|
|
self.extid = extid
|
2017-09-21 19:55:32 +00:00
|
|
|
self.xcoord = float(xcoord)/1000000
|
|
|
|
self.ycoord = float(ycoord)/1000000
|
2017-09-19 20:50:19 +00:00
|
|
|
self.prodclass = prodclass
|
|
|
|
|
2017-09-21 12:48:05 +00:00
|
|
|
def useId(self):
|
|
|
|
return self.extid or self.name
|
|
|
|
|
2017-09-21 19:55:32 +00:00
|
|
|
def lat(self):
|
|
|
|
return self.ycoord
|
|
|
|
|
|
|
|
def lon(self):
|
|
|
|
return self.xcoord
|
|
|
|
|
2017-09-24 18:48:22 +00:00
|
|
|
def json(self, indent = 0, name = True, extid = True, sttype = False, coords = False, prodclass = False, distance = False):
|
|
|
|
out = " " * indent + "{\n"
|
2017-09-23 14:57:24 +00:00
|
|
|
|
2017-09-24 18:48:22 +00:00
|
|
|
out += (" " * indent + " \"name\": \"%s\",\n" % self.name) if name else ""
|
|
|
|
out += (" " * indent + " \"id\": \"%s\",\n" % self.useId()) if extid else ""
|
|
|
|
out += (" " * indent + " \"distance\": %i,\n" % int(self.distance)) if distance else ""
|
|
|
|
out += (" " * indent + " \"type\": \"%s\",\n" % self.sttype) if sttype else ""
|
2017-09-23 14:57:24 +00:00
|
|
|
|
2017-09-24 18:48:22 +00:00
|
|
|
if coords:
|
|
|
|
out += " " * indent + " \"coords\": {\n"
|
|
|
|
out += " " * indent + " \"lon\": %f,\n" % self.xcoord
|
|
|
|
out += " " * indent + " \"lat\": %f\n" % self.ycoord
|
|
|
|
out += " " * indent + " },\n"
|
|
|
|
|
|
|
|
out += (" " * indent + " \"prodclass\": \"%s\",\n" % self.prodclass) if prodclass else ""
|
|
|
|
|
|
|
|
out = "".join(out.rsplit(",", 1))
|
|
|
|
|
|
|
|
out += " " * indent + "}"
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
def xml(self, indent = 0, name = True, extid = True, sttype = False, coords = False, prodclass = False, distance = False):
|
2017-09-23 14:57:24 +00:00
|
|
|
out = " " * indent + "<station>\n"
|
2017-09-24 18:48:22 +00:00
|
|
|
|
2017-09-23 14:57:24 +00:00
|
|
|
out += (" " * indent + " <name>%s</name>\n" % self.name) if name else ""
|
|
|
|
out += (" " * indent + " <id>%s</id>\n" % self.useId()) if extid else ""
|
2017-09-24 18:48:22 +00:00
|
|
|
out += (" " * indent + " <distance>%i</distance>\n" % int(self.distance)) if distance else ""
|
2017-09-23 14:57:24 +00:00
|
|
|
out += (" " * indent + " <type>%s</type>\n" % self.sttype) if sttype else ""
|
|
|
|
|
|
|
|
if coords:
|
|
|
|
out += " " * indent + " <coords>\n"
|
|
|
|
out += " " * indent + " <lon>%f</lon>\n" % self.xcoord
|
|
|
|
out += " " * indent + " <lat>%f</lat>\n" % self.ycoord
|
|
|
|
out += " " * indent + " </coords>\n"
|
|
|
|
|
|
|
|
out += (" " * indent + " <prodclass>%s</prodclass>\n" % self.prodclass) if prodclass else ""
|
|
|
|
|
2017-09-24 18:48:22 +00:00
|
|
|
out += " " * indent + "</station>"
|
2017-09-23 14:57:24 +00:00
|
|
|
|
|
|
|
return out
|
|
|
|
|
2017-09-19 20:50:19 +00:00
|
|
|
class Service:
|
2017-09-22 15:25:26 +00:00
|
|
|
def __init__(self, name, depst, deptime, arrst, arrtime, dest = None, deppf = None, currdep = None, arrpf = None, curarr = None):
|
2017-09-19 20:50:19 +00:00
|
|
|
self.name = name
|
2017-09-22 15:25:26 +00:00
|
|
|
self.dest = dest
|
2017-09-19 20:50:19 +00:00
|
|
|
self.depst = depst
|
|
|
|
self.deptime = deptime
|
|
|
|
self.arrst = arrst
|
|
|
|
self.arrtime = arrtime
|
|
|
|
self.deppf = deppf
|
|
|
|
self.currdep = currdep
|
|
|
|
self.arrpf = arrpf
|
|
|
|
self.curarr = curarr
|
2017-09-22 15:25:26 +00:00
|
|
|
|
|
|
|
def duration():
|
|
|
|
return self.arrtime - self.deptime
|
2017-09-19 20:50:19 +00:00
|
|
|
|
|
|
|
class Connection:
|
2017-09-22 15:25:26 +00:00
|
|
|
def __init__(self, buyurl = None):
|
2017-09-19 20:50:19 +00:00
|
|
|
self.services = []
|
|
|
|
self.buyurl = buyurl
|
|
|
|
|
|
|
|
def addService(self, service):
|
|
|
|
self.services.append(service)
|
|
|
|
|
|
|
|
def depst(self):
|
|
|
|
try:
|
|
|
|
return self.services[0].depst
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def arrst(self):
|
|
|
|
try:
|
|
|
|
return self.services[-1].arrst
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def deptime(self):
|
|
|
|
try:
|
|
|
|
return self.services[0].deptime
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def arrtime(self):
|
|
|
|
try:
|
|
|
|
return self.services[-1].arrtime
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def currdep(self):
|
|
|
|
try:
|
|
|
|
return self.services[0].currdep
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def currarr(self):
|
|
|
|
try:
|
|
|
|
return self.services[-1].currarr
|
|
|
|
except:
|
|
|
|
return None
|
2017-09-22 15:25:26 +00:00
|
|
|
|
|
|
|
def duration(self):
|
|
|
|
try:
|
|
|
|
return self.services[-1].arrtime - self.services[0].deptime
|
|
|
|
except:
|
|
|
|
return None
|