Skip to content

Commit

Permalink
make the linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Dec 26, 2023
1 parent 071ca81 commit cc4174f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
102 changes: 51 additions & 51 deletions frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import tempfile
import time
from datetime import datetime
from logging import basicConfig, getLogger
from logging import basicConfig
from secrets import token_hex

import iso8601
Expand Down Expand Up @@ -449,56 +449,56 @@ def content_live():
return resp


@app.route("/content/last")
def content_last():
assets = get_all_live_assets()
asset_by_id = dict((asset["id"], asset) for asset in assets)

last = {}

for room in CONFIG["ROOMS"]:
proofs = [
json.loads(data)
for data in r.zrange("last:{}".format(room["device_id"]), 0, -1)
]

last[room["name"]] = room_last = []
for proof in reversed(proofs):
asset = asset_by_id.get(proof["asset_id"])
if asset is None:
continue
room_last.append(
{
"id": proof["id"],
"user": asset["userdata"]["user"],
"filetype": asset["filetype"],
"shown": int(proof["ts"]),
"thumb": asset["thumb"],
"url": url_for("static", filename=cached_asset_name(asset)),
}
)
if len(room_last) > 10:
break

resp = jsonify(
last=[[room["name"], last.get(room["name"], [])] for room in CONFIG["ROOMS"]]
)
resp.headers["Cache-Control"] = "public, max-age=5"
return resp


@app.route("/proof", methods=["POST"])
def proof():
proofs = [(json.loads(row), row) for row in request.stream.read().split("\n")]
device_ids = set()
p = r.pipeline()
for proof, row in proofs:
p.zadd("last:{}".format(proof["device_id"]), row, proof["ts"])
device_ids.add(proof["device_id"])
for device_id in device_ids:
p.zremrangebyscore(f"last:{device_id}", 0, time.time() - 1200)
p.execute()
return "ok"
#@app.route("/content/last")
#def content_last():
# assets = get_all_live_assets()
# asset_by_id = dict((asset["id"], asset) for asset in assets)
#
# last = {}
#
# for room in CONFIG["ROOMS"]:
# proofs = [
# json.loads(data)
# for data in r.zrange("last:{}".format(room["device_id"]), 0, -1)
# ]
#
# last[room["name"]] = room_last = []
# for proof in reversed(proofs):
# asset = asset_by_id.get(proof["asset_id"])
# if asset is None:
# continue
# room_last.append(
# {
# "id": proof["id"],
# "user": asset["userdata"]["user"],
# "filetype": asset["filetype"],
# "shown": int(proof["ts"]),
# "thumb": asset["thumb"],
# "url": url_for("static", filename=cached_asset_name(asset)),
# }
# )
# if len(room_last) > 10:
# break
#
# resp = jsonify(
# last=[[room["name"], last.get(room["name"], [])] for room in CONFIG["ROOMS"]]
# )
# resp.headers["Cache-Control"] = "public, max-age=5"
# return resp
#
#
#@app.route("/proof", methods=["POST"])
#def proof():
# proofs = [(json.loads(row), row) for row in request.stream.read().split("\n")]
# device_ids = set()
# p = r.pipeline()
# for proof, row in proofs:
# p.zadd("last:{}".format(proof["device_id"]), row, proof["ts"])
# device_ids.add(proof["device_id"])
# for device_id in device_ids:
# p.zremrangebyscore(f"last:{device_id}", 0, time.time() - 1200)
# p.execute()
# return "ok"


@app.route("/robots.txt")
Expand Down
2 changes: 1 addition & 1 deletion redis_session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pickle

from flask import session, sessions
from flask import sessions
from redis import Redis

from helper import get_random
Expand Down
3 changes: 0 additions & 3 deletions syncer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from json import dumps as json_dumps
from logging import getLogger

from flask import url_for

from conf import CONFIG
from frontend import app
from helper import get_all_live_assets
from ib_hosted import ib

Expand Down

0 comments on commit cc4174f

Please sign in to comment.