def main(file, sensor, begin, end, radius, stats, db, table): # Parse time string into datetime object begin = datetime.strptime(begin, '%Y-%m-%j') end = datetime.strptime(end, '%Y-%m-%j') # Read coordinates and table names from text file with open(file) as src: reader = csv.reader(src) for line in reader: try: lon = float(line[0]) lat = float(line[1]) site = line[2] # Extract data dict_list_0 = ts_extract(lon=lon, lat=lat, sensor=sensor, start=begin, end=end, radius=radius, stats=stats) print('Extracted %d records from Google Eath Engine' % len(dict_list_0)) # Prepare list of dictories () dict_list_1 = relabel(dict_list_0, sensor) dict_list_2 = date_append(dict_list_1) # Write to db dictlist2sqlite(dict_list_2, site=site, sensor=sensor, db_src=db, table=table) except Exception as e: print('An error occured while extracting a site. %s' % e)
def test_insert(self): dictlist2sqlite(dict_list, 'testSite', 'LT5', db_name, 'unittesting') conn = sqlite3.connect(db_name) cur = conn.cursor() cur.execute("SELECT * FROM unittesting") rows = cur.fetchall() self.assertEqual(len(rows), 3)
def main(lon, lat, sensor, begin, end, radius, stats, db, table, site): # Parse time string into datetime object begin = datetime.strptime(begin, '%Y-%m-%j') end = datetime.strptime(end, '%Y-%m-%j') # Extract data dict_list_0 = ts_extract(lon=lon, lat=lat, sensor=sensor, start=begin, end=end, radius=radius, stats=stats) print('Extracted %d records from Google Eath Engine' % len(dict_list_0)) # Prepare list of dictories () dict_list_1 = relabel(dict_list_0, sensor) dict_list_2 = date_append(dict_list_1) # Write to db dictlist2sqlite(dict_list_2, site=site, sensor=sensor, db_src=db, table=table)