1 #!/usr/bin/env -S python3 -Bu
2 # Someone's Mattermost scripts.
3 # Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
4 # published under MIT-License
6 # Run stats and post results to stats-channel(s).
17 def run_stats(prefix, module):
19 return prefix+module.main(dbconn)
21 return "``AUTODELETE-DAY`` Error in module: ``"+repr(module)+"``\n# :boom::boom::boom::boom::boom:\n```\n"+traceback.format_exc()+"\n```"
24 dbconn = psycopg2.connect(config.dbconnstring)
25 dbconn.set_session(autocommit=False, isolation_level=psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE, readonly=True)
27 mm = mattermost.MMApi(config.mm_api_url)
28 mm.login(config.mm_user, config.mm_user_pw)
31 [mm.create_post(config.stats_daily_channel_id, run_stats("``AUTODELETE-WEEK`` ", m)) for m in config.stats_daily]
34 if len(sys.argv) > 1 and sys.argv[1] == "week":
35 [mm.create_post(config.stats_weekly_channel_id, run_stats("``AUTODELETE-MONTH`` ", m)) for m in config.stats_weekly]