made some work for pastedb / pastecache..

This commit is contained in:
kalzu
2023-04-04 09:15:28 +03:00
parent 32d3e2dfe1
commit 5ffd0f0c03
63 changed files with 2251 additions and 0 deletions

View 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

View 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()

View 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()

View File

@ -0,0 +1,2 @@
requests==2.25.1
matplotlib==3.6.2