Beispiel #1
0
    def get_db_observation(date):
        key_name = make_key_name(site, date.date())
        if key_name in obs:
            return obs[key_name]

        o = ObservationDay.get_by_key_name(key_name)
        if o is None:
            o = ObservationDay(key_name=key_name)
            o.site = site
            o.observation_date = date.date()
            o.observations = Observations()

        obs[key_name] = o
        return o
Beispiel #2
0
def site_observations(site_id):
    site = Site.get_by_key_name(site_id)
    if site is None:
        return Response(status = 404)

    if request.args.has_key('day'):
        p = request.args.get('day')
        day = parse_yyyy_mm_dd_date(p)
    else:
        return Response("day query parameter is required",status = 400)

    observation_day = ObservationDay.get_by_key_name(make_key_name(site,day))

    if observation_day is None:
        return Response(status = 404)

    return json_response(observation_day)
Beispiel #3
0
def observation_import(site_id):
    site = Site.get_by_key_name(site_id)
    if site is None:
        return Response(status = 404)
    today = date.today()
    url = "http://metofficewatch.appspot.com/sites/%s/observations?day=%s" % (site_id, today.isoformat())

    result = urlfetch.fetch(url)

    if result.status_code == 200:
        obs = json.loads(result.content)
        obs_day = ObservationDay.get_by(site, today, not_found_return_new = True)
        obs_day.observations = Observations.from_json(obs['observations'])
        obs_day.lastdata_datetime = parse_date(obs['lastdata_datetime'])

        obs_day.save()

    return Response(status = 204)
Beispiel #4
0
    def get_db_observation(date):
        key_name = make_key_name(site, date.date())
        if key_name in obs:
            return obs[key_name]

        o = ObservationDay.get_by_key_name(key_name)
        if o is None:
            o = ObservationDay(key_name=key_name)
            o.site = site
            o.observation_date = date.date()
            o.observations = Observations()

        obs[key_name] = o
        return o