Beispiel #1
0
def update_from_tepco():
    lastmod = Config.get_by_key_name('last-modified')
    lastmod = lastmod and lastmod.value

    data = tepco.from_web(lastmod)
    if not data:
        return ''
    Config(key_name='last-modified', value=data['lastmodstr']).put()

    usage_updated = data['usage-updated']
    capacity = data['capacity']
    capacity_updated = data['capacity-updated']
    year = data['year']
    month = data['month']
    day = data['day']

    for hour, (usage, saving) in data['usage'].iteritems():
        entryfor = utc_from_jst(datetime.datetime(year, month, day, hour))
        entry = Usage.all().filter('entryfor =', entryfor).get()
        if not entry:
            Usage(
                entryfor=entryfor,
                year=year,
                month=month,
                day=day,
                hour=hour,
                usage=usage,
                saving=saving,
                usage_updated=usage_updated,
                capacity=capacity,
                capacity_updated=capacity_updated,
            ).put()
    return ''
Beispiel #2
0
def update_from_tepco():
  lastmod = Config.get_by_key_name('last-modified')
  lastmod = lastmod and lastmod.value
  data = tepco.from_web(lastmod)
  if not data:
    return ''	# not yet updated
  Config(
    key_name='last-modified',
    value=data['lastmodstr']
  ).put()

  if data.has_key('quick'):
    Config(
      key_name='quick.txt',
      value=data['quick']
    ).put()

  # the image is updated hourly just after the hour.
  jst = jst_from_utc(data['usage-updated']) - datetime.timedelta(hours=1)
  jst = jst.replace(minute=0, second=0, microsecond=0)

  for hour, (usage, saving, forecast) in data['usage'].iteritems():
    entryfor = utc_from_jst(jst.replace(hour=hour))
    entry = Usage.all().filter('entryfor =', entryfor).get()
    if entry:
      entry.saving = saving
      entry.forecast = forecast
      if entry.usage != usage:
	entry.usage = usage
	entry.usage_updated = data['usage-updated']
      if entry.capacity != data['capacity']:
	entry.capacity = data['capacity']
	entry.capacity_updated = data['capacity-updated']
    else:
      entry = Usage(
	entryfor=entryfor,
	year=entryfor.year,
	month=jst.month,
	day=jst.day,
	hour=hour,
	saving=saving,
	forecast=forecast,
	usage=usage,
	usage_updated=data['usage-updated'],
	capacity=data['capacity'],
	capacity_updated=data['capacity-updated']
      )

    entry.capacity_peak_period = data['capacity-peak-period']
    entry.forecast_peak_usage = data['forecast-peak-usage']
    entry.forecast_peak_period = data['forecast-peak-period']
    entry.forecast_peak_updated = data['forecast-peak-updated']
    entry.put()
  memcache.flush_all()
  return ''
Beispiel #3
0
def update_from_tepco():
    lastmod = Config.get_by_key_name('last-modified')
    lastmod = lastmod and lastmod.value
    data = tepco.from_web(lastmod)
    if not data:
        return ''  # not yet updated
    Config(key_name='last-modified', value=data['lastmodstr']).put()

    if data.has_key('quick'):
        Config(key_name='quick.txt', value=data['quick']).put()

    # the image is updated hourly just after the hour.
    jst = jst_from_utc(data['usage-updated']) - datetime.timedelta(hours=1)
    jst = jst.replace(minute=0, second=0, microsecond=0)

    for hour, (usage, saving, forecast) in data['usage'].iteritems():
        entryfor = utc_from_jst(jst.replace(hour=hour))
        entry = Usage.all().filter('entryfor =', entryfor).get()
        if entry:
            entry.saving = saving
            entry.forecast = forecast
            if entry.usage != usage:
                entry.usage = usage
                entry.usage_updated = data['usage-updated']
            if entry.capacity != data['capacity']:
                entry.capacity = data['capacity']
                entry.capacity_updated = data['capacity-updated']
        else:
            entry = Usage(entryfor=entryfor,
                          year=entryfor.year,
                          month=jst.month,
                          day=jst.day,
                          hour=hour,
                          saving=saving,
                          forecast=forecast,
                          usage=usage,
                          usage_updated=data['usage-updated'],
                          capacity=data['capacity'],
                          capacity_updated=data['capacity-updated'])

        entry.capacity_peak_period = data['capacity-peak-period']
        entry.forecast_peak_usage = data['forecast-peak-usage']
        entry.forecast_peak_period = data['forecast-peak-period']
        entry.forecast_peak_updated = data['forecast-peak-updated']
        entry.put()
    memcache.flush_all()
    return ''
Beispiel #4
0
def update_from_tepco():
  lastmod = Config.get_by_key_name('last-modified')
  lastmod = lastmod and lastmod.value
  data = tepco.from_web(lastmod)
  if not data:
    return ''	# not yet updated
  Config(
    key_name='last-modified',
    value=data['lastmodstr']
  ).put()

  usage_updated = data['usage-updated']
  capacity = data['capacity']
  capacity_updated = data['capacity-updated']
  capacity_peak_period = data['capacity-peak-period']

  # the image is updated hourly just after the hour.
  jst = jst_from_utc(usage_updated) - datetime.timedelta(hours=1)
  jst = jst.replace(minute=0, second=0, microsecond=0)

  for hour, (usage, saving) in data['usage'].iteritems():
    entryfor = utc_from_jst(jst.replace(hour=hour))
    entry = Usage.all().filter('entryfor =', entryfor).get()
    if entry:
      if entry.usage != usage:
	entry.usage = usage
	entry.usage_updated = usage_updated
      entry.saving = saving
    else:
      entry = Usage(
	entryfor=entryfor,
	year=entryfor.year,
	month=jst.month,
	day=jst.day,
	hour=hour,
	usage=usage,
	saving=saving,
	usage_updated=usage_updated,
	capacity=capacity,
	capacity_updated=capacity_updated,
	capacity_peak_period=capacity_peak_period,
      )
    entry.put()
  memcache.delete('latest.json')
  return ''
Beispiel #5
0
def update_from_tepco():
  lastmod = Config.get_by_key_name('last-modified')
  lastmod = lastmod and lastmod.value

  data = tepco.from_web(lastmod)
  if not data:
    return ''
  Config(
    key_name='last-modified',
    value=data['lastmodstr']
  ).put()

  usage_updated = data['usage-updated']
  capacity = data['capacity']
  capacity_updated = data['capacity-updated']
  year = data['year']
  month = data['month']
  day = data['day']

  for hour, (usage, saving) in data['usage'].iteritems():
    entryfor = utc_from_jst(datetime.datetime(year, month, day, hour))
    entry = Usage.all().filter('entryfor =', entryfor).get()
    if not entry:
      Usage(
	entryfor=entryfor,
	year=year,
	month=month,
	day=day,
	hour=hour,
	usage=usage,
	saving=saving,
	usage_updated=usage_updated,
	capacity=capacity,
	capacity_updated=capacity_updated,
      ).put()
  return ''