Exemple #1
0
def callback():
    darwin_session = DarwinLdbSession(wsdl='https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2015-05-14', api_key = '6adcdf6a-2b06-40e0-8436-469c4468a679')
    crs_code = "HGY"
    board = darwin_session.get_station_board(crs_code)
    tex.delete(1.0, tk.END)
    s = "\nNext departures for %s" % (board.location_name)
    t = """
-------------------------------------------------------------------------------
|  PLAT  | DEST                                        |   SCHED   |    DUE   |
------------------------------------------------------------------------------- """
    tex.insert(tk.END, s + t)
    tex.see(tk.END)

    for service in board.train_services:
        u = ("| %6s | %43s | %9s | %8s |\n" %(service.platform or "", service.destination_text, service.std, service.etd))
                 # Scroll if necessary
        tex.insert(tk.END, u)
        tex.see(tk.END)
    v = "-------------------------------------------------------------------------------\n"
    tex.insert(tk.END, v)
    tex.see(tk.END)
    timey = time.asctime()
    tex.insert(tk.END, timey)
    
    top.after(1000, callback)
Exemple #2
0
def get_train_times(source, dest):
    log.log_message('trains: Getting session')
    session = DarwinLdbSession(wsdl=apis.darwin_api_url,
                               api_key=apis.darwin_api_key)

    log.log_message('trains: Getting train times: ' + source + ' -> ' + dest)
    result = session.get_station_board(source, destination_crs=dest)

    log.log_message('trains: Got times: ' + source + ' -> ' + dest)
    return result
Exemple #3
0
class RailDisplay:

    config = None
    service_count = 0
    journey_count = 0

    def __init__(self, config):
        self.config = config
        self.service_count = 0
        self.journey_count = 0
        self.darwin_session = DarwinLdbSession(wsdl=config["wsdl"], api_key=config["api_key"])
        self.board = None
        self.displays = []
        # Configure displays
        for display_config in config['displays']:
            # Skip if not enabled
            if display_config['enabled']:
                # Create and store instance
                class_name = display_config['class']
                display_module = __import__('RailDisplay.Display.%s' % class_name, fromlist=["RailDisplay.Display"])
                display_class = getattr(display_module, class_name)
                self.displays.append(display_class(config=display_config, rail=self))

    # Update the board
    def update_board(self):
        from_csr = self.config["journey"][self.journey_count]["departure_station"]
        to_csr = self.config["journey"][self.journey_count]["destination_station"]
        self.board = self.darwin_session.get_station_board(from_csr, 10, True, False, to_csr)
        print 'Updating Board'
        self.display_train(self.service_count)

    # Display train details on all configured displays
    def display_train(self, count):
        s = self.board.train_services[count]
        message = s.destination_text + " - " + s.std + " - " + s.etd
        for display in self.displays:
            display.display_message(message)
        # If the train is late, let the display alert
        if s.etd != 'On time':
            for display in self.displays:
                display.alert_late()
def HGY_dep_board():
    darwin_session = DarwinLdbSession(wsdl='https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2015-05-14', api_key = '6adcdf6a-2b06-40e0-8436-469c4468a679')

    crs_code = "HGY"

# retrieve departure board
    board = darwin_session.get_station_board(crs_code)

# print table header
    print("\nNext departures for %s" % (board.location_name))
    print("""
-------------------------------------------------------------------------------
|  PLAT  | DEST                                        |   SCHED   |    DUE   |
------------------------------------------------------------------------------- """)

# Loop through services
    for service in board.train_services:
        print("| %6s | %43s | %9s | %8s |" %(service.platform or "", service.destination_text, service.std, service.etd))

 #Print a footer 
    print("-------------------------------------------------------------------------------")
    def GetData():
        LiveTime.LastUpdate = datetime.now()
        services = []

        try:
            darwin_sesh = DarwinLdbSession(wsdl="https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx", api_key=Args.APIToken)
            board = darwin_sesh.get_station_board(Args.StationID)
            global StationName
            StationName = board.location_name

            for serviceC in board.train_services:
                if len(services) >= Args.NumberOfCards:
                    break
                service = darwin_sesh.get_service_details(serviceC.service_id)
                if (service.sta != None or service.std != None) and str(service.platform) not in Args.ExcludedPlatforms:
                    services.append(LiveTime(service, len(services) + 1, serviceC))

            return services
        except Exception as e:
            print("GetData() ERROR")
            print(str(e))
            return []
# Expects DARWIN_WEBSERVICE_API_KEY environment variable (you will need to sign up for an API key for OpenLDBWS)
# Expects DEPARTURE_CRS_CODE environment variable (e.g. "GTW" - the departure station that we're interested in)
# Expects DESTINATION_CRS_CODE environment variable (e.g. "BTN" - the destination station that we're interested in)
AvailableLEDCount = 8  # Total number of LEDs available; this should be 8 if you're using a Blinkt!

