Exemplo n.º 1
0
def fetch_api():
    try:
        response_text = weather.fetch()
    except IOError:
        return {'error': 'server_unavailable'}
    try:
        weather_dict = weather.parse(response_text)
        weather_dict['date'] = tz.localize(datetime.strptime(weather_dict['date'], '%Y/%m/%d %H:%M:%S'))
        return weather_dict
    except Exception:
        return {'error': 'data_unavailable'}
Exemplo n.º 2
0
def fetch_api():
    try:
        response_text = weather.fetch()
    except IOError:
        return {'error': 'server_unavailable'}
    try:
        weather_dict = weather.parse(response_text)
        weather_dict['date'] = tz.localize(
            datetime.strptime(weather_dict['date'], '%Y/%m/%d %H:%M:%S'))
        return weather_dict
    except Exception:
        return {'error': 'data_unavailable'}
Exemplo n.º 3
0
def api(zip_code):
	if not zip_codes.is_listed(zip_code):
	    return json.dumps({"error":"Couldn't find zip code "+zip_code})+"\n",404
	city = " / ".join(zip_codes.city(zip_code))
	txt = weather.forecast_txt(zip_code)
	alerts,forecast,meta = weather.parse(txt)
	print(forecast)
	return jsonify(
	    city=city,
	    alerts=alerts,
	    forecast=[(day, "\u2014".join(text)) for day, text in forecast],
	    meta=meta
	)
Exemplo n.º 4
0
def curl(zip_code):
	if not zip_codes.is_listed(zip_code):
		return "Hm, I don't have zip code " + zip_code + "\n",404
	city = " / ".join(zip_codes.city(zip_code))
	txt = weather.forecast_txt(zip_code)
	alerts,forecast,meta = weather.parse(txt)
	print(forecast)
	return render_template(
		"forecast.txt",
		city=city,
		alerts=alerts,
		forecast=forecast,
		meta=meta
	)
Exemplo n.º 5
0
def forecast(zip_code):
	if not zip_codes.is_listed(zip_code):
		return render_template("wrong_zip.html", zip_code=zip_code),404
	city = " / ".join(zip_codes.city(zip_code))
	txt = weather.forecast_txt(zip_code)
	alerts,forecast,meta = weather.parse(txt)
	print(forecast)
	return render_template(
		"forecast.html",
		city=city,
		alerts=alerts,
		forecast=forecast,
		meta=meta
	)
Exemplo n.º 6
0
def test_parse():
	assert w.parse(test_data) == parsed