Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_read_connection():
- connection = None
- read_host = 'localhost'
- try:
- if sys.platform != 'darwin':
- read_host = 'remote_rds_host.com'
- read_c = pymysql.connect(
- host=read_host,
- user=user,
- password=password,
- db=db_name,
- autocommit=False,
- cursorclass=pymysql.cursors.DictCursor)
- print('Read Connected')
- except Exception as ex:
- print('Exception in Read Connection')
- print(str(ex))
- finally:
- return read_c
- def get_connection():
- connection = None
- try:
- connection = pymysql.connect(host=host,
- user=user,
- password=password,
- db=db_name,
- cursorclass=pymysql.cursors.DictCursor)
- print('Connected')
- except Exception as ex:
- print(str(ex))
- finally:
- return connection
- def get_links(size=4):
- total_links = []
- sql = None
- try:
- if connection is not None:
- # connection_read.ping(reconnect=True)
- now = datetime.datetime.now()
- # print("Current date and time using strftime:")
- # print(now.strftime("%Y-%m-%d %H:%M"))
- with connection.cursor() as cursor:
- # sql = ' SELECT * from zillow_links_master where status = 0 LIMIT ' + str(size)
- sql = " select license_id from " + TABLE_NAME + " WHERE status = 0 ORDER BY id LIMIT " + str(size)
- print(sql)
- cursor.execute(sql)
- links = cursor.fetchall()
- for link in links:
- total_links.append(link['license_id'])
- print(tuple(total_links))
- print('======================================')
- if len(total_links) > 0:
- if connection is not None:
- now = datetime.datetime.now()
- # print("Current date and time using strftime:")
- # print(now.strftime("%Y-%m-%d %H:%M"))
- with connection.cursor() as cursor:
- format_strings = ','.join(['%s'] * len(total_links))
- # sql = " UPDATE " + TABLE_NAME + " set is_processed = 4 WHERE url IN (%s)" % format_strings,
- sql = " UPDATE " + TABLE_NAME + " set status = 1 WHERE license_id IN ({})".format(
- format_strings)
- cursor.execute(sql, tuple(total_links))
- connection.commit()
- print(cursor.rowcount)
- except Exception as ex:
- print('Exception in get_links')
- crash_date = time.strftime("%Y-%m-%d %H:%m:%S")
- crash_string = "".join(traceback.format_exception(etype=type(ex), value=ex, tb=ex.__traceback__))
- exception_string = '[' + crash_date + '] - ' + crash_string + 'n'
- print(exception_string)
- print(sql)
- if 'lost' in exception_string:
- print('Connection lost')
- # connection_read.ping()
- finally:
- return total_links
- while True:
- print('Block Begin')
- now = datetime.datetime.now()
- # print("Current date and time using strftime:")
- # print(now.strftime("%Y-%m-%d %H:%M"))
- p_links = get_links(LIMIT)
- for p in p_links:
- l_id = p
- result = parse(l_id)
- store_lic_info(l_id, result)
- sleep(2)
- connection.commit()
- print('Block End')
- sleep(2)
Add Comment
Please, Sign In to add comment