예제 #1
0
파일: dollar.py 프로젝트: limiear/soyprice
def update_dollars_ratios():
    url = ("http://www.ambito.com/economia/mercados/monedas/dolar/"
           "x_dolar_get_grafico.asp?ric={:}&tipo={:}")
    begin = datetime(1984, 4, 12)
    dollar_vars = {
        "ARSB=": {
            "name": u"dollar/blue",
            "description": u"Dolar blue en Argentina",
            "reference": u"ARS/USD"
        },
        "ARSSCBCRA": {
            "name": u"dollar/bcra",
            "description": (u"Dolar del Banco Central de la Republica "
                            "Argentina"),
            "reference": u"ARS/USD"
        }
    }
    for k, v in dollar_vars.items():
        var = variable(**v)
        lapse = "ww" if var['changes'] else "yyyy"
        composed_url = url.format(k, lapse)
        dollars = map(
            lambda (d, v): (datetime.strptime(d, "%Y/%m/%d").date(), v),
            eval(GET(composed_url)))
        begin = get_next_date(var)
        update_prices(var, dollars, begin)
예제 #2
0
def update_bcra_reserves():
    url = "http://www.bcra.gov.ar/Estadisticas/estprv010001.asp"
    bcra_vars = {
        u"reserve": {
            u"name": u"reserve/bcra",
            u"description": u"Reservas en dolares del Banco Central de la República Argentina",
            u"reference": u"USD"
        }
    }
    variables = {k: variable(**v) for k, v in bcra_vars.items()}
    var = variables["reserve"]
    first_date = datetime(1996, 03, 02)
    data = {
        'desde': first_date.strftime("%d/%m/%Y"),
        'hasta': datetime.now().strftime("%d/%m/%Y"),
        'descri': 1,
        'I1.x': 40,
        'I1.y': 7,
        'I1': 'Enviar',
        'fecha': 'Fecha_Serie',
        'campo': 'Res_Int_BCRA'
    }
    page = beautifulsoup(POST(url, data))
    rows = page.select("#texto_columna_2 tr")
    data = map(lambda r: map(lambda c: c.text, r.select('td')), rows)
    data = data[1:]
    reserves = map(lambda d:
                   (datetime.strptime(d[0], "%d/%m/%Y").date(),
                    float(d[1]) * 1000000),
                   data)
    print reserves
    begin = get_next_date(var, first_date)
    print begin
    update_prices(var, reserves, begin)
    print "ready!"
예제 #3
0
def update_dollars_ratios():
    url = ("http://www.ambito.com/economia/mercados/monedas/dolar/"
           "x_dolar_get_grafico.asp?ric={:}&tipo={:}")
    begin = datetime(1984, 4, 12)
    dollar_vars = {
        "ARSB=": {
            "name": u"dollar/blue",
            "description": u"Dolar blue en Argentina",
            "reference": u"ARS/USD"
        },
        "ARSSCBCRA": {
            "name":
            u"dollar/bcra",
            "description": (u"Dolar del Banco Central de la Republica "
                            "Argentina"),
            "reference":
            u"ARS/USD"
        }
    }
    for k, v in dollar_vars.items():
        var = variable(**v)
        lapse = "ww" if var['changes'] else "yyyy"
        composed_url = url.format(k, lapse)
        dollars = map(
            lambda (d, v): (datetime.strptime(d, "%Y/%m/%d").date(), v),
            eval(GET(composed_url)))
        begin = get_next_date(var)
        update_prices(var, dollars, begin)
