repl.it
@pyelias/

farming game database verified

Python

No description

fork
loading
Files
  • main.py
  • poetry.lock
  • pyproject.toml
  • requirements.txt
  • simulator.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pymongo, flask, os

import simulator
# no database
'''
client = pymongo.MongoClient(f"mongodb+srv://{os.getenv('USERNAME')}:{os.getenv('PASSWORD')}@cluster0-hwxl5.mongodb.net/test?retryWrites=true&w=majority")
scores = client.scores'''

app = flask.Flask(__name__)

@app.route('/lead')
def leaders():
  # no db
  return "[]"

  newdata = []
  data = list(scores.leaders.find({}))
  for d in data:
    del d['_id']
    newdata.append(d)
  return str(newdata)

@app.route('/avg')
def average():
  # no db
  return "1"

  data = scores.avg.find_one({'key': 'AVG'})
  return str(data['score']/data['players'])

@app.route('/add', methods=['POST'])
def add(): 
  data = flask.request.get_json()
  
  '''nscores = []
  def getscore(p):
    return p[0]
  for player in list(scores.leaders.find({})):
    nscores.append((player['s'], player['n']))
  nscores.sort(key=getscore)
  nscores.reverse()'''

  u = data["name"]
  s = data["score"]
  l = data["l"]

  length, state, log = data["log"]
  real_score = simulator.simulate(length, state, log)
  if real_score is None or real_score != s:
    print("big oof")
    return "something broke or u cheat"
  print("ok")

  # no db
  '''if l==1:
    scores.leaders.insert_one({'n': u, 's': s})
    scores.leaders.delete_one({'s': nscores[4][0]})
  data = scores.avg.find_one({'key': 'AVG'})
  scores.avg.delete_one({'key': 'AVG'})
  scores.avg.insert_one({'key': 'AVG', 'score': data['score']+s, 'players':data['players']+1})'''
  return 'SUCCESS!'

app.run(host='0.0.0.0', port=6506)