@pyelias/

stonk charts

Python

No description

fork
loading
Files
  • main.py
  • static
  • data.json
  • keepalive.py
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import time
import threading

import requests

import keepalive

API = "https://stonks-bot.mat1.repl.co/api/leaderboard"
SLEEP_TIME = 60

with open("data.json", "r+") as f:
	data = f.read().strip()
	if data:
		money, users = json.loads(data)
	else:
		money, users = {}, {}

def get_api():
	return requests.get(API).json()[0]

def update_data():
	new_money = {}
	for user in get_api():
		new_money[user["id"]] = user["money"]
		users[str(user["id"])] = user["username"]
	money[time.time()] = new_money
	with open("data.json", "w+") as f:
		f.write(json.dumps([money, users]))

def update_thread():
	while True:
		update_data()
		time.sleep(SLEEP_TIME)

update_thread()