def test_crossing_years(self): start = datetime(2015, 12, 31) end = datetime(2016, 1, 2) dates = [datetime(2015, 12, 31), datetime(2016, 1, 1)] generated_dates = list(date_generator(start, end)) self.assertEqual(generated_dates, dates)
def test_one_url(self): start = datetime(2015, 2, 28) dates = [ datetime(2015, 2, 28), ] generated_dates = list(date_generator(start)) self.assertEqual(generated_dates, dates)
def test_one_url(self): start = datetime(2015, 2, 28) dates = [ datetime(2015, 2, 28), ] generated_dates = list(date_generator(start)) self.assertEqual(generated_dates, dates)
def test_crossing_years(self): start = datetime(2015, 12, 31) end = datetime(2016, 1, 2) dates = [ datetime(2015, 12, 31), datetime(2016, 1, 1), ] generated_dates = list(date_generator(start, end)) self.assertEqual(generated_dates, dates)
def test_starting_from_a_bigger_date(self): start = datetime(2015, 12, 31) end = datetime(2015, 12, 28) dates = [ datetime(2015, 12, 31), datetime(2015, 12, 30), datetime(2015, 12, 29), ] generated_dates = list(date_generator(start, end)) self.assertEqual(generated_dates, dates)
def test_starting_from_a_bigger_date(self): start = datetime(2015, 12, 31) end = datetime(2015, 12, 28) dates = [ datetime(2015, 12, 31), datetime(2015, 12, 30), datetime(2015, 12, 29), ] generated_dates = list(date_generator(start, end)) self.assertEqual(generated_dates, dates)
def test_crossing_months(self): start = datetime(2015, 1, 30) end = datetime(2015, 2, 3) dates = [ datetime(2015, 1, 30), datetime(2015, 1, 31), datetime(2015, 2, 1), datetime(2015, 2, 2), ] generated_dates = list(date_generator(start, end)) self.assertEqual(generated_dates, dates)
def test_crossing_months(self): start = datetime(2015, 1, 30) end = datetime(2015, 2, 3) dates = [ datetime(2015, 1, 30), datetime(2015, 1, 31), datetime(2015, 2, 1), datetime(2015, 2, 2), ] generated_dates = list(date_generator(start, end)) self.assertEqual(generated_dates, dates)
parser.add_argument("--codigo", "-c", choices=codes, metavar="ICAO", help="Codigo da estação") args = parser.parse_args() station, start, end = args.codigo, args.inicio, args.fim data = [] i = 0 stations = codes if station == "all" else [station] for station in stations: if station == "all": continue for date in date_generator(start, end): if not check_day(date, station): print("Date {} has already been captured from station {} ".format( date, station)) continue print("Fetching data from {} at {}.".format(station, date)) res = capture(station, date) print(res) data.append(res) if i % 10 == 0: save(data, schema="Municipio", table="Clima_wu") data = [] time.sleep(1) save(data, schema="Municipio", table="Clima_wu")
date = lambda d: datetime.strptime(d, "%Y-%m-%d") parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--inicio", "-i", type=date, help="Data inicial de captura: yyyy-mm-dd") parser.add_argument("--fim", "-f", type=date, help="Data final de captura: yyyy-mm-dd") parser.add_argument("--codigo", "-c", choices=codes, metavar='ICAO', help="Codigo da estação" ) args = parser.parse_args() station, start, end = args.codigo, args.inicio, args.fim data = [] i = 0 stations = codes if station == 'all' else [station] for station in stations: if station == 'all': continue for date in date_generator(start, end): if not check_day(date, station): print("Date {} has already been captured from station {} ".format(date, station)) continue print("Fetching data from {} at {}.".format(station, date)) res = capture(station, date) print(res) data.append(res) if i % 10 == 0: save(data, schema='Municipio', table='Clima_wu') data = [] time.sleep(1) save(data, schema='Municipio', table='Clima_wu')