-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
import logging | ||
import time | ||
import sys | ||
import time | ||
|
||
from israelrailapi.train_station import translate_station | ||
from israelrailapi.api import GetRoutesApi | ||
from api import GetRoutesApi | ||
from train_station import translate_station | ||
|
||
|
||
class TrainSchedule(object): | ||
def query(self, src_station, dst_station, start_date=None, start_hour=None): | ||
@staticmethod | ||
def query(src_station, dst_station, start_date=None, start_hour=None): | ||
src_station = translate_station(src_station) | ||
dst_station = translate_station(dst_station) | ||
if start_date is None: | ||
start_date = time.strftime("%Y-%m-%d") | ||
if start_hour is None: | ||
start_hour = "09:00" | ||
start_date = start_date.strip().replace('-', '').replace('/', '').replace('.', '') | ||
start_hour = start_hour.strip().replace(':', '') | ||
start_hour = start_hour.strip().replace(':', '').replace('-', '') | ||
start_hour = f"{start_hour[:2]}:{start_hour[2:]}" | ||
start_date = f"{start_date[:4]}-{start_date[4:6]}-{start_date[6:8]}" | ||
|
||
logging.info("Query: %s->%s (%s %s)" % (src_station, dst_station, | ||
start_date, start_hour)) | ||
result = GetRoutesApi().request(OId=src_station, TId=dst_station, | ||
Date=start_date, Hour=start_hour) | ||
result = GetRoutesApi().request(fromStation=src_station, toStation=dst_station, | ||
date=start_date, hour=start_hour) | ||
logging.info(result) | ||
return result | ||
|
||
|
||
if '__main__' == __name__: | ||
logging.basicConfig(level=logging.DEBUG) | ||
t = TrainSchedule() | ||
if len(sys.argv) >= 4: | ||
t.query(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) | ||
if len(sys.argv) == 5: | ||
q = t.query(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) | ||
print(q) | ||
else: | ||
print("Usage: %s <src> <dst> <YYYY-MM-DD> <hh:mm>" % (sys.argv[0], )) | ||
print("Usage: %s <src> <dst> <YYYY-MM-DD> <hh:mm>" % (sys.argv[0],)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters