def update_and_alert(): ksl_results = ksl_scraper.get_mls_listings() ure_results = ure_scraper.get_mls_listings() results = ure_results + ksl_results results_dict = { status: [result for result in results if result.status == status] for status in shared.STATUSES } current = shared.format_listings(results) current_dict = { key: shared.format_listings(value) for key, value in results_dict.items() } if db.db_exists(): shared.log_message(f'Begin update DB') previous, previous_dict = db.get_db_listings() new_listings = update_db_new_listings(current, current_dict, previous, previous_dict) if new_listings: shared.log_message( f'New listings added to DB: {", ".join([str(listing)for listing in new_listings])}' ) else: shared.log_message('No new listings added to DB') off_market_ids = update_db_off_market(current, current_dict, previous, previous_dict) if off_market_ids: shared.log_message( f'Off market listings updated in DB: {", ".join([str(listing)for listing in off_market_ids])}' ) else: shared.log_message('No off market listings updated in DB') update_db(current, current_dict, previous, previous_dict) shared.log_message('Updated DB') send_email(current, current_dict, previous, previous_dict) else: shared.log_message(f'Begin create DB, no file at "{shared.DB}"') db.create_db() db.insert_rows([value for key, value in current[1].items()]) shared.log_message('Created DB')
def upload_csv_to_db(): """First it checks if the database exists, if it doesn't it will be created along with the table that will store the companies' data. Then it will upload every row of the csv file to that table """ if not os.path.exists(DB_FILENAME): create_db() logging.info(f"Now uploading the csv file to the database") with open(CSV_FILENAME, "r", encoding='utf-8') as results: n_records = 0 lines = csv.reader(results) next(lines, None) connection = connect_to_db() for line in lines: insert_row(line, connection) n_records += 1 close_connection(connection) logging.info(f"{n_records} rows inserted in the table")
def filter_cases(db_path, fetched_case_list): db_conn = db_manager.create_db(db_path) cursor = db_conn.cursor() cursor.execute("SELECT * FROM case_table") saved_case_list = cursor.fetchall() cursor.close() for fetched_case in fetched_case_list: handle_case(db_conn, saved_case_list, fetched_case) notification_list = get_notification_list(db_conn) db_conn.commit() db_conn.close() return notification_list
with open(file) as text_file: is_fraud, tokens = document.tokenize(text_file.read().decode('utf-8')) # get academic sickness ac = document.academic_sickness(tokens) # write to db write_to_db(db_path, file, is_fraud, ac) def run_pools(files_dir, count_workers, db_path): """Run parse files in threads""" with ThreadPoolExecutor(max_workers=count_workers) as executor: file_list = os.listdir(files_dir) for element in file_list: executor.submit(parse, files_dir + '/' + element, db_path) if __name__ == "__main__": m = argparse.ArgumentParser(description="Run parsing text") m.add_argument("--files_dir", "-f", type=str, default="./text_files", help="Path to dir with text files") m.add_argument("--count_workers", "-c", type=int, default=1, help="Count of workers in thread pool") m.add_argument("--db_path", "-d", type=str, default="result.db", help="Path to create db") options = vars(m.parse_args()) # create db create_db(options['db_path']) #run workers run_pools(options['files_dir'], options['count_workers'], options['db_path'])
text= "You need to set a username to use this bot. Set and start again." ) else: greeting = "Hello {}, you've been successfully added to u-l8-m8-bot!".format( username) add_user(update.message.from_user.username, update.message.chat_id) bot.send_message(chat_id=update.message.chat_id, text=greeting) start_handler = CommandHandler("start", start_callback) # Add Start handler dispatcher.add_handler(start_handler) # Add Meeting handler dispatcher.add_handler(add_meeting_handler) # Add User handler dispatcher.add_handler(user_handler) # Add RSVP handlers dispatcher.add_handler(rsvp_handler) dispatcher.add_handler(end_rsvp_handler) # Start up open('state.txt', "w+").write('WAITING') create_db() print("init success") updater.start_polling()
def new_db(message): if message.from_user.id == 364251261: dbm.create_db() bot.reply_to(message, "New DB created")