repl.it
@PYer/

Leaderboard PYer

Python

No description

fork
loading
Files
  • main.py
  • load.css
  • load.html
  • temp.css
  • temp.html
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
37
38
39
40
41
42
43
44
45
import flask, requests, replit

link = 'https://Leader-Board-Member-greater-JSON.pyer.repl.co/get?user='
llink = 'https://Leader-Board-Member-greater-JSON.pyer.repl.co/lead'

app = flask.Flask('')

replit.clear()

@app.route('/')
def index():
  try:
    leaders = []
    leadernames = eval(requests.get(llink).text)
    for leadername in leadernames:
      print('requesting ' + leadername)
      json = requests.get(link + leadername).text
      json = eval(json)
      leaders.append(json)
      print('recieved')
    print(leaders)
    entire = 0
    for leader in leaders:
      entire += leader['cycles']
    lds = []
    for leader in leaders:
      l = leader
      l['hold'] = l['cycles'] / entire
      lds.append(l)
    with open('temp.css', 'r') as css:
      with open('temp.html', 'r') as temp:
        return '<style>\n' + css.read() + '\n</style>\n' + temp.read().format(lds)
  except Exception as e:
    return str(e)

@app.route('/load')
def load():
  with open('load.css', 'r') as css:
    with open('load.html', 'r') as temp:
      return '<style>\n' + css.read() + '\n</style>\n' + temp.read()

def run(host='0.0.0.0', port=8080):
  app.run(host=host, port=port)

run()