예제 #1
0
    def test_capture_return_type(self, mocked_sleep):
        with open('crawlclima/redemet/tests/example_data.txt', 'r') as fd:
            response_text = fd.read()

        responses.add(responses.GET,
                      "https://www.redemet.aer.mil.br/api/consulta_automatica/"
                      "index.php?local=SBAF&msg=metar"
                      "&data_ini=2015022800&data_fim=2015022823",
                      body=response_text)

        station_code = 'SBAF'
        date = datetime(2015, 2, 28)
        data = capture(station_code, date)
        self.assertIsInstance(data, dict)
예제 #2
0
    def test_capture_return_type(self, mocked_sleep):
        with open('crawlclima/tests/test_data/test_example_data.json',
                  'r') as fd:
            response_text = fd.read()

        api_key = os.getenv('API_KEY')
        station_code = 'SBAF'
        date = datetime(2020, 6, 25)

        responses.add(
            responses.GET,
            'https://api-redemet.decea.gov.br/mensagens/metar/{}?'
            'api_key={}'
            '&data_ini=2020062500&data_fim=2020062523'.format(
                station_code, api_key),
            body=response_text,
        )

        data = capture(station_code, date)
        self.assertIsInstance(data, dict)
예제 #3
0
    def test_capture_return_type(self, mocked_sleep):
        with open(
            "crawlclima/redemet/tests/test_example_data.json", "r"
        ) as fd:
            response_text = fd.read()

        api_key = os.getenv("API_KEY")
        station_code = "SBAF"
        date = datetime(2020, 6, 25)

        responses.add(
            responses.GET,
            "https://api-redemet.decea.gov.br/mensagens/metar/{}?"
            "api_key={}"
            "&data_ini=2020062500&data_fim=2020062523".format(
                station_code, api_key
            ),
            body=response_text,
        )

        data = capture(station_code, date)
        self.assertIsInstance(data, dict)
예제 #4
0
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")
예제 #5
0
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')