Example #1
0
 def start():
     if os.getenv("TEST_EMAIL"):
         logger.info("send test email to: {}".format(
             os.getenv("TEST_EMAIL")))
         send_email(
             os.getenv("TEST_EMAIL"),
             "scheduler test",
             "started a scheduler at {}".format(socket.gethostname()),
         )
     logger.info("Running pre-start initialization...")
     if bool(os.getenv("RESET_DB", False)):
         logger.info("removed {} tokens".format(
             mongo.RefreshTokens().remove({})))
         logger.info("removed {} users".format(mongo.Users().remove({})))
         logger.info("removed {} ack".format(mongo.Acknowlegments().remove(
             {})))
         logger.info("removed {} channels".format(mongo.Channels().remove(
             {})))
         logger.info("removed {} warehouses".format(
             mongo.Warehouses().remove({})))
         logger.info("removed {} orders".format(mongo.Orders().remove({})))
         logger.info("removed {} creator_tasks".format(
             mongo.CreatorTasks().remove({})))
         logger.info("removed {} writer_tasks".format(
             mongo.WriterTasks().remove({})))
     Initializer.create_database_indexes()
     Initializer.create_initial_data()
Example #2
0
def get_all_filings_settings_between_dates(start_date: date,
                                           end_date: date,
                                           county: str,
                                           showbrowser=bool) -> List[str]:
    """
    Gets all filings and settings between `start_date` and `end_date` but splits it up by week.

    Logs the weeks that failed.
    """

    weeks = split_into_weeks(start_date, end_date)
    logger.info(
        f"Will get all filings and settings between {start_date} and {end_date}\n"
    )

    failures: List[str] = []
    scraper = scrapers.SCRAPER_NAMES[county](headless=not showbrowser)
    for week_start, week_end in weeks:
        msg = try_to_parse(week_start, week_end, 5, scraper=scraper)
        if msg != "success":
            failures.append(msg)

    if failures:
        failures_str = "\n".join(failures)
        logger.info("All failures:")
        logger.info(Fore.RED + failures_str + Style.RESET_ALL)
        send_email(
            failures_str,
            "Date ranges for which parsing filings and settings failed")
    else:
        logger.info(Fore.GREEN +
                    "There were no failures when getting all filings " +
                    f"between {start_date} and {end_date} - yay!!" +
                    Style.RESET_ALL)
Example #3
0
    def run(self):
        # Starting main routing
        send_email('Starting fermenter at %gF' % self.target_temp)

        while True:
            self.regulate_and_record_temp()
            time.sleep(60)
Example #4
0
def get_all_filings_settings_since_date(start_date: str):
    """Gets all filings and settings since `start_date` but splits it up by week. Logs the weeks that failed."""

    yesterdays_date = (date.today() - timedelta(days=1)).strftime("%-m-%-d-%Y")
    weeks = split_into_weeks(start_date, yesterdays_date)
    logger.info(
        f"Will get all filings and settings between {start_date} and {yesterdays_date}\n"
    )

    failures = []
    for week_start, week_end in weeks:
        msg = try_to_parse(week_start, week_end, 5)
        if msg != "success":
            failures.append(msg)

    if failures:
        failures_str = "\n".join(failures)
        logger.info("All failures:")
        logger.info(Fore.RED + failures_str + Style.RESET_ALL)
        send_email(
            failures_str, "Date ranges for which parsing filings and settings failed"
        )
    else:
        logger.info(
            Fore.GREEN
            + f"There were no failures when getting all filings between {start_date} and {yesterdays_date} - yay!!"
            + Style.RESET_ALL
        )
def get_all_filings_settings_between_dates(start_date: str, end_date: str):
    """Gets all filings and settings between `start_date` and `end_date` but splits it up by week. Logs the weeks that failed."""

    weeks = split_into_weeks(start_date, end_date)
    logger.info(
        f"Will get all filings and settings between {start_date} and {end_date}\n"
    )

    failures = []
    for week_start, week_end in weeks:
        msg = try_to_parse(week_start, week_end, 5)
        if msg != "success":
            failures.append(msg)

    if failures:
        failures_str = "\n".join(failures)
        logger.info("All failures:")
        logger.info(Fore.RED + failures_str + Style.RESET_ALL)
        send_email(
            failures_str,
            "Date ranges for which parsing filings and settings failed")
    else:
        logger.info(
            Fore.GREEN +
            f"There were no failures when getting all filings between {start_date} and {end_date} - yay!!"
            + Style.RESET_ALL)
