def populate_db(records): with db.ez_connection() as c: _populate_db(c, tmax_tbl, records)
def check_data(): ''' Returns True if it looks like the stations data have been installed ''' tbl = db.ez_connection()[tmax_tbl] return len(tbl) == 7501
def populate_db(records): with db.ez_connection() as c: _populate_db(c, tmax_tbl, records) def download_stations(): ''' @retval generates the individual data rows, as text ''' res = requests.get(tmax_file_url) return (x for x in res.text.split('\n') if x) def install_data(): lines = download_stations() records = (parse_line(line) for line in lines) populate_db(records) def check_data(): ''' Returns True if it looks like the stations data have been installed ''' tbl = db.ez_connection()[tmax_tbl] return len(tbl) == 7501 if __name__ == "__main__": install_data() if not check_data(): print("Got {0} records, expected {1}".format( len(db.ez_connection()[tmax_tbl]), 7501)) exit(1)