Ejemplo n.º 1
0
def main():

    cache = Cache()

    for user in config.users:

        # Check that all information about the user is present
        try:
            name = user["name"]
            language = user["language"]
            email = user["email"]
            modules = user["modules"]
        except:
            print("Some keys missing")
            continue

        lang = Language(language)
        if lang.dictionary == {}:
            continue

        header = lang.getHeader(name)
        body = ""
        footer = lang.getFooter()

        # Date
        if "date" in modules:
            date = info.get_date()
            week = info.get_week()
            body += lang.getDate(str(date), str(week))

        # Birthdays
        if "birthdays" in modules:
            birthdays = info.get_birthdays(user["birthdayDBA"])
            birthday_string = lang.getBirthdays(birthdays)
            if birthday_string != "":
                body += birthday_string + "\n"

        # SOL information
        if "sol" in modules:
            try:
                places = user["sol"]
                sol_info = info.get_sol_info(places, cache)
                sol_string = lang.getSol(sol_info)
                if sol_string != "":
                    body += sol_string + "\n"
            except:
                print("Error with the SOL module")

        # Temperature information
        if "temperature" in modules:
            try:
                places = user["temperature"]
                temperature_info = info.get_temperatures(places, cache)
                temperature_string = lang.getTemperature(temperature_info)
                if temperature_string != "":
                    body += temperature_string + "\n"
            except:
                print("Error with the temperature")

        # Aurora information
        if "aurora" in modules:
            values = info.get_aurora_info(cache)
            body += lang.getAurora(values)

        # IP information
        if "ip" in modules:
            current_ip = info.getip()
            body += lang.getIp(current_ip)

        # Exchange information
        if "exchange" in modules:
            try:
                exchanges = user["exchange"]
                exchange_values = info.get_exchange_values(exchanges)
                exchange_string = lang.getExchange(exchange_values)
                body += exchange_string + "\n"
            except:
                print("Error with the exchange module")

        text = header + body + footer

        # Email
        filelist = [f for f in os.listdir(config.application_path) if f.endswith(".png")]
        mail.send_mail(email, lang.getSubject(info.get_date()), text, filelist)

        # Remove the graphs created in the exchange module
        if "exchange" in modules:
            for f in filelist:
                try:
                    os.remove(f)
                except:
                    pass