Exemplo n.º 1
0
 def exception_keyboard_interrupt(self):
     # what to do when the app is stopped
     write_log("Application Terminated.")
     print("")
     print("{start}Application Terminated.{end}".format(
         start=FirstCheck.colors.WARNING, end=FirstCheck.colors.ENDC))
     self.terminate_app = True
Exemplo n.º 2
0
    def info_text(self):
        write_log("Application Started.")

        print("{start}Application Started.{end}".format(
            start=FirstCheck.colors.WARNING, end=FirstCheck.colors.ENDC))
        print("Remember to check the log! -> " + ConfigReader.log_path)
        print("To Exit Press: ⌃C")
def send_mail():
    html = WebCrawler.crawler.fetch_finished_table()
    msg = MIMEMultipart('alternative')

    with open(ConfigReader.email_list_path) as elist:
        for email in elist:
            # Continue if it is a comment or no @ is in the 'email' (line)
            if email[0] == "#" or email == "\n" or "@" not in email:
                continue

            msg["From"] = ConfigReader.bot_email
            msg["To"] = email
            msg["Subject"] = "Vertretungsplan Info. " + WebCrawler.crawler.fetch_date(
            )

            part = MIMEText(html, 'html')
            msg.attach(part)

            server = smtplib.SMTP(ConfigReader.smtp_server,
                                  ConfigReader.smtp_server_port)
            server.starttls()
            server.login(ConfigReader.bot_email, ConfigReader.bot_password)
            server.sendmail(ConfigReader.bot_email, email, msg.as_string())

            # strip because there is a \n at the end
            write_log("Email successfully send to: " + email.rstrip())
Exemplo n.º 4
0
    def start_loop(self):
        while True:
            if self.check_the_information():
                write_log("Change Detected.", "Preceding to send emails.")
                SendMail.send_mail()
                self.update_prevtables()

            self.sleep_between_check()
Exemplo n.º 5
0
    def fetch_tables(self):
        # fetches the website
        write_log("Checking for news...")

        fetch = WebCrawler.crawler.fetch_table_content()
        self.table1 = str(fetch[0])
        self.table2 = str(fetch[1])
        return self.table1, self.table2
Exemplo n.º 6
0
    def exception_everything_else(self, exception):
        # if an error occures its being written down in the log
        write_log(
            "An Error occurred:", exception, "The program will precede in " +
            str(ConfigReader.wait_between_error_retry) + " seconds.")

        try:
            self.sleep_between_error()
        except KeyboardInterrupt:
            self.exception_keyboard_interrupt()
Exemplo n.º 7
0
    def run_application(self):
        try:
            self.start_loop()

        except KeyboardInterrupt:
            self.exception_keyboard_interrupt()
            # So that self.run_application() isn't run afterwards
            return None

        except Exception as e:
            self.exception_everything_else(e)
            if self.terminate_app is True:
                return None
            write_log("The program is preceding now.")

        self.run_application()
Exemplo n.º 8
0
def do_the_check():
    # dictionary to store the booleans
    checks = {}

    print("Checking for {start}Connection Errors{end} and for possible {start}wrong login data{end}...".format(start=colors.OKGREEN, end=colors.ENDC))
    print("")

    checks["Internet Connection:" + "\t" * 3] = check_internet_connection()

    # If there is no connection every test will fail so this just returns False and informs the user:
    if check_internet_connection() is False:
        # Logs the Connection Error and informs about Checking the connection
        write_log("Initializing the connection and login data check:",
                  "-------------------------------------------------",
                  "Internet Connection: Error",
                  "-------------------------------------------------",
                  "Due to no internet connection all the other tests will come out wrong",
                  "So fix your Internet Connection!")

        print("Internet Connection: " + colors.FAIL + "Error!" + colors.ENDC)
        print("")
        print("{font}{underline}{color}Due to no internet connection all the other tests will come out wrong.{end}".format(font=colors.BOLD, underline=colors.UNDERLINE, color=colors.FAIL, end=colors.ENDC))
        print("{font}{color}{underline}So fix your Internet Connection!{end}".format(font=colors.BOLD, underline=colors.UNDERLINE, color=colors.FAIL, end=colors.ENDC))
        return False

    checks["Connection to the Elternportal Website:" + "\t" * 1] = check_response_code()
    checks["Login Data for Elternportal:" + "\t" * 2] = check_elternportal_logindata()
    checks["Login Data for the Bot email service:" + "\t" * 1] = check_bot_data()

    # Writes the first check in the log and replaces True with working and False with Error!
    keys = list(checks.keys())
    values = list(checks.values())
    write_log("Initializing the connection and login data check:",
              "-------------------------------------------------",
              keys[0] + str(values[0]).replace("True", "Working.").replace("False", "Error!"),
              keys[1] + str(values[1]).replace("True", "Working.").replace("False", "Error!"),
              keys[2] + str(values[2]).replace("True", "Working.").replace("False", "Error!"),
              keys[3] + str(values[3]).replace("True", "Working.").replace("False", "Error!"),
              "-------------------------------------------------",)

    for check in checks:
        print(check + str(checks[check]).replace("True", colors.OKBLUE + "Working." + colors.ENDC).replace("False", colors.FAIL + "Error!" + colors.ENDC))

    if False in checks.values():
        return False
    else:
        return True