# Uses nre-darwin-py package (install with pip)
from nredarwin.webservice import DarwinLdbSession
from blinkt import set_all, set_pixel, set_clear_on_exit, show
from datetime import datetime, timedelta
import os
import syslog

DarwinSession = DarwinLdbSession(
    wsdl='https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx')
DepartureBoard = DarwinSession.get_station_board(
    os.environ["DEPARTURE_CRS_CODE"],
    destination_crs=os.environ["DESTINATION_CRS_CODE"])

# Initialise lists
ServiceStatus = []
Services = []
LEDs = [0] * AvailableLEDCount

# Populate ServiceStatus and Services.
# White=5=imminent/just left, Green=4=on time, yellow=3=late, blue=2=unspecified delay, red=1=cancelled, black=0=none
# We also check and deal with trains that wrap over midnight
CurrentYMD = datetime.now().strftime("%Y-%m-%d")
CurrentTime = datetime.now()
for service in DepartureBoard.train_services:
    ServiceStatus.append((service.std, service.etd))
    STD = datetime.strptime(CurrentYMD + service.std, '%Y-%m-%d%H:%M')
from nredarwin.webservice import DarwinLdbSession

# initiate a session
# this depends on the DARWIN_WEBSERVICE_API_KEY environment variable
# The WSDL environment variable also allows for
darwin_session = DarwinLdbSession(
    wsdl='https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx')
print("Enter 3 digit CRS code:")
try:
    input = raw_input  #python2 has raw_input, python3 has input
except NameError:
    pass
crs_code = input().upper()

# retrieve departure board
board = darwin_session.get_station_board(crs_code)

# print table header
print("\nNext departures for %s" % (board.location_name))
print("""
-------------------------------------------------------------------------------
|  PLAT  | DEST                                        |   SCHED   |    DUE   |
------------------------------------------------------------------------------- """
      )

# Loop through services
for service in board.train_services:
    print("| %6s | %43s | %9s | %8s |" %
          (service.platform
           or "", service.destination_text, service.std, service.etd))
from nredarwin.webservice import DarwinLdbSession

# initiate a session
# this depends on the DARWIN_WEBSERVICE_API_KEY environment variable
# The WSDL environment variable also allows for
darwin_session = DarwinLdbSession(wsdl='https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2015-05-14', api_key = '6adcdf6a-2b06-40e0-8436-469c4468a679')
print("Enter 3 digit CRS code:")
try:
    input = raw_input #python2 has raw_input, python3 has input
except NameError:
    pass
crs_code = input().upper()

# retrieve departure board
board = darwin_session.get_station_board(crs_code)

# print table header
print("\nNext departures for %s" % (board.location_name))
print("""
-------------------------------------------------------------------------------
|  PLAT  | DEST                                        |   SCHED   |    DUE   |
------------------------------------------------------------------------------- """)

# Loop through services
for service in board.train_services:
    print("| %6s | %43s | %9s | %8s |" %(service.platform or "", service.destination_text, service.std, service.etd))

# Print a footer 
print("-------------------------------------------------------------------------------")
Exemple #9
0
darwin_session = DarwinLdbSession(
    wsdl="https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx",
    api_key=nre_key)

path = os.getcwd()
tlc = os.path.basename(path).upper()
out = ""
message = ""


def setTimer():
    return 60 - (datetime.datetime.now().second +
                 datetime.datetime.now().microsecond * 0.000001)


board = darwin_session.get_station_board(tlc, rows=200)

print("This program will tweet departures from", board.location_name)

while True:
    try:
        #tlc = input("Input a three letter code: ").upper()
        board = darwin_session.get_station_board(tlc, rows=200)
        #print("This program will tweet departures from",board.location_name)
        while True:
            print(str(datetime.datetime.now()) + ": Still Alive")
            if (datetime.datetime.now().minute) % 5 == 0:
                if (datetime.datetime.now().second) == 0:
                    try:
                        if board != darwin_session.get_station_board(tlc):
                            break
Exemple #10
0
from nredarwin.webservice import DarwinLdbSession

darwin_sesh = DarwinLdbSession(wsdl="http://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx", api_key="c879e817-1c98-4aff-9e56-977025775c3b")

count = 0

board = darwin_sesh.get_station_board('GLC')

print(darwin_sesh.get_station_board('GLC'))



while count < 10:
    info = board.train_services[count]
    platforminfo = "Main Concorse"
    if info.platform == "16", "17":
        platforminfo = "Low Level Platform"
    print("Departure No ", count+1, info.std, " ", info.operator_name, " ",info.destination_text, "Platform: ",info.platform, platforminfo)

    service_id = board.train_services[count].service_id
    service = darwin_sesh.
    get_service_details(service_id)
    print ("This train will call at: ", [cp.location_name for cp in service.subsequent_calling_points])
    print ("")
    count  +=1 
print ("****** Additonal Service Information *****")
print (darwin_sesh.get_station_board('GLC').nrcc_messages)
print ("****** END *******")