Example #6
0
def insert_command():
    this_barcode = SQLapp.search_barcodedata()[0][0]
    # for code in SQLapp.search_barcodedata():
    #     barcodes_left.append(code[0])
    # print(barcode_text.get())
    # print(barcodes_left[0])
    list1.delete(0, END)
    if len(name_text.get()) > 0 and len(title_text.get()) > 0:
        SQLapp.delete_data(this_barcode)
##        check if customer is from a school or not and add as needed
        if len(school_text.get()) ==0:
            SQLapp.insert_data(this_barcode, name_text.get().upper(), "NONE", title_text.get().upper())
            create_regletter(this_barcode)
            emailing.send_email(str(email_address_text.get()), this_barcode)
            for row in SQLapp.search_data(this_barcode, name_text.get(), title_text.get()):
                list1.insert(END, row)
        else:
            SQLapp.insert_data(this_barcode, name_text.get().upper(), school_text.get(), title_text.get().upper())
            create_regletter(this_barcode)
            emailing.send_email(str(email_address_text.get()), this_barcode)
            for row in SQLapp.search_data(this_barcode, name_text.get(), title_text.get()):
                list1.insert(END, row)
    else:
        window2 = Tk()
        window2.wm_title('ERROR')
        E1 = Label(window2, text="Please check your info")
        E1.grid(row=0, column=0)
    clear_entries()
Example #7
0
    def regulate_and_record_temp(self):
        target_temp = self.get_target_temp()
        if target_temp != self.target_temp:
            temps = tuple(['off' if t == 'off' else '%gF' % t for t in (self.target_temp, target_temp)])
            send_email('Changing temperature from %s to %s' % temps)
            self.target_temp = target_temp

        try:        # try grabbing the current temp
            current_temp = self.therm.read_temp()
            stat_str = '%.2f (%g)' % (current_temp, self.target_temp)
        except:     # send an email if you can't
            send_email("can't read the temperature")
            time.sleep(2)

        # deal with target_temp=off
        if self.target_temp == 'off':
            self.set_state('normal')
            if self.fridge.turn_off():
                stat_str += ' on->off'
            else:
                stat_str += ' off'
            print stat_str
            self.temp_history.add_temp(time.time(), current_temp, -1, self.fridge.is_on())
            return

        # regulate the temperature:
        if current_temp > self.target_temp + 1.0:
            if self.fridge.turn_on():
                stat_str += ' off->on'
                self.set_state('normal')
            else:
                stat_str += ' on'
                if current_temp > self.target_temp + 2.0:
                    stat_str += '\tWarning: High Temperatures'
                    self.set_state('high_temp')

        elif current_temp < self.target_temp - 0.05:
            if self.fridge.turn_off():
                stat_str += ' on->off'
                self.set_state('normal')
            else:
                stat_str += ' off'
                if current_temp < self.target_temp - 2.0:
                    stat_str += '\tWarning: Low Temperatures'
                    self.set_state('low_temp')

        else:
            if self.fridge.is_on():
                stat_str += ' on'
            else:
                stat_str += ' off'

        print stat_str
        self.temp_history.add_temp(time.time(), current_temp, self.target_temp, self.fridge.is_on())
Example #8
0
def email_results(tests, *, root_path):
    """
    Send an email with the results files
    """
    path_hash = run_one.get_path_hash(root_path)
    os.makedirs(path_hash)
    files = []
    for test in tests:
        prefix = path_hash + '_' + test
        shutil.copy2(prefix+'.zip', os.path.join(path_hash, test+'.zip'))
        shutil.copy2(prefix+'_build_run.html', os.path.join(path_hash, test+'_build_run.html'))
    files = glob.glob(os.path.join(path_hash, '*'))
    emailing.send_email(files, recipients=email_recipients, subject='Test results from path:'+root_path)
    shutil.rmtree(path_hash)
Example #9
0
    def process_task(self) -> None:
        self.file_path = os.path.join(config.DOWNLOAD_DIR, 'hgjbkn',
                                      str(self.id))
        try:
            self.download_file()
            hash_sum = self.get_hash()
        except Exception:
            hash_sum = ''
            traceback.print_exc()

        self.delete_file()

        model.write_result(self.id, hash_sum)
        if self.email:
            emailing.send_email(hash_sum, self.id, self.email)
