Пример #1
0
    async def handle_last_week(self, request):
        day_timestamps = list(map(date_to_timestamp, last_days(7)))
        values = await self.redis.hmget(settings.REDIS_KEY_DAILY_RATES, *day_timestamps)

        data = {
            timestamp: json.loads(value.decode())
            for timestamp, value in zip(day_timestamps, values) if value
        }
        return json_response(data)
Пример #2
0
async def update_last_days(n):
    import json
    import settings
    from tools import date_to_timestamp

    redis = await aioredis.create_redis(settings.REDIS_HOST)

    pairs = []
    day_objects = last_days(n)
    for day in day_objects:
        pairs += [date_to_timestamp(day), json.dumps(get_nbrb_rates(day))]

    pprint(pairs)

    redis.hmset(settings.REDIS_KEY_DAILY_RATES, *pairs)