def func_wrapper(script): """ :param script: :type script: """ my_diag = classes.Diagnostic(script=script) try: func() classes.LoggingDB().add_row_to_db(diagnostics=my_diag.make_dict(), passfail=1) except Exception as e: my_diag.traceback = e classes.LoggingDB().add_row_to_db(diagnostics=my_diag.make_dict(), passfail=0)
def init(): """Initializes databases, Reddit bot""" global hist_db, journal_db, log_db, r, soc_db, cont_db hist_db = classes.HistoryDB() journal_db = classes.JournalDB() log_db = classes.LoggingDB() r = praw.Reddit('bot1') soc_db = classes.SocMediaDB() cont_db = classes.ContestDB()
def init() -> None: """Initializes test databases for testing""" global test_hist_db, test_log_db, test_soc_db, test_jour_db, test_db_list, test_cont_db test_hist_db = classes.HistoryDB(path=test_db_path) test_log_db = classes.LoggingDB(path=test_db_path) test_soc_db = classes.SocMediaDB(path=test_db_path) test_jour_db = classes.JournalDB(path=test_db_path) test_cont_db = classes.ContestDB(path=test_db_path) test_db_list = [ test_hist_db, test_log_db, test_soc_db, test_jour_db, test_cont_db ]
def init(path: str = 'data/mapporn.db') -> None: """Initializes databases, Reddit bot :param path: database path :type path: str """ global hist_db, log_db, r, soc_db hist_db = classes.HistoryDB(path=path) log_db = classes.LoggingDB(path=path) soc_db = classes.SocMediaDB(path=path)
def main() -> None: """Main script: gets map and posts it to social media.""" soc_db = classes.SocMediaDB() log_db = classes.LoggingDB() popular_hour = 9 my_target_zone = get_target_hour(popular_hour) map_row: object = soc_db.get_one_map_row(target_zone=my_target_zone) map_row.post_to_social_media(script=str(os.path.basename(__file__))) soc_db.close() log_db.close()
def main(): '''Main Script''' hist_db = classes.HistoryDB() today_list = hist_db.get_rows_by_date(get_todays_date()) if len(today_list) == 0: my_diag = classes.Diagnostic(script=os.path.basename(__file__)) my_diag.table = 'historymaps' log_db = classes.LoggingDB() log_db.add_row_to_db(diagnostics=my_diag.make_dict(), passfail=1) log_db.close() exit() maprow = random.choice(today_list) maprow.post_to_social_media(script=os.path.basename(__file__))
'''Congratulations post for best map of the year.''' import classes import functions import os import praw # Todo: can this be done as part of the normal congratulations script, that way I don't have to maintain two scripts # Verify before running in case of accidental execution. # If this script is automated, this line will need to be deleted. input('Are you ready?') r = praw.Reddit('bot1') log_db = classes.LoggingDB() cont_db = classes.ContestDB() def get_raw_id() -> object: """Get the raw ID of the voting post. :return: PRAW Object :rtype: object """ votingpostdata = open('data/votingpostdata.txt', 'r') raw_id = (votingpostdata.read()) return r.submission(id=raw_id) def main():