Example #10
0
def endpoint_send_removal():
    data = request.get_json()
    sender = data['name']
    company_id = data['company']
    removal_list = data['removal_list']
    login_credentials = data['account']

    userid = dummy_user

    user = db.get_user_details(userid)
    target_email = db.get_company(company_id)['email']
    body = templates.removal_template(sender, target_email, user['legal-name'],
                                      removal_list, login_credentials)

    send_email(body, sender, target_email)
    db.save_email(userid, company_id, 'data-removal', body)
Example #11
0
def endpoint_send_followup():
    data = request.get_json()
    sender = data['name']
    company_id = data['company']
    login_credentials = data['account']

    userid = dummy_user

    user = db.get_user_details(userid)
    target_email = db.get_company(company_id)['email']
    previous_date = db.get_last_response(userid, company_id)['timestamp']
    previous_date = datetime.fromtimestamp(previous_date).strftime('%Y-%m-%d')
    body = templates.followup_template(sender, target_email,
                                       user['legal-name'], previous_date)

    send_email(body, sender, target_email)
    db.save_email(userid, company_id, 'followup', body)
Example #12
0
def run() -> None:
    while True:
        msg = main()
        if msg != None:
            print('\nSending Message')
            gen_pdf.usage_alert(listprocessor())
            subject = f"Error - {msg}"
            message = emailing.generate_error_report(subject)
            emailed = emailing.send_email(message)
            create_log(emailed)
            print(f'\n__Sended Email__[{time.ctime()}]')
            time.sleep(30)
            system('cls')
            print(f'\n....Running....[{time.ctime()}]')
Example #13
0
def send_paid_order_email(
    kind,
    email,
    name,
    timestamp,
    product,
    product_name,
    price,
    http_url=None,
    torrent_url=None,
    username=None,
    password=None,
    existing_account=False,
    expire_on=None,
    recurring=False,
):
    """Sends email receipt to customer. Calls `prepare_order`."""
    context = {
        "email": email,
        "name": name,
        "timestamp": timestamp,
        "product": product,
        "product_name": product_name,
        "price": price,
        "http_url": http_url,
        "torrent_url": torrent_url,
        "username": username,
        "password": password,
        "existing_account": existing_account,
        "expire_on": expire_on,
        "recurring": recurring,
    }
    subject = "Your Kiwix receipt"
    content = email_env.get_template(f"stripe/email_success_{kind}.html").render(
        **context
    )
    return send_email(
        to=email,
        subject=subject,
        contents=content,
        copy_support=False,
    )
Example #14
0
            # For debugging only
            # with open(os.path.dirname(__file__)+os.sep+"log.txt", "a+") as f:
            #     f.write(str(dt.datetime.now())+"\n")

            # process timing-related things
            # update whether it is new recording period
            if time.time(
            ) - _start_recording_period >= RECORDING_SESSION_DURATION_HOUR * 3600:
                _start_recording_period = int(
                    time.time() / RECORDING_SESSION_DURATION_HOUR /
                    3600) * RECORDING_SESSION_DURATION_HOUR * 3600
                _is_new_recording_period = True


if __name__ == "__main__":
    import traceback
    try:
        srm: SessionRecordingManager = SessionRecordingManager()
        srm.run()
    except Exception:
        logger.exception(
            "Try to catpure all exceptions when running session recording")
        from emailing import send_email
        receivers = ["*****@*****.**"]
        title = "[NO REPLY] Session Recording exited"
        content = "Please refer to the log file for more details!"
        send_email(receivers, title, content)
        try:
            srm.dispose()
        except:
            logger.exception("Session Recording manager dispose exception")
