コード例 #1
0
class NaptanImporter(object):
    """
    Imports points of interest from the UK's National Public Transport Access Node dataset
    """

    IMPORTER_NAME = 'naptan'
    IMPORT_SCHEDULE = schedule(run_every=timedelta(weeks=1))

    HTTP_HOST = "www.dft.gov.uk"
    REMOTE_PATH = "/NaPTAN/snapshot/NaPTANxml.zip"

    def __init__(self, config):
        self._http_connection = httplib.HTTPConnection(self.HTTP_HOST)
        self._url = "http://%s%s" % (self.HTTP_HOST, self.REMOTE_PATH)
        self.parser = NaptanParser(config['codes'].split(','))

    def _get_file_from_url(self):
        temporary = TemporaryFile()
        self._http_connection.request('GET', self._url)
        temporary.write(self._http_connection.getresponse().read())
        return ZipFile(temporary).open('NaPTAN.xml')

    def load(self):
        for stop in self.parser.import_from_file(self._get_file_from_url(), self._url):
            self.poi_service.add_or_update(stop)
コード例 #2
0
 def __init__(self, config):
     self._http_connection = httplib.HTTPConnection(self.HTTP_HOST)
     self._url = "http://%s%s" % (self.HTTP_HOST, self.REMOTE_PATH)
     self.parser = NaptanParser(config['codes'].split(','))