This commit is contained in:
Vladislav 2026-07-23 04:47:21 -04:00
parent 88bf2ee3f6
commit 073f9c407e
5 changed files with 29 additions and 59 deletions

View File

@ -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")

View File

@ -621,6 +621,7 @@
" text=\"Ваши картины на выставке\",\n",
" )\n",
" )\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",
@ -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",

25
main.py
View File

@ -425,6 +425,7 @@ async def cron_every_five_min(token: str = Security(get_token)):
text="Ваши картины на выставке",
)
)
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(
@ -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)

View File

@ -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)"

View File

@ -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)