예제 #4
0
파일: crops.py 프로젝트: limiear/soyprice
def update_crops_bcr():
    bcr_variables = {
        u"Soja": {
            "name": u"soy/bcr",
            "description": u"Soja de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u"Trigo": {
            "name": u"wheat/bcr",
            "description": u"Trigo de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u"Sorgo": {
            "name": u"sorghum/bcr",
            "description": u"Sorgo de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u'Ma\xedz': {
            "name": u"corn/bcr",
            "description": u"Maiz de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u"Girasol": {
            "name": u"sunseed/bcr",
            "description": u"Girasol de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        }
    }
    variables = {k: variable(**v) for k, v in bcr_variables.items()}
    is_empty = len(variables["Soja"]['changes']) == 0
    if is_empty:
        datasets = glob('data/bcr/*.prices.xml')
        load_data = partial(load_bcr_dataset, variables=variables)
        map(load_data, datasets)
    url = 'http://www.bcr.com.ar/Pages/Granos/Cotizaciones/default.aspx'
    rows = get_page(url).select('.ms-vb tr')
    text = map(lambda r: [c.text for c in r.select('td')], rows)
    to_date = lambda d: datetime.strptime(d, '%d/%m/%Y').date()
    dts = map(to_date, text[0][2:])
    for line in text[2:]:
        var = variables[line[0]]
        begin = get_next_date(var)
        prices = map(lambda v: float(v) if is_float(v) else None, line[2:])
        prices = zip(dts, prices)
        update_prices(var, prices, begin)
예제 #5
0
def update_crops_bcr():
    bcr_variables = {
        u"Soja": {
            "name": u"soy/bcr",
            "description": u"Soja de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u"Trigo": {
            "name": u"wheat/bcr",
            "description": u"Trigo de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u"Sorgo": {
            "name": u"sorghum/bcr",
            "description": u"Sorgo de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u'Ma\xedz': {
            "name": u"corn/bcr",
            "description": u"Maiz de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        },
        u"Girasol": {
            "name": u"sunseed/bcr",
            "description": u"Girasol de la Bolsa de Comercio de Rosario (Arg)",
            "reference": u"ARS/tn"
        }
    }
    variables = {k: variable(**v) for k, v in bcr_variables.items()}
    is_empty = len(variables["Soja"]['changes']) == 0
    if is_empty:
        datasets = glob('data/bcr/*.prices.xml')
        load_data = partial(load_bcr_dataset, variables=variables)
        map(load_data, datasets)
    url = 'http://www.bcr.com.ar/Pages/Granos/Cotizaciones/default.aspx'
    rows = get_page(url).select('.ms-vb tr')
    text = map(lambda r: [c.text for c in r.select('td')], rows)
    to_date = lambda d: datetime.strptime(d, '%d/%m/%Y').date()
    dts = map(to_date, text[0][2:])
    for line in text[2:]:
        var = variables[line[0]]
        begin = get_next_date(var)
        prices = map(lambda v: float(v) if is_float(v) else None, line[2:])
        prices = zip(dts, prices)
        update_prices(var, prices, begin)
예제 #6
0
파일: crops.py 프로젝트: limiear/soyprice
def update_crops_chicago():
    chicago_variables = {
        u"soybean": {
            "name": u"soy/chicago",
            "description": u"Soja de la Bolsa de Chicago (USA)",
            "reference": u"USD/bushel"
        }
    }
    variables = {k: variable(**v) for k, v in chicago_variables.items()}
    url = "http://api.ieconomics.com/ie5/?s=s%201:com&span=1y&_="
    data = get_page(url).select('p')[0].text
    data = json.loads(data)[0]
    data = data['series'][0]['serie']['data']
    to_tuple = (lambda r:
                (datetime.strptime(r['x_dt'], "%Y-%m-%dT%H:%M:%S.%fZ").date(),
                 float(r['close'])))
    prices = map(to_tuple, data)
    for k, var in variables.items():
        begin = get_next_date(var)
        update_prices(var, prices, begin)
예제 #7
0
def update_crops_chicago():
    chicago_variables = {
        u"soybean": {
            "name": u"soy/chicago",
            "description": u"Soja de la Bolsa de Chicago (USA)",
            "reference": u"USD/bushel"
        }
    }
    variables = {k: variable(**v) for k, v in chicago_variables.items()}
    url = "http://api.ieconomics.com/ie5/?s=s%201:com&span=1y&_="
    data = get_page(url).select('p')[0].text
    data = json.loads(data)[0]
    data = data['series'][0]['serie']['data']
    to_tuple = (lambda r:
                (datetime.strptime(r['x_dt'], "%Y-%m-%dT%H:%M:%S.%fZ").date(),
                 float(r['close'])))
    prices = map(to_tuple, data)
    for k, var in variables.items():
        begin = get_next_date(var)
        update_prices(var, prices, begin)
예제 #8
0
def update_petroleum_wti_barrel_ratios():
    url = ("http://www.ambito.com/economia/mercados/petroleo/"
           "x_petroleo_get_grafico.asp?ric=1&"
           "timeFrom={:}&timeTo={:}&tipo=libre")
    begin = datetime(1984, 4, 12)
    end = datetime.now()
    petroleum_vars = {
        u"PETROLEUM": {
            u"name": u"petroleum/wti",
            u"description": u"Petroleo West Texas Intermediate",
            u"reference": u"USD/barrel"
        }
    }
    for k, v in petroleum_vars.items():
        var = variable(**v)
        begin = get_next_date(var, begin)
        p = lambda dt: dt.strftime("%d/%m/%Y")
        composed_url = url.format(p(begin), p(end))
        prices = map(
            lambda (d, v): (datetime.strptime(d, "%Y/%m/%d").date(), v),
            eval(GET(composed_url)))
        prices = filter(lambda p: p[0] >= begin.date(), prices)
        update_prices(var, prices, begin)
예제 #9
0
파일: crops.py 프로젝트: limiear/soyprice
def update_crops_afascl():
    afascl_variables = {
        u"Soja": {
            "name": u"soy/afascl",
            "description": u"Soja de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u"Trigo": {
            "name": u"wheat/afascl",
            "description": u"Trigo de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u"Sorgo": {
            "name": u"sorghum/afscl",
            "description": u"Sorgo de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u'Ma\xedz': {
            "name": u"corn/afascl",
            "description": u"Maiz de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u"Girasol": {
            "name": u"sunseed/afascl",
            "description": u"Girasol de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        }
    }
    variables = {k: variable(**v) for k, v in afascl_variables.items()}
    get_prices = partial(get_afascl_prices, variables=variables)
    dt = get_next_date(variables['Soja'], date(2007, 10, 1))
    while dt.date() <= date.today():
        for variable_id, price in get_prices(dt).items():
            change(value=price,
                   moment=dt.strftime('%Y-%m-%d'),
                   variable_id=variable_id)
        dt += timedelta(days=1)
예제 #10
0
def update_crops_afascl():
    afascl_variables = {
        u"Soja": {
            "name": u"soy/afascl",
            "description": u"Soja de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u"Trigo": {
            "name": u"wheat/afascl",
            "description": u"Trigo de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u"Sorgo": {
            "name": u"sorghum/afscl",
            "description": u"Sorgo de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u'Ma\xedz': {
            "name": u"corn/afascl",
            "description": u"Maiz de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        },
        u"Girasol": {
            "name": u"sunseed/afascl",
            "description": u"Girasol de la AFSCL de San Martin (Arg)",
            "reference": u"ARS/tn"
        }
    }
    variables = {k: variable(**v) for k, v in afascl_variables.items()}
    get_prices = partial(get_afascl_prices, variables=variables)
    dt = get_next_date(variables['Soja'], date(2007, 10, 1))
    while dt.date() <= date.today():
        for variable_id, price in get_prices(dt).items():
            change(value=price,
                   moment=dt.strftime('%Y-%m-%d'),
                   variable_id=variable_id)
        dt += timedelta(days=1)