Este script deve ser executado via cron, diariamente para lançar a tarefa de captura de dados de temperatura do Weather underground veja crontab para saber como executar este script """ import sys import os from datetime import datetime, timedelta sys.path.append(os.getcwd()) from crawlclima.tasks import fetch_redemet from utilities.models import find_all user_date = None if len(sys.argv) > 1: user_date = datetime.strptime(sys.argv[1], "%Y-%m-%d") today = datetime.today() if user_date is None else user_date year_start = datetime(datetime.today().year, 1, 1) yesterday = today - timedelta(1) rows = find_all(schema='Municipio', table='Estacao_wu') stations = [row['estacao_id'] for row in rows] day = year_start if today.isoweekday() == 5 else yesterday for station in stations: fetch_redemet.delay(station, day)
""" Este script captura series de clima do servidor da Weather Underground em um período determinado. Copyright 2014 by Flávio Codeço Coelho license: GPL v3 """ import argparse import time from datetime import datetime from crawlclima.redemet.rmet import capture, check_day, date_generator from utilities.models import find_all, save rows = find_all(schema="Municipio", table="Estacao_wu") codes = [row["estacao_id"] for row in rows] codes.append("all") # keyword to allow fetching from all stations 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",
""" Este script captura series de clima do servidor da Weather Underground em um período determinado. Copyright 2014 by Flávio Codeço Coelho license: GPL v3 """ import argparse from datetime import datetime import time from crawlclima.redemet.rmet import capture, date_generator, check_day from utilities.models import save, find_all rows = find_all(schema='Municipio', table='Estacao_wu') codes = [row['estacao_id'] for row in rows] codes.append('all') # keyword to allow fetching from all stations 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",