From 073f9c407ef47ab0f1ba55a976737fafe1c067dbe11ae47e6c108f992bb979da Mon Sep 17 00:00:00 2001 From: Vladislav Date: Thu, 23 Jul 2026 04:47:21 -0400 Subject: [PATCH] feat --- config.py | 2 +- main.ipynb | 27 ++++++--------------------- main.py | 27 ++++++--------------------- tasks.ipynb | 16 ++++++++-------- tasks.py | 16 ++++++++-------- 5 files changed, 29 insertions(+), 59 deletions(-) diff --git a/config.py b/config.py index b33fc00..52b7e28 100644 --- a/config.py +++ b/config.py @@ -7,7 +7,7 @@ ctx.load_verify_locations(cafile="certs.pem") PROD = os.getenv("PROD", "True").lower() != "false" - +SOCIALS = {'vk', 'tg', 'max', 'fb', 'inst'} ATOKEN = os.getenv("ATOKEN") MONGO_PASSWORD = os.getenv("MONGO_INITDB_ROOT_PASSWORD") MONGODB_HOST = os.getenv("MONGODB_SERVICE_HOST") diff --git a/main.ipynb b/main.ipynb index 1c9a33d..c3a9173 100644 --- a/main.ipynb +++ b/main.ipynb @@ -621,7 +621,8 @@ " text=\"Ваши картины на выставке\",\n", " )\n", " )\n", - " asyncio.gather(*tasks)\n", + " if tasks:\n", + " asyncio.gather(*tasks)\n", " # 2) Otherwise find an exhibition that should start soon -> move deliveries to \"На выставке\"\n", " exhibition_to_start = await exhibition_collection.find_one_and_update(\n", " {**prod_filter, \"status\": 0, \"datetime_start\": {\"$lt\": limit_dt}},\n", @@ -3080,11 +3081,7 @@ " \"medias\": post_medias or [],\n", " \"medias_original\": post_medias or [],\n", " \"user\": display_user(current_user),\n", - " \"vk\": [],\n", - " \"max\": [],\n", - " \"tg\": [],\n", - " \"fb\": [],\n", - " \"inst\": []\n", + " **{i:[] for i in SOCIALS},\n", " }\n", " \n", " res = await posts_collection.insert_one(doc)\n", @@ -3221,11 +3218,7 @@ " \"media\": post_medias,\n", " \"media_original\": post_medias,\n", " \"user\": display_user(current_user),\n", - " \"vk\": [],\n", - " \"max\": [],\n", - " \"tg\": [],\n", - " \"fb\": [],\n", - " \"inst\": []\n", + " **{i:[] for i in SOCIALS},\n", " }\n", "\n", " res = await news_collection.insert_one(doc)\n", @@ -3370,11 +3363,7 @@ " \"user\": display_user(current_user),\n", " \"min_paintings\": payload.min_paintings,\n", " \"max_paintings\": payload.max_paintings,\n", - " \"vk\": [],\n", - " \"max\": [],\n", - " \"tg\": [],\n", - " \"fb\": [],\n", - " \"inst\": [],\n", + " **{i:[] for i in SOCIALS},\n", " }\n", "\n", " res = await competitions_col.insert_one(doc)\n", @@ -3587,11 +3576,7 @@ " \"prod\": PROD,\n", " \"user\": display_user(current_user),\n", " \"posts\": [],\n", - " \"vk\": [],\n", - " \"max\": [],\n", - " \"tg\": [],\n", - " \"fb\": [],\n", - " \"inst\": []\n", + " **{i:[] for i in SOCIALS},\n", " }\n", " \n", " res = await exhibition_collection.insert_one(doc)\n", diff --git a/main.py b/main.py index e95e8c9..5a2b45c 100644 --- a/main.py +++ b/main.py @@ -425,7 +425,8 @@ async def cron_every_five_min(token: str = Security(get_token)): text="Ваши картины на выставке", ) ) - asyncio.gather(*tasks) + if tasks: + asyncio.gather(*tasks) # 2) Otherwise find an exhibition that should start soon -> move deliveries to "На выставке" exhibition_to_start = await exhibition_collection.find_one_and_update( {**prod_filter, "status": 0, "datetime_start": {"$lt": limit_dt}}, @@ -2334,11 +2335,7 @@ async def post_painting( "medias": post_medias or [], "medias_original": post_medias or [], "user": display_user(current_user), - "vk": [], - "max": [], - "tg": [], - "fb": [], - "inst": [] + **{i:[] for i in SOCIALS}, } res = await posts_collection.insert_one(doc) @@ -2454,11 +2451,7 @@ async def post_news( "media": post_medias, "media_original": post_medias, "user": display_user(current_user), - "vk": [], - "max": [], - "tg": [], - "fb": [], - "inst": [] + **{i:[] for i in SOCIALS}, } res = await news_collection.insert_one(doc) @@ -2575,11 +2568,7 @@ async def post_competition( "user": display_user(current_user), "min_paintings": payload.min_paintings, "max_paintings": payload.max_paintings, - "vk": [], - "max": [], - "tg": [], - "fb": [], - "inst": [], + **{i:[] for i in SOCIALS}, } res = await competitions_col.insert_one(doc) @@ -2763,11 +2752,7 @@ async def post_exhibition( "prod": PROD, "user": display_user(current_user), "posts": [], - "vk": [], - "max": [], - "tg": [], - "fb": [], - "inst": [] + **{i:[] for i in SOCIALS}, } res = await exhibition_collection.insert_one(doc) diff --git a/tasks.ipynb b/tasks.ipynb index e806014..69b04ce 100644 --- a/tasks.ipynb +++ b/tasks.ipynb @@ -430,11 +430,11 @@ "\n", " platforms = [\n", " ('tg', tg, lambda s: [\n", - " f\"{FULL_PATH_DOMAIN}/a/{exhibition['user']['_id']}\" if should_sign_avatar(exhibition, s) else None,\n", + " # f\"{FULL_PATH_DOMAIN}/a/{exhibition['user']['_id']}\" if should_sign_avatar(exhibition, s) else None,\n", " *[f\"{FULL_PATH_DOMAIN}/b/exhibition/{m}\" for m in medias]\n", " ]),\n", " ('vk', vk, lambda s: [\n", - " exhibition['user']['_id'] if should_sign_avatar(exhibition, s) else None,\n", + " # exhibition['user']['_id'] if should_sign_avatar(exhibition, s) else None,\n", " *medias\n", " ])\n", " ]\n", @@ -448,14 +448,14 @@ " text = parse_text_exhibition(exhibition)\n", " sign_avatar = should_sign_avatar(exhibition, social)\n", " attachments = [a for a in get_attachments(social) if a is not None]\n", - " redis_key = f\"nospamsends:{exhibition['_id']}:{social['_id']}\"\n", + " redis_key = f\"nospamsends:{platform_type}:{exhibition['_id']}:{social['_id']}\"\n", " already_sent = await redis_client.set(\n", " redis_key, \n", " 1, \n", " ex=8*60*60,\n", " nx=True\n", " )\n", - " print(f\"nospamsends:{exhibition['_id']}:{social['_id']}\")\n", + " print(f\"nospamsends:{platform_type}:{exhibition['_id']}:{social['_id']}\")\n", " if already_sent:\n", " print(social)\n", " client.notify.delay(post_ref, text, attachments, bson_clear(social), False)" @@ -484,11 +484,11 @@ "\n", " platforms = [\n", " ('tg', tg, lambda s: [\n", - " f\"{FULL_PATH_DOMAIN}/a/{competition['user']['_id']}\" if should_sign_avatar(competition, s) else None,\n", + " # f\"{FULL_PATH_DOMAIN}/a/{competition['user']['_id']}\" if should_sign_avatar(competition, s) else None,\n", " *[f\"{FULL_PATH_DOMAIN}/b/competition/{m}\" for m in medias]\n", " ]),\n", " ('vk', vk, lambda s: [\n", - " competition['user']['_id'] if should_sign_avatar(competition, s) else None,\n", + " # competition['user']['_id'] if should_sign_avatar(competition, s) else None,\n", " *medias\n", " ])\n", " ]\n", @@ -501,14 +501,14 @@ " text = parse_text_competition(competition)\n", " sign_avatar = should_sign_avatar(competition, social)\n", " attachments = [a for a in get_attachments(social) if a is not None]\n", - " redis_key = f\"nospamsends:{competition['_id']}:{social['_id']}\"\n", + " redis_key = f\"nospamsends:{platform_type}:{competition['_id']}:{social['_id']}\"\n", " already_sent = await redis_client.set(\n", " redis_key, \n", " 1, \n", " ex=8*60*60,\n", " nx=True\n", " )\n", - " print(f\"nospamsends:{competition['_id']}:{social['_id']}\")\n", + " print(f\"nospamsends:{platform_type}:{competition['_id']}:{social['_id']}\")\n", " if already_sent:\n", " print(social)\n", " client.notify.delay(post_ref, text, attachments, bson_clear(social), False)" diff --git a/tasks.py b/tasks.py index a7f1bdf..f3e2c97 100644 --- a/tasks.py +++ b/tasks.py @@ -328,11 +328,11 @@ async def service_social_exhibition(exhibition): platforms = [ ('tg', tg, lambda s: [ - f"{FULL_PATH_DOMAIN}/a/{exhibition['user']['_id']}" if should_sign_avatar(exhibition, s) else None, + # f"{FULL_PATH_DOMAIN}/a/{exhibition['user']['_id']}" if should_sign_avatar(exhibition, s) else None, *[f"{FULL_PATH_DOMAIN}/b/exhibition/{m}" for m in medias] ]), ('vk', vk, lambda s: [ - exhibition['user']['_id'] if should_sign_avatar(exhibition, s) else None, + # exhibition['user']['_id'] if should_sign_avatar(exhibition, s) else None, *medias ]) ] @@ -346,14 +346,14 @@ async def service_social_exhibition(exhibition): text = parse_text_exhibition(exhibition) sign_avatar = should_sign_avatar(exhibition, social) attachments = [a for a in get_attachments(social) if a is not None] - redis_key = f"nospamsends:{exhibition['_id']}:{social['_id']}" + redis_key = f"nospamsends:{platform_type}:{exhibition['_id']}:{social['_id']}" already_sent = await redis_client.set( redis_key, 1, ex=8*60*60, nx=True ) - print(f"nospamsends:{exhibition['_id']}:{social['_id']}") + print(f"nospamsends:{platform_type}:{exhibition['_id']}:{social['_id']}") if already_sent: print(social) client.notify.delay(post_ref, text, attachments, bson_clear(social), False) @@ -374,11 +374,11 @@ async def service_social_competition(competition, serviceSocial, userSocial, use platforms = [ ('tg', tg, lambda s: [ - f"{FULL_PATH_DOMAIN}/a/{competition['user']['_id']}" if should_sign_avatar(competition, s) else None, + # f"{FULL_PATH_DOMAIN}/a/{competition['user']['_id']}" if should_sign_avatar(competition, s) else None, *[f"{FULL_PATH_DOMAIN}/b/competition/{m}" for m in medias] ]), ('vk', vk, lambda s: [ - competition['user']['_id'] if should_sign_avatar(competition, s) else None, + # competition['user']['_id'] if should_sign_avatar(competition, s) else None, *medias ]) ] @@ -391,14 +391,14 @@ async def service_social_competition(competition, serviceSocial, userSocial, use text = parse_text_competition(competition) sign_avatar = should_sign_avatar(competition, social) attachments = [a for a in get_attachments(social) if a is not None] - redis_key = f"nospamsends:{competition['_id']}:{social['_id']}" + redis_key = f"nospamsends:{platform_type}:{competition['_id']}:{social['_id']}" already_sent = await redis_client.set( redis_key, 1, ex=8*60*60, nx=True ) - print(f"nospamsends:{competition['_id']}:{social['_id']}") + print(f"nospamsends:{platform_type}:{competition['_id']}:{social['_id']}") if already_sent: print(social) client.notify.delay(post_ref, text, attachments, bson_clear(social), False)