This commit is contained in:
parent
033a8b6534
commit
a43eaee8e0
|
@ -90,27 +90,33 @@ class ViewedStorage:
|
||||||
async def update_pages():
|
async def update_pages():
|
||||||
"""query all the pages from ackee sorted by views count"""
|
"""query all the pages from ackee sorted by views count"""
|
||||||
logger.info(" ⎧ updating ackee pages data ---")
|
logger.info(" ⎧ updating ackee pages data ---")
|
||||||
start = time.time()
|
try:
|
||||||
self = ViewedStorage
|
start = time.time()
|
||||||
if self.client:
|
self = ViewedStorage
|
||||||
self.pages = self.client.execute(load_pages)
|
if self.client:
|
||||||
domains = self.pages.get("domains", [])
|
# Use asyncio.run to execute asynchronous code in the main entry point
|
||||||
logger.debug(f" | domains: {domains}")
|
self.pages = await asyncio.to_thread(self.client.execute, load_pages)
|
||||||
for domain in domains:
|
domains = self.pages.get("domains", [])
|
||||||
pages = domain.get("statistics", {}).get("pages", [])
|
# logger.debug(f" | domains: {domains}")
|
||||||
if pages:
|
for domain in domains:
|
||||||
logger.debug(f" | pages: {pages}")
|
pages = domain.get("statistics", {}).get("pages", [])
|
||||||
shouts = {}
|
if pages:
|
||||||
for page in pages:
|
# logger.debug(f" | pages: {pages}")
|
||||||
p = page["value"].split("?")[0]
|
shouts = {}
|
||||||
slug = p.split("discours.io/")[-1]
|
for page in pages:
|
||||||
shouts[slug] = page["count"]
|
p = page["value"].split("?")[0]
|
||||||
for slug in shouts.keys():
|
slug = p.split("discours.io/")[-1]
|
||||||
await ViewedStorage.increment(slug, shouts[slug])
|
shouts[slug] = page["count"]
|
||||||
logger.info(" ⎪ %d pages collected " % len(shouts.keys()))
|
for slug in shouts.keys():
|
||||||
|
await ViewedStorage.increment(slug, shouts[slug])
|
||||||
|
logger.info(" ⎪ %d pages collected " % len(shouts.keys()))
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
logger.info(" ⎪ update_pages took %fs " % (end - start))
|
logger.info(" ⎪ update_pages took %fs " % (end - start))
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_facts():
|
async def get_facts():
|
||||||
|
@ -119,7 +125,7 @@ class ViewedStorage:
|
||||||
try:
|
try:
|
||||||
if self.client:
|
if self.client:
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
facts = self.client.execute(load_facts)
|
facts = await self.client.execute(load_facts)
|
||||||
except Exception as er:
|
except Exception as er:
|
||||||
logger.error(f" - get_facts error: {er}")
|
logger.error(f" - get_facts error: {er}")
|
||||||
return facts or []
|
return facts or []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user