def test_account_should_run_run_all(self): """Pass an id which should NOT run on the schedule. Should return true because of the RUN_ALL_ACTIVE_ACCOUNTS env Set RUN_ALL_ACTIVE_ACCOUNTS to true """ if not Schedule().run_all_active_accounts: print('RUN_ALL_ACTIVE_ACCOUNTS needs to be true for this test') return account_id = '497d2852-2a23-4b82-904f-c871bec0f062' self.assertTrue(Schedule().accountShouldRun(account_id))
def toSystem(self, immediate=False): schedulesInDB = self.databaseManager.temporDB.execute( 'SELECT * FROM `Schedule`').fetchall() for (name, jsonContent) in schedulesInDB: if name in self.schedules: if immediate: self.schedules[name].exit() self.schedules[name] = Schedule(self, self.outputQueue, json.loads(jsonContent)) else: self.schedules[name].update(json.loads(jsonContent)) else: self.schedules[name] = Schedule(self, self.outputQueue, json.loads(jsonContent))
def runProcessAccountAndBudgetCommander(account_id): """Run the account once the time is after 3am (local time) but only run once per day Run Budget Commander features after processing because they use the data from the download """ if not Schedule().accountShouldRun(account_id): return if Helpers().isActiveAccount(account_id): try: download.main(account_id) NotifyViaEmail(account_id).main() MonthlyStop(account_id) ControlSpend(account_id).main() except Exception as exception: Log("error", str(exception), traceback.format_exc(), account_id)
def main(): """Runs every hour via cron In turn: Once per night: - Processes accounts - Runs Budget Commander features (Email, Monthly Pause, Control Spend) Every hour: - Runs Emergency stop """ Log("info", "every_hour running", "Output to python_log table") account_ids = Schedule().getSyncedAccountIds() for account_id in account_ids: runProcessAccountAndBudgetCommander(account_id) runEmergencyStop(account_id)
from core.urls import URL from core import config from bs4 import BeautifulSoup import requests import json def get_grades(url: URL) -> dict[str, str]: """ Get a dictionary containing available classes and URLs to their schedule :return: dict with grades and URLs """ grades: dict[str, str] = dict() html = requests.get(str(url)).text soup = BeautifulSoup(html, 'html5lib') for a in soup.select(".sf-main-area .sf-iblock-card-area a"): grade = a.text.lower().removeprefix('класс ') grades[grade] = a['href'] return grades if __name__ == '__main__': folder = config['Folders']['saved_schedule'] grades = get_grades(URL(config['Website']['schedule_grades_path'])) with open(f"{folder}/grades.json", "w", encoding="utf8") as file: json.dump(grades, file, ensure_ascii=False) for grade, href in grades.items(): schedule: Schedule = Schedule.download(grade, URL(href)) print(schedule) schedule.save(folder)
def test_account_should_not_run(self): """Pass an id which should NOT run on the schedule. Should return false""" if Schedule().run_all_active_accounts: return account_id = '497d2852-2a23-4b82-904f-c871bec0f062' self.assertFalse(Schedule().accountShouldRun(account_id))
def test_account_should_run(self): """Pass an id which should run on the schedule. Should return true""" account_id = '0bafd106-696d-4bba-93a9-9e42ff62f55f' self.assertTrue(Schedule().accountShouldRun(account_id))
def test_get_synced_accounts(self): """There should always be at least one synced account returned""" self.assertTrue(len(Schedule().getSyncedAccountIds()) > 0)