|
|
@@ -1,4 +1,3 @@
|
|
|
-import database
|
|
|
import psycopg2.extras
|
|
|
|
|
|
|
|
|
@@ -7,14 +6,12 @@ def get_timestamp_previous():
|
|
|
Retrieve second to last timestamp from the stocks database
|
|
|
:return timestamp:
|
|
|
"""
|
|
|
- db = database.db
|
|
|
cursor = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
query = """SELECT DISTINCT timestamp FROM stocks ORDER BY stocks.timestamp DESC LIMIT 1 OFFSET 1;"""
|
|
|
cursor.execute(query)
|
|
|
res = cursor.fetchone()
|
|
|
this_timestamp_previous = res.timestamp
|
|
|
cursor.close()
|
|
|
- db.close()
|
|
|
return this_timestamp_previous
|
|
|
|
|
|
|
|
|
@@ -23,14 +20,12 @@ def get_timestamp_latest():
|
|
|
Retrieve latest timestamp from the stocks database
|
|
|
:return timestamp:
|
|
|
"""
|
|
|
- db = database.db
|
|
|
cursor = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
query = """SELECT DISTINCT timestamp FROM stocks ORDER BY stocks.timestamp DESC LIMIT 1;"""
|
|
|
cursor.execute(query)
|
|
|
res = cursor.fetchone()
|
|
|
this_timestamp_latest = res.timestamp
|
|
|
cursor.close()
|
|
|
- db.close()
|
|
|
return this_timestamp_latest
|
|
|
|
|
|
|
|
|
@@ -41,7 +36,7 @@ def get_timestamp_stored():
|
|
|
"""
|
|
|
with open('timestamp.txt', 'r') as f:
|
|
|
this_timestamp_stored_string = f.read()
|
|
|
- if this_timestamp_stored_string.replace('.','',1).isdigit():
|
|
|
+ if this_timestamp_stored_string.replace('.', '', 1).isdigit():
|
|
|
this_timestamp_stored = int(this_timestamp_stored_string)
|
|
|
else:
|
|
|
this_timestamp_stored = 0
|
|
|
@@ -59,13 +54,11 @@ def put_timestamp_stored(this_timestamp):
|
|
|
|
|
|
|
|
|
def get_data(stock_id, this_timestamp):
|
|
|
- db = database.db
|
|
|
cursor = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
query = """SELECT current_price, available_shares FROM stocks WHERE stock_id = %s AND timestamp = %s"""
|
|
|
cursor.execute(query, (stock_id, this_timestamp))
|
|
|
this_data = cursor.fetchone()
|
|
|
cursor.close()
|
|
|
- db.close()
|
|
|
return this_data
|
|
|
|
|
|
|