made some work for pastedb / pastecache..
This commit is contained in:
20
btc_tracker/01042023/TheClient/bin/TheClient.py
Normal file
20
btc_tracker/01042023/TheClient/bin/TheClient.py
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
import os
|
||||
import configparser
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from TheClient.database.db_utils import Database
|
||||
from TheClient.graphing.graph_utils import Graph
|
||||
|
||||
def load_config(config_file):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_file)
|
||||
return config
|
||||
|
||||
def get_btc_price():
|
||||
response = requests.get('https://api.binance.com/api/v3/avgPrice', params={'symbol': 'BTCUSDT'})
|
||||
json_data = response.json()
|
||||
return float(json_data['price'])
|
||||
|
||||
def main():
|
||||
config = load_config(os.path.join(os.path.dirname(__file__), '..', 'config', 'The
|
0
btc_tracker/01042023/TheClient/database/__init__.py
Normal file
0
btc_tracker/01042023/TheClient/database/__init__.py
Normal file
27
btc_tracker/01042023/TheClient/database/db_utils.py
Normal file
27
btc_tracker/01042023/TheClient/database/db_utils.py
Normal file
@ -0,0 +1,27 @@
|
||||
import sqlite3
|
||||
|
||||
class Database():
|
||||
def __init__(self, db_file):
|
||||
self.db_file = db_file
|
||||
self._create_table()
|
||||
|
||||
def _create_table(self):
|
||||
with sqlite3.connect(self.db_file) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS timeseries
|
||||
(timestamp INTEGER PRIMARY KEY, value REAL)''')
|
||||
conn.commit()
|
||||
|
||||
def insert_data(self, timestamp, value):
|
||||
with sqlite3.connect(self.db_file) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''INSERT INTO timeseries (timestamp, value)
|
||||
VALUES (?, ?)''', (timestamp, value))
|
||||
conn.commit()
|
||||
|
||||
def fetch_data(self, limit):
|
||||
with sqlite3.connect(self.db_file) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''SELECT timestamp, value FROM timeseries
|
||||
ORDER BY timestamp DESC LIMIT ?''', (limit,))
|
||||
return cursor.fetchall()
|
0
btc_tracker/01042023/TheClient/fetch/__init__.py
Normal file
0
btc_tracker/01042023/TheClient/fetch/__init__.py
Normal file
0
btc_tracker/01042023/TheClient/graphing/__init__.py
Normal file
0
btc_tracker/01042023/TheClient/graphing/__init__.py
Normal file
12
btc_tracker/01042023/TheClient/graphing/graph_utils.py
Normal file
12
btc_tracker/01042023/TheClient/graphing/graph_utils.py
Normal file
@ -0,0 +1,12 @@
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
class Graph():
|
||||
def __init__(self, xdata, ydata):
|
||||
self.fig, self.ax = plt.subplots()
|
||||
self.line, = self.ax.plot(xdata, ydata)
|
||||
|
||||
def update_graph(self, xdata, ydata):
|
||||
self.line.set_data(xdata, ydata)
|
||||
self.ax.relim()
|
||||
self.ax.autoscale_view()
|
||||
self.fig.canvas.draw()
|
2
btc_tracker/01042023/TheClient/requirements.txt
Normal file
2
btc_tracker/01042023/TheClient/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
requests==2.25.1
|
||||
matplotlib==3.6.2
|
0
btc_tracker/01042023/TheClient/tests/__init__.py
Normal file
0
btc_tracker/01042023/TheClient/tests/__init__.py
Normal file
Reference in New Issue
Block a user