コード例 #1
0
ファイル: test_utilities.py プロジェクト: cfax/tflbusarrival
def check_epoch_to_localtime_conversion_different_timezone(timezone):
    os.environ['TZ'] = timezone
    seconds = '1440000441000'  # 19/08/2015 17:07:21
    time_struct = Utilities.epoch_to_localtime(seconds)
    assert_equal(2015, time_struct.tm_year)
    assert_equal(8, time_struct.tm_mon)
    assert_equal(19, time_struct.tm_mday)
    assert_equal(17, time_struct.tm_hour)
    assert_equal(7, time_struct.tm_min)
    assert_equal(21, time_struct.tm_sec)
    assert_equal(2, time_struct.tm_wday)
    assert_equal(231, time_struct.tm_yday)
    assert_equal(1, time_struct.tm_isdst)
コード例 #2
0
ファイル: tfl_api.py プロジェクト: cfax/tflbusarrival
    def getBusList(self, stopcode_list):
        """Return list of busses stops (type: STBC) around the user's location"""

        return_list = [
            'StopPointName',
            'StopCode1',
            'LineName',
            'DestinationText',
            'EstimatedTime',
        ]

        stops = ','.join(stopcode_list)
        query = 'StopCode1={}'.format(stops) + \
                '&VisitNumber=1' + \
                '&ReturnList=' + ','.join(return_list)

        url = self.__base_url + query
        try:
            response = urlopen(url, data=None, timeout=10)
        except URLError:
            e.args = chain(e.args, ['Error retrieving list of busses'])
            raise

        timestamp = response.readline()
        result = response.readlines()

        busses = []
        for r in result:
            # Clean entry and split into a list
            r = r.rstrip().strip('[]').split(',')
            # Discard first element (always 1) and replace any leading/trailing double quotes
            r = [i.strip('"') for i in r[1:]]
            # Convert epoch time to readable format
            r = r[:-1] + [Utilities.epoch_to_localtime(r[-1])]
            busses.append(dict(zip(return_list, r)))

        return busses