class Station: def __init__(self, name, sttype, extid = None, xcoord = None, ycoord = None, prodclass = None): self.name = name self.sttype = sttype self.extid = extid self.xcoord = float(xcoord)/1000000 self.ycoord = float(ycoord)/1000000 self.prodclass = prodclass def useId(self): return self.extid or self.name def lat(self): return self.ycoord def lon(self): return self.xcoord def json(self, indent = 0, name = True, extid = True, sttype = False, coords = False, prodclass = False, distance = False): out = " " * indent + "{\n" 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 "" 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): out = " " * indent + "\n" out += (" " * indent + " %s\n" % self.name) if name else "" out += (" " * indent + " %s\n" % self.useId()) if extid else "" out += (" " * indent + " %i\n" % int(self.distance)) if distance else "" out += (" " * indent + " %s\n" % self.sttype) if sttype else "" if coords: out += " " * indent + " \n" out += " " * indent + " %f\n" % self.xcoord out += " " * indent + " %f\n" % self.ycoord out += " " * indent + " \n" out += (" " * indent + " %s\n" % self.prodclass) if prodclass else "" out += " " * indent + "" return out class Service: def __init__(self, name, depst, deptime, arrst, arrtime, dest = None, deppf = None, currdep = None, arrpf = None, curarr = None): self.name = name self.dest = dest self.depst = depst self.deptime = deptime self.arrst = arrst self.arrtime = arrtime self.deppf = deppf self.currdep = currdep self.arrpf = arrpf self.curarr = curarr def duration(): return self.arrtime - self.deptime class Connection: def __init__(self, buyurl = None): 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 def duration(self): try: return self.services[-1].arrtime - self.services[0].deptime except: return None