logs-fixes

This commit is contained in:
tonyrewin 2022-11-22 09:20:01 +03:00
parent 8b0a5ed035
commit 11710218b9
3 changed files with 25 additions and 20 deletions

View File

@ -155,18 +155,17 @@ async def migrate(entry, storage):
r["deletedAt"] = date_parse(entry["deletedAt"]) r["deletedAt"] = date_parse(entry["deletedAt"])
# topics # topics
category = entry["category"] category = entry.get("category")
mainTopic = topics_by_oid.get(category) for oid in [category, ] + entry.get("tags", []):
if mainTopic: t = storage["topics"]["by_oid"].get(oid)
r["mainTopic"] = storage["replacements"].get(mainTopic["slug"], mainTopic["slug"]) if t:
topic_oids = [category, ] tslug = storage["topics"]["by_oid"][oid]["slug"]
topic_oids.extend(entry.get("tags", [])) r["topics"].add(tslug)
for oid in topic_oids:
if oid in storage["topics"]["by_oid"]:
r["topics"].add(storage["topics"]["by_oid"][oid]["slug"])
else:
print("[migration] unknown old topic id: " + oid)
r["topics"] = list(r["topics"]) r["topics"] = list(r["topics"])
# main topic
mt = topics_by_oid.get(category)
if mt and mt.get("slug"):
r["mainTopic"] = storage["replacements"].get(mt["slug"]) or r["topics"][0]
# add author as TopicFollower # add author as TopicFollower
with local_session() as session: with local_session() as session:
@ -187,8 +186,10 @@ async def migrate(entry, storage):
) )
session.add(tf) session.add(tf)
except IntegrityError: except IntegrityError:
print('[migration.shout] skipped by topic ' + tpc) print('[migration.shout] hidden by topic ' + tpc)
return r["visibility"] = "authors"
r["publishedAt"] = None
r["topics"].remove(tpc)
entry["topics"] = r["topics"] entry["topics"] = r["topics"]
entry["cover"] = r["cover"] entry["cover"] = r["cover"]
@ -196,7 +197,7 @@ async def migrate(entry, storage):
# body # body
r["body"], media = prepare_html_body(entry) r["body"], media = prepare_html_body(entry)
if media: if media:
r["media"] = json.dumps(media) r["media"] = json.dumps(media, ensure_ascii=True)
# save shout to db # save shout to db
s = object() s = object()
shout_dict = r.copy() shout_dict = r.copy()

View File

@ -596,6 +596,7 @@
"r-b": "rnb", "r-b": "rnb",
"rasizm": "racism", "rasizm": "racism",
"realizm": "realism", "realizm": "realism",
"redaktura": "editing",
"refleksiya": "reflection", "refleksiya": "reflection",
"reggi": "reggae", "reggi": "reggae",
"religion": "religion", "religion": "religion",

View File

@ -102,12 +102,15 @@ class ViewedStorage:
@staticmethod @staticmethod
async def init(): async def init():
if token:
self = ViewedStorage self = ViewedStorage
async with self.lock: async with self.lock:
self.client = create_client({ self.client = create_client({
"Authorization": "Bearer %s" % str(token) "Authorization": "Bearer %s" % str(token)
}, schema=schema_str) }, schema=schema_str)
print("[stat.viewed] authorized permanentely by ackee.discours.io: %s" % token) print("[stat.viewed] authorized permanentely by ackee.discours.io: %s" % token)
else:
print("[stat.viewed] please, set ACKEE_TOKEN")
@staticmethod @staticmethod
async def update(session): async def update(session):