#NEWLINE# @ task ( run_every = timedelta ( days = 7 ) ) #NEWLINE# def import_data( self , **metadata ) : #NEWLINE# #INDENT# ( username , password ) = ( archive . _username , self . _password ) #NEWLINE# self . _source = self . _get_source ( ) #NEWLINE# self . _entity_types = self . _get_entity_types ( ) #NEWLINE# archive = zipfile . ZipFile ( StringIO ( urllib . urlopen ( self . HTTP_NTPG_URL ) . read ( ) ) ) #NEWLINE# f = StringIO ( archive . read ( 'Localities.csv' ) ) #NEWLINE# falt = StringIO ( archive . read ( 'LocalityAlternativeNames.csv' ) ) #NEWLINE# localities = self . _get_nptg_alt_names ( falt , self . _get_nptg ( f ) ) #NEWLINE# with tempfile . TemporaryFile ( ) as temp : #NEWLINE# #INDENT# temp . write ( urllib . urlopen ( self . HTTP_URL ) . read ( ) ) #NEWLINE# archive = zipfile . ZipFile ( temp ) #NEWLINE# if hasattr ( archive , 'open' ) : #NEWLINE# #INDENT# f = archive . open ( 'NaPTAN.xml' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f = StringIO ( archive . read ( 'NaPTAN.xml' ) ) #NEWLINE# #UNINDENT# self . _import_from_pipe ( f , localities , areas = self . _areas ) #NEWLINE# archive . close ( )