rDrama/files/helpers/cron.py

404 lines
14 KiB
Python
Raw Permalink Normal View History

[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
import time
2024-04-25 16:23:59 +00:00
import datetime
2023-02-25 19:18:40 +00:00
import os
2023-09-13 22:39:47 +00:00
import glob
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from sys import stdout
from shutil import make_archive
from hashlib import md5
from collections import Counter
2023-07-03 01:58:02 +00:00
from sqlalchemy.orm import load_only, InstrumentedAttribute
2023-08-31 10:09:12 +00:00
from sqlalchemy.sql import text
2024-02-10 15:34:45 +00:00
from sqlalchemy import or_
2023-02-25 19:18:40 +00:00
import click
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
import requests
2024-04-06 01:46:14 +00:00
from files.helpers.stats import *
2023-07-26 01:14:41 +00:00
from files.routes.front import frontlist
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.__main__ import cache
from files.classes import *
2024-02-10 15:34:45 +00:00
from files.helpers.alerts import *
from files.helpers.config.const import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.get import *
from files.helpers.lottery import check_if_end_lottery_task
from files.helpers.roulette import spin_roulette_wheel
2023-09-13 22:39:47 +00:00
from files.helpers.sanitize import filter_emojis_only, sanitize
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.useractions import *
2024-02-23 20:36:38 +00:00
from files.helpers.offsite_mentions import *
2024-02-16 20:42:42 +00:00
2023-03-16 06:27:58 +00:00
from files.cli import app, db_session, g
CRON_CACHE_TIMEOUT = 172800
2023-11-12 20:27:09 +00:00
def cron_fn(every_5m, every_1d, every_1mo):
with app.app_context():
g.db = db_session()
g.v = None
2022-07-21 18:11:04 +00:00
try:
if every_5m:
if FEATURES['GAMBLING']:
check_if_end_lottery_task()
g.db.commit()
2023-05-13 02:00:54 +00:00
spin_roulette_wheel()
g.db.commit()
_award_timers_task()
g.db.commit()
_unpin_expired()
g.db.commit()
2024-04-25 23:35:30 +00:00
if not IS_LOCALHOST and SITE_NAME == 'WPD':
reddit_mentions_task()
g.db.commit()
2024-02-16 20:42:42 +00:00
2024-04-25 23:35:30 +00:00
lemmy_mentions_task()
g.db.commit()
2023-09-05 21:57:46 +00:00
2024-04-25 23:35:30 +00:00
fourchan_mentions_task()
g.db.commit()
2024-02-23 16:19:18 +00:00
2024-04-25 23:35:30 +00:00
soyjak_mentions_task()
g.db.commit()
2024-02-23 20:15:21 +00:00
if every_1d or (not cache.get('stats') and not IS_LOCALHOST):
2023-10-20 16:23:01 +00:00
if IS_HOMOWEEN():
g.db.execute(text(
"INSERT INTO award_relationships (user_id, kind, created_utc) "
f"SELECT id, 'bite', {int(time.time())} FROM users "
"WHERE users.zombie < 0"))
g.db.commit()
_generate_emojis_zip()
g.db.commit()
2023-10-24 19:04:40 +00:00
if FEATURES['EMOJI_SUBMISSIONS']:
2023-08-03 03:29:01 +00:00
_generate_emojis_original_zip()
g.db.commit()
2023-08-03 03:29:01 +00:00
2023-10-07 17:55:50 +00:00
_hole_inactive_purge_task()
g.db.commit()
2023-08-05 11:18:14 +00:00
2024-04-06 01:46:14 +00:00
chart(kind='daily')
chart(kind='weekly')
g.db.commit()
2023-08-05 11:18:14 +00:00
2024-04-06 01:46:14 +00:00
cache.set('stats', stats(), timeout=CRON_CACHE_TIMEOUT)
g.db.commit()
2023-09-13 20:57:03 +00:00
2023-10-20 16:23:01 +00:00
_leaderboard_task()
g.db.commit()
2023-09-28 23:58:09 +00:00
2024-02-12 14:50:59 +00:00
if FEATURES['BLOCK_MUTE_EXILE_EXPIRY']:
_expire_blocks_mutes_exiles()
2024-02-12 12:10:46 +00:00
g.db.commit()
_set_top_poster_of_the_day_id()
g.db.commit()
2024-04-27 23:08:24 +00:00
_grant_one_year_badges()
g.db.commit()
_grant_two_year_badges()
g.db.commit()
if every_1mo:
_give_marseybux_salary()
g.db.commit()
except:
g.db.rollback()
2023-09-26 12:45:27 +00:00
raise
g.db.close()
del g.db
stdout.flush()
if IS_LOCALHOST:
print('Cron tasks Finished!', flush=True)
2023-07-22 17:11:07 +00:00
@app.cli.command('cron', help='Run scheduled tasks.')
@click.option('--every-5m', is_flag=True, help='Call every 5 minutes.')
@click.option('--every-1d', is_flag=True, help='Call every 1 day.')
@click.option('--every-1mo', is_flag=True, help='Call every 1 month.')
2023-09-20 17:52:39 +00:00
def cron(**kwargs):
cron_fn(**kwargs)
2023-09-13 22:39:47 +00:00
2023-08-31 10:09:12 +00:00
def _grant_one_year_badges():
2024-04-25 16:23:59 +00:00
today = datetime.datetime.today()
one_year_ago = datetime.datetime(today.year - 1, today.month, today.day + 1).timestamp()
2023-08-31 10:09:12 +00:00
notif_text = f"@AutoJanny has given you the following profile badge:\n\n{SITE_FULL_IMAGES}/i/{SITE_NAME}/badges/134.webp\n\n**1 Year Old 🥰**\n\nThis user has wasted an ENTIRE YEAR of their life here! Happy birthday!"
cid = notif_comment(notif_text)
_notif_query = text(f"""insert into notifications
select id, {cid}, false, extract(epoch from now())
from users where created_utc < {one_year_ago} and id not in (select user_id from badges where badge_id=134);""")
g.db.execute(_notif_query)
_badge_query = text(f"""insert into badges
select 134, id, null, null, extract(epoch from now())
from users where created_utc < {one_year_ago} and id not in (select user_id from badges where badge_id=134);""")
g.db.execute(_badge_query)
def _grant_two_year_badges():
2024-04-25 16:23:59 +00:00
today = datetime.datetime.today()
two_years_ago = datetime.datetime(today.year - 2, today.month, today.day + 1).timestamp()
2023-08-31 10:09:12 +00:00
notif_text = f"@AutoJanny has given you the following profile badge:\n\n{SITE_FULL_IMAGES}/i/{SITE_NAME}/badges/237.webp\n\n**2 Years Old 🥰🥰**\n\nThis user has wasted TWO WHOLE BUTT YEARS of their life here! Happy birthday!"
cid = notif_comment(notif_text)
_notif_query = text(f"""insert into notifications
select id, {cid}, false, extract(epoch from now())
from users where created_utc < {two_years_ago} and id not in (select user_id from badges where badge_id=237);""")
g.db.execute(_notif_query)
_badge_query = text(f"""insert into badges
select 237, id, null, null, extract(epoch from now())
from users where created_utc < {two_years_ago} and id not in (select user_id from badges where badge_id=237);""")
g.db.execute(_badge_query)
2023-10-07 17:55:50 +00:00
def _hole_inactive_purge_task():
if not HOLE_INACTIVITY_DELETION:
return False
one_week_ago = time.time() - 604800
2023-10-07 17:55:50 +00:00
active_holes = [x[0] for x in g.db.query(Post.hole).distinct() \
.filter(Post.hole != None, Post.created_utc > one_week_ago,
2024-02-18 15:29:53 +00:00
Post.draft == False, Post.is_banned == False,
2023-08-11 13:15:34 +00:00
Post.deleted_utc == 0)]
2024-02-24 18:33:17 +00:00
active_holes.extend(['changelog','countryclub','museumofrdrama','highrollerclub','test','truth']) # holes immune from deletion
2023-10-07 17:55:50 +00:00
dead_holes = g.db.query(Hole).filter(Hole.name.notin_(active_holes)).all()
names = [x.name for x in dead_holes]
for name in names:
2023-10-07 17:55:50 +00:00
first_mod_id = g.db.query(Mod.user_id).filter_by(hole=name).order_by(Mod.created_utc).first()
2022-08-24 20:30:31 +00:00
if first_mod_id:
first_mod = get_account(first_mod_id[0])
2022-08-24 20:30:31 +00:00
badge_grant(
user=first_mod,
badge_id=156,
2022-12-24 18:55:26 +00:00
description=f'Let a hole they owned die (/h/{name})'
2022-08-24 20:30:31 +00:00
)
2024-02-10 15:34:45 +00:00
text = f":marseyrave: /h/{name} has been deleted for inactivity after one week without new posts. All posts in it have been moved to the main feed :marseyrave:"
mod_ids = (x[0] for x in g.db.query(Mod.user_id).filter_by(hole=name))
extra_criteria = or_(User.hole_creation_notifs == True, User.id.in_(mod_ids))
alert_active_users(text, None, extra_criteria)
2023-10-07 17:55:50 +00:00
posts = g.db.query(Post).filter(Post.hole.in_(names)).all()
for post in posts:
2023-10-07 17:55:50 +00:00
if post.hole == 'programming':
post.hole = 'slackernews'
else:
2023-10-07 17:55:50 +00:00
post.hole = None
2022-11-18 19:58:12 +00:00
post.hole_pinned = None
2023-03-16 06:27:58 +00:00
g.db.add(post)
2024-02-10 15:34:45 +00:00
to_delete = g.db.query(Mod).filter(Mod.hole.in_(names)).all() \
2023-10-07 17:55:50 +00:00
+ g.db.query(Exile).filter(Exile.hole.in_(names)).all() \
+ g.db.query(HoleBlock).filter(HoleBlock.hole.in_(names)).all() \
+ g.db.query(StealthHoleUnblock).filter(StealthHoleUnblock.hole.in_(names)).all() \
+ g.db.query(HoleFollow).filter(HoleFollow.hole.in_(names)).all() \
+ g.db.query(HoleAction).filter(HoleAction.hole.in_(names)).all()
for x in to_delete:
2023-03-16 06:27:58 +00:00
g.db.delete(x)
g.db.flush() #Necessary, following deletion errors out otherwise
for x in dead_holes:
2023-03-16 06:27:58 +00:00
g.db.delete(x)
return True
def _generate_emojis_zip():
make_archive('files/assets/emojis', 'zip', 'files/assets/images/emojis')
m = md5()
with open('files/assets/emojis.zip', "rb") as f:
data = f.read()
m.update(data)
cache.set('emojis_hash', m.hexdigest(), timeout=CRON_CACHE_TIMEOUT)
2023-02-25 19:18:40 +00:00
2023-08-03 03:29:01 +00:00
def _generate_emojis_original_zip():
make_archive('files/assets/emojis_original', 'zip', '/asset_submissions/emojis/original')
def _leaderboard_task():
2024-04-20 14:47:09 +00:00
votes1 = g.db.query(Vote.user_id, func.count(Vote.user_id)).filter(Vote.vote_type == 1).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
votes2 = g.db.query(CommentVote.user_id, func.count(CommentVote.user_id)).filter(CommentVote.vote_type == 1).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
users14 = g.db.query(User).filter(User.id.in_(votes3.keys())).all()
users13 = []
for user in users14:
users13.append((user.id, votes3[user.id]-user.post_count-user.comment_count))
if not users13: users13 = [(None,None)]
users13 = sorted(users13, key=lambda x: x[1], reverse=True)
users13_1, users13_2 = zip(*users13[:25])
cache.set("users13", list(users13), timeout=CRON_CACHE_TIMEOUT)
cache.set("users13_1", list(users13_1), timeout=CRON_CACHE_TIMEOUT)
cache.set("users13_2", list(users13_2), timeout=CRON_CACHE_TIMEOUT)
2024-04-20 14:47:09 +00:00
votes1 = g.db.query(Post.author_id, func.count(Post.author_id)).join(Vote).filter(Vote.vote_type == -1).group_by(Post.author_id).order_by(func.count(Post.author_id).desc()).all()
votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote).filter(CommentVote.vote_type == -1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all()
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
users8 = g.db.query(User.id).filter(User.id.in_(votes3.keys())).all()
users9 = []
for user in users8:
users9.append((user.id, votes3[user.id]))
if not users9: users9 = [(None,None)]
users9 = sorted(users9, key=lambda x: x[1], reverse=True)
users9_1, users9_2 = zip(*users9[:25])
cache.set("users9", list(users9), timeout=CRON_CACHE_TIMEOUT)
cache.set("users9_1", list(users9_1), timeout=CRON_CACHE_TIMEOUT)
cache.set("users9_2", list(users9_2), timeout=CRON_CACHE_TIMEOUT)
2023-05-13 02:00:54 +00:00
def _process_timer(attr, badge_ids, text, extra_attrs={}):
now = time.time()
users = g.db.query(User).options(load_only(User.id)).filter(1 < attr, attr < now)
uids = set(x.id for x in users)
2023-05-13 02:00:54 +00:00
#set user attributes
2023-07-04 20:59:42 +00:00
attr = str(attr).split('.')[1]
2023-07-02 21:42:34 +00:00
for user in users:
2023-07-04 20:44:28 +00:00
setattr(user, attr, 0)
for k, val in extra_attrs.items():
2023-07-02 21:42:34 +00:00
k = str(k).split('.')[1]
2023-07-03 01:58:02 +00:00
if isinstance(val, InstrumentedAttribute):
val = str(val).split('.')[1]
val = getattr(user, val)
2023-07-02 21:42:34 +00:00
setattr(user, k, val)
2023-05-13 02:00:54 +00:00
#remove corresponding badges
if badge_ids:
g.db.query(Badge).options(load_only(Badge.badge_id)).filter(Badge.badge_id.in_(badge_ids), Badge.user_id.in_(uids)).delete()
#notify users
for uid in uids:
send_repeatable_notification(uid, text)
if attr == 'patron_utc':
verifiedrich_memberships = g.db.query(GroupMembership).filter(
GroupMembership.user_id.in_(uids),
GroupMembership.group_name == 'verifiedrich'
).all()
for membership in verifiedrich_memberships:
g.db.delete(membership)
2023-05-13 02:00:54 +00:00
def _award_timers_task():
#only awards
_process_timer(User.deflector, [], "The deflector award you received has expired!")
_process_timer(User.progressivestack, [94], "The progressive stack award you received has expired!")
_process_timer(User.bird, [95], "The bird site award you received has expired!")
_process_timer(User.longpost, [97], "The pizzashill award you received has expired!")
2023-10-13 19:04:45 +00:00
_process_timer(User.hieroglyphs, [98], "The hieroglyphs award you received has expired!")
2023-05-13 02:00:54 +00:00
_process_timer(User.rehab, [109], "The rehab award you received has expired!")
_process_timer(User.owoify, [167], "The OwOify award you received has expired!")
_process_timer(User.sharpen, [289], "The Sharpen award you received has expired!")
_process_timer(User.bite, [168], "The bite award you received has expired! You're now back in your original house!", {
2023-07-03 01:58:02 +00:00
User.house: User.old_house,
2023-05-13 02:00:54 +00:00
User.old_house: '',
})
2024-02-10 08:44:00 +00:00
if SITE_NAME != 'WPD':
_process_timer(User.earlylife, [169], "The earlylife award you received has expired!")
2023-05-13 02:00:54 +00:00
_process_timer(User.marsify, [170], "The marsify award you received has expired!")
_process_timer(User.rainbow, [171], "The rainbow award you received has expired!")
_process_timer(User.queen, [285], "The queen award you received has expired!")
_process_timer(User.spider, [179], "The spider award you received has expired!")
2023-10-28 12:24:28 +00:00
_process_timer(User.namechanged, [281], "The namelock/queen award you received has expired. You're now back to your old username!", {
User.username: User.prelock_username,
User.prelock_username: None,
})
2023-05-13 02:00:54 +00:00
#both awards and janny powers
_process_timer(User.unban_utc, [], "Your temporary ban has expired!", {
User.is_banned: None,
User.ban_reason: None,
})
_process_timer(User.patron_utc, [22,23,24,25,26,27,28], f"Your {patron} status has expired!", {
User.patron: 0,
2024-04-28 13:24:27 +00:00
User.sig: None,
User.sig_html: None,
User.extra_username: None,
User.keyword_notifs: None,
User.snappy_quotes: None,
2023-05-13 02:00:54 +00:00
})
2023-06-23 11:07:47 +00:00
_process_timer(User.chud, [58], "Your temporary chud status has expired!", {
User.chud_phrase: None,
2023-05-13 02:00:54 +00:00
User.chudded_by: None,
})
_process_timer(User.flairchanged, [96], "Your temporary flair-lock has expired. You can now change your flair!")
def _unpin_expired():
t = int(time.time())
pins = []
for cls in (Post, Comment):
2024-02-18 15:29:53 +00:00
pins += g.db.query(cls).options(load_only(cls.id)).filter(cls.pinned_utc < t)
for pin in pins:
2024-02-18 15:29:53 +00:00
pin.pinned = None
pin.pinned_utc = None
g.db.add(pin)
2023-12-04 13:20:19 +00:00
if isinstance(pin, Comment):
pin.unpin_parents()
if pins:
cache.delete_memoized(frontlist)
def _give_marseybux_salary():
for u in g.db.query(User).filter(User.admin_level > 0).all():
marseybux_salary = u.admin_level * 10000
2024-03-02 17:24:07 +00:00
u.pay_account('marseybux', marseybux_salary, "Janny salary")
send_repeatable_notification(u.id, f"You have received your monthly janny salary of {marseybux_salary} Marseybux!")
2024-02-12 12:10:46 +00:00
2024-02-12 14:50:59 +00:00
def _expire_blocks_mutes_exiles():
2024-02-13 19:36:35 +00:00
one_month_ago = time.time() - 2592000
2024-02-12 12:10:46 +00:00
blocks = g.db.query(UserBlock).filter(UserBlock.created_utc < one_month_ago)
for block in blocks:
send_repeatable_notification(block.user_id, f"Your block of @{block.target.username} has passed 1 month and expired!")
send_repeatable_notification(block.target_id, f"@{block.user.username}'s block of you has passed 1 month and expired!")
g.db.delete(block)
mutes = g.db.query(UserMute).filter(UserMute.created_utc < one_month_ago)
for mute in mutes:
send_repeatable_notification(mute.user_id, f"Your mute of @{mute.target.username} has passed 1 month and expired!")
send_repeatable_notification(mute.target_id, f"@{mute.user.username}'s mute of you has passed 1 month and expired!")
g.db.delete(mute)
2024-02-12 14:50:59 +00:00
exiles = g.db.query(Exile).filter(Exile.created_utc < one_month_ago)
for exile in exiles:
send_repeatable_notification(exile.user_id, f"Your exile from /h/{exile.hole} has passed 1 month and expired!")
g.db.delete(exile)
def _set_top_poster_of_the_day_id():
t = int(time.time()) - 86400
db = db_session()
user = db.query(User, func.sum(Post.upvotes)).join(Post, Post.author_id == User.id).filter(
Post.created_utc > t,
User.admin_level == 0,
).group_by(User).order_by(func.sum(Post.upvotes).desc()).first()
2024-04-18 12:55:32 +00:00
if not user: return
user = user[0]
date = time.strftime("%B %d, %Y", time.gmtime())
2024-04-18 12:56:13 +00:00
send_notification(user.id, f":marseyjam: Congratulations! You're the Top Poster of the Day for {date}! :!marseyjam:")
badge_grant(badge_id=327, user=user)
cache.set("top_poster_of_the_day_id", user.id, timeout=86400)