Example #15
0
    def plot_temp_history(
        self,
        start=None,
        stop=None,
        step=1,
        title=None,
        subject=None,
        event_times=None,
        event_labels=None,
        fpath=None,
        email=False,
    ):
        history = self[start:stop:step]
        target_temps = history[:, 2]
        bad_idxs = [i for i, tt in enumerate(target_temps) if tt == 0]
        history = np.delete(history, bad_idxs, axis=0)

        times = history[:, 0]
        temps = history[:, 1]
        target_temps = history[:, 2]
        fridge_states = history[:, 3]

        label_idxs = np.linspace(0, len(times) - 1, 4).astype(int)
        label_times = times[label_idxs]
        label_fmt = "%I:%M %p\n%m/%d/%y"
        labels = [time.strftime(label_fmt, time.localtime(t)) for t in label_times]

        state = fridge_states[0]
        on_temps, off_temps = [], []
        for t, fs in zip(temps, fridge_states):
            if fs != state:
                state = fs
                on_temps.append(t)
                off_temps.append(t)
            elif fs:
                on_temps.append(t)
                off_temps.append(None)
            else:
                off_temps.append(t)
                on_temps.append(None)

        fig, ax = plt.subplots(figsize=(10, 7))
        ax.plot(times, on_temps, color="b", linewidth=2, label="fridge on")
        ax.plot(times, off_temps, color="b", linewidth=0.60, label="fridge off")
        ax.plot(times, target_temps, "--", color="k", alpha=0.3, linewidth=0.40, label="target")
        if event_times is not None:
            if event_labels is None:
                event_labels = [None for ev in event_times]
            else:
                assert len(event_times) == len(event_labels)
            for ev, ev_label in zip(event_times, event_labels):
                ax.plot([ev, ev], ax.get_ylim(), "-.", alpha=0.5, linewidth=2, label=ev_label)

        ax.set_xticks(label_times)
        ax.set_xticklabels(labels)
        ax.set_xlabel("time")
        ax.set_ylabel("temperature (f)")
        ax.legend(loc="best", fancybox=True, prop={"size": 10})
        if title:
            title += "\n%s" % (format_time(times[-1] - times[0]))
        else:
            title = "%s" % (format_time(times[-1] - times[0]))
        ax.set_title(title)

        if fpath is None:
            fpath = os.path.splitext(self.filename)[0] + ".png"
        fig.savefig(fpath, bbox_inches="tight")

        if email:
            send_email("Temperature history.", attachment_fpath=fpath, subject=subject)

        return fpath
Example #16
0
                                    meta=dict(traffic_type=traffic_type))
    fig_30_days.update_layout(
        updatemenus=[dict(buttons=create_buttons(fig_30_days, button_label))],
        title='Daily Server-to-Cloud Traffic in the past 30 days',
        yaxis_title='Byte')
    # hide traces on initialization, by default all traces are shown
    fig_30_days.update_traces(visible=False)
    fig_30_days.update_traces(
        visible=True, selector=dict(meta={'traffic_type': button_label[0]}))

    # plot the interactive/sortable table

    # generate the html
    # https://stackoverflow.com/a/59869358/11659389
    file_timestamp = datetime.today()
    file_name = "traffic_report_" + file_timestamp.strftime(
        "%Y_%m_%d") + ".html"
    file_full_path = report_dir + "graphs" + os.sep + file_name
    with open(file_full_path, 'w') as f:
        f.write(fig_7_days.to_html(full_html=False, include_plotlyjs='cdn'))
        f.write(fig_30_days.to_html(full_html=False, include_plotlyjs='cdn'))

    # email
    receivers = [
        "*****@*****.**", "*****@*****.**",
        "*****@*****.**", "*****@*****.**"
    ]
    title = "[NO REPLY] Weekly Report of the Network Traffic of the TBS GPU Server"
    content = "Please open the .html file attached with a browser. For well loading the html file, an active internet connection is required."
    send_email(receivers, title, content, file_full_path)
Example #17
0
while True:
    try:
        browser.get(url)
        time.sleep(
            5)  # Make sure the website loads completely (javascript included)
        html = browser.page_source
        soup = BeautifulSoup(html, 'lxml')

        languages = soup.select('select[id=' + select + '] > option')

        if prev != languages:
            langsAvailable = 'Languages currently available:'
            for lang in languages[1:]:  # first option is usually disabled
                langsAvailable += '\n' + lang.text

            message = 'Hello! The language choice at our website has changed.\n\n' \
                + langsAvailable + '\n\nCreate an account: ' + url

            send_email(sender, password, receiver, subject, message)

            prev = languages

        time.sleep(300)

    except:
        print('Connection lost. Next try in 2 minutes.')
        time.sleep(120)

browser.quit()