Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
events almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
Olegogonich committed Nov 22, 2024
1 parent 8f3c00c commit 8faf96b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
20 changes: 11 additions & 9 deletions apps/backend/app.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
from flask import Flask, request, jsonify
from random import randrange
from events import events

app = Flask(__name__)


sobytie = {
"data": 10
}
def get_random_event():
randindex = randrange(0, len(events))
return events[randindex]

@app.route('/data', methods=['GET'])
def get_data():
print(request.get_json())

data = request.get_json().get("data")
@app.route('/event', methods=['POST'])
def get_data():
data = request.get_json()
print(data)

if data:
return sobytie
if not data:
return get_random_event().to_json()


if __name__ == '__main__':
Expand Down
23 changes: 20 additions & 3 deletions apps/backend/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,33 @@ def __init__(self, data):


class Event:
def __init__(self, description, minus_money, answers):
def __init__(self, description, answers, delta_money=0):
self.description = description
self.minus_money = minus_money
self.delta_money = delta_money
self.answers = answers

def to_json(self):
return {
"description": self.description,
"answers": [answer.to_json() for answer in self.answers],
"delta_money": self.delta_money
}


class Answer:
def __init__(self, text, chance_bad):
def __init__(self, text, chance_bad, delta_money=0, analytic_text=""):
self.text = text
self.chance_bad = chance_bad
self.delta_money = delta_money
self.analytic_text = analytic_text

def to_json(self):
return {
"text": self.text,
"chance_bad": self.chance_bad,
"delta_money": self.delta_money,
"analytic_text": self.analytic_text
}



Expand Down
1 change: 0 additions & 1 deletion apps/backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def close_db():
DB.conn.close()



# cursor.execute('''INSERT INTO users (money) VALUES (35000)''')

# data = cursor.execute('''SELECT * FROM users''')
Expand Down
32 changes: 16 additions & 16 deletions apps/backend/events.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
from classes import Event, Answer

events = {
"1": Event(
description="",
minus_money=0,
answers={
"1": Answer(
events = [
Event(
description="Зарплата",
delta_money=1000,
answers=[
Answer(
text="Да",
chance_bad=50
),
"2": Answer(
Answer(
text="Нет",
chance_bad=50
)
}
]
),
"2": Event(
Event(
description="",
minus_money=0,
answers={
"1": Answer(
answers=[
Answer(
text="Да",
chance_bad=50
chance_bad=50,
delta_money=10
),
"2": Answer(
Answer(
text="Нет",
chance_bad=50
)
}
]
)
}
]

0 comments on commit 8faf96b

Please sign in to comment.