-
Notifications
You must be signed in to change notification settings - Fork 1
updating the code to work with python 3.12 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7b4f994
d67ac66
087a8d6
31371cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| .Python | ||
| env/ | ||
| venv/ | ||
| .git | ||
| .gitignore | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,3 +117,4 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
| .lh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| FROM python:3.12-slim | ||
|
|
||
|
|
||
| # Upgrade pip and system packages to reduce vulnerabilities | ||
| RUN apt-get update && \ | ||
| apt-get upgrade -y && \ | ||
| apt-get install -y --no-install-recommends gcc build-essential && \ | ||
| python3 -m pip install --upgrade pip && \ | ||
| apt-get clean && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY requirements.txt ./ | ||
| RUN python3 -m pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| COPY . . | ||
|
Comment on lines
+14
to
+17
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just use this last |
||
|
|
||
| EXPOSE 5000 | ||
|
|
||
| CMD ["python3", "web.py"] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole webapp doesn't have any external services, so I don't see a need for it to have a docker compose. I appreciate the Dockerfile though! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| version: "3.12" | ||
|
|
||
| services: | ||
| clonenames: | ||
| build: . | ||
| ports: | ||
| - "5000:5000" | ||
| environment: | ||
| - PYTHONUNBUFFERED=1 | ||
| restart: unless-stopped |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ dnspython==1.16.0 | |
| eventlet==0.30.1 | ||
| Flask==1.1.2 | ||
| Flask-SocketIO==5.0.1 | ||
| greenlet==1.0.0 | ||
| greenlet | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dependency (and many others) is out of date, but I don't want to unpin them. |
||
| itsdangerous==1.1.0 | ||
| Jinja2==2.11.3 | ||
| MarkupSafe==1.1.1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,116 +21,123 @@ | |||||
| games = dict() | ||||||
|
|
||||||
|
|
||||||
| @app.route(u'/') | ||||||
| @app.route("/") | ||||||
| def home_page(): | ||||||
| return render_template(u'index.html') | ||||||
| return render_template("index.html") | ||||||
|
|
||||||
|
|
||||||
| @app.route(u'/start', methods = [u'GET', u'POST']) | ||||||
| @app.route("/start", methods=["GET", "POST"]) | ||||||
| def start_page(): | ||||||
| if request.method == u'POST': | ||||||
| game = clonenames.Board(request.form.get(u'words')) | ||||||
| if request.method == "POST": | ||||||
| game = clonenames.Board(request.form.get("words")) | ||||||
|
|
||||||
| success = game.load_settings( | ||||||
| teams = int(request.form.get(u'number')), | ||||||
| size = int(request.form.get(u'size'))) | ||||||
| teams=int(request.form.get("number")), size=int(request.form.get("size")) | ||||||
| ) | ||||||
|
|
||||||
| if success: | ||||||
| room = generate_room_code() | ||||||
|
|
||||||
| games[room] = game | ||||||
|
|
||||||
| return redirect(url_for(u'game_page', room = room)) | ||||||
| return redirect(url_for("game_page", room=room)) | ||||||
|
|
||||||
| else: | ||||||
| return render_template( | ||||||
| u'start.html', | ||||||
| words = clonenames.wordlists, | ||||||
| alert = u'The word list selected must be played on a smaller game board... Sorry!') | ||||||
| "start.html", | ||||||
| words=clonenames.wordlists, | ||||||
| alert="The word list selected must be played on a smaller game board... Sorry!", | ||||||
| ) | ||||||
|
|
||||||
| elif request.method == u'GET': | ||||||
| return render_template(u'start.html', words = clonenames.wordlists) | ||||||
| elif request.method == "GET": | ||||||
| return render_template("start.html", words=clonenames.wordlists) | ||||||
|
|
||||||
|
|
||||||
| @app.route(u'/game', methods = [u'GET', u'POST']) | ||||||
| @app.route("/game", methods=["GET", "POST"]) | ||||||
| def game_page(): | ||||||
| if request.args.get(u'room'): | ||||||
| room = request.args.get(u'room') | ||||||
| if request.args.get("room"): | ||||||
| room = request.args.get("room") | ||||||
| return render_template( | ||||||
| u'game.html', | ||||||
| show_input = False, | ||||||
| room = room, | ||||||
| host = True, | ||||||
| words = games[room].table(), | ||||||
| start = games[room].order[0], | ||||||
| remnants = games[room].remnants) | ||||||
| "game.html", | ||||||
| show_input=False, | ||||||
| room=room, | ||||||
| host=True, | ||||||
| words=games[room].table(), | ||||||
| start=games[room].order[0], | ||||||
| remnants=games[room].remnants, | ||||||
| ) | ||||||
|
|
||||||
| else: | ||||||
| try: | ||||||
| if request.method == u'GET': | ||||||
| return render_template( | ||||||
| u'game.html', | ||||||
| show_input = True) | ||||||
| if request.method == "GET": | ||||||
| return render_template("game.html", show_input=True) | ||||||
|
|
||||||
| elif request.method == u'POST': | ||||||
| room = request.form.get(u'room', False).upper() | ||||||
| elif request.method == "POST": | ||||||
| room = request.form.get("room", False).upper() | ||||||
| if check_room_code(room): | ||||||
| return render_template( | ||||||
| u'game.html', | ||||||
| show_input = False, | ||||||
| room = room, | ||||||
| host = request.form.get(u'host', False) == u'on', | ||||||
| words = games[room].table(), | ||||||
| start = games[room].order[0], | ||||||
| remnants = games[room].remnants) | ||||||
| "game.html", | ||||||
| show_input=False, | ||||||
| room=room, | ||||||
| host=request.form.get("host", False) == "on", | ||||||
| words=games[room].table(), | ||||||
| start=games[room].order[0], | ||||||
| remnants=games[room].remnants, | ||||||
| ) | ||||||
|
|
||||||
| else: | ||||||
| return render_template( | ||||||
| u'game.html', | ||||||
| show_input = True, | ||||||
| alert = u'The room code you entered does not exist. Please try again!') | ||||||
| "game.html", | ||||||
| show_input=True, | ||||||
| alert="The room code you entered does not exist. Please try again!", | ||||||
| ) | ||||||
|
|
||||||
| except AttributeError: | ||||||
| return redirect(url_for(u'home_page')) | ||||||
| return redirect(url_for("home_page")) | ||||||
|
|
||||||
|
|
||||||
| # @app.route(u'/statistics') | ||||||
| # def stats_page(): | ||||||
| # return render_template(u'statistics.html', | ||||||
| # rooms = [games[game].statistics() for game in games]) | ||||||
|
|
||||||
|
|
||||||
| @socketio.on(u'join') | ||||||
| @socketio.on("join") | ||||||
| def join(data): | ||||||
| join_room(data[u'room']) | ||||||
| join_room(data["room"]) | ||||||
|
|
||||||
|
|
||||||
| @socketio.on(u'clicked') | ||||||
| @socketio.on("clicked") | ||||||
| def handle_host_click(json): | ||||||
| response = games[json[u'room']].get(json[u'id']) | ||||||
| socketio.emit(u'revealed', { | ||||||
| u'text': u'Host clicked on {word}'.format( | ||||||
| word = response[u'word']), | ||||||
| u'id': u'#{id}'.format(id = json[u'id']), | ||||||
| u'remnant': response[u'remnant'], | ||||||
| u'class': u'btn-{team}'.format( | ||||||
| team = response[u'team'])}, room = json['room']) | ||||||
|
|
||||||
|
|
||||||
| @socketio.on(u'ended_turn') | ||||||
| response = games[json["room"]].get(json["id"]) | ||||||
| socketio.emit( | ||||||
| "revealed", | ||||||
| { | ||||||
| "text": "Host clicked on {word}".format(word=response["word"]), | ||||||
| "id": "#{id}".format(id=json["id"]), | ||||||
| "remnant": response["remnant"], | ||||||
| "class": "btn-{team}".format(team=response["team"]), | ||||||
| }, | ||||||
| room=json["room"], | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @socketio.on("ended_turn") | ||||||
| def handle_end_turn(json): | ||||||
| team = games[json[u'room']].advance_turn() | ||||||
| team = games[json["room"]].advance_turn() | ||||||
|
|
||||||
| alert = u'alert {team}-start alert-start'.format(team = team) | ||||||
| button = u'btn btn-{team} float-right'.format(team = team) | ||||||
| alert = "alert {team}-start alert-start".format(team=team) | ||||||
| button = "btn btn-{team} float-right".format(team=team) | ||||||
|
|
||||||
| socketio.emit(u'change_turn', { | ||||||
| u'alert': alert, | ||||||
| u'text': team, | ||||||
| u'button': button}, room = json[u'room']) | ||||||
| socketio.emit( | ||||||
| "change_turn", | ||||||
| {"alert": alert, "text": team, "button": button}, | ||||||
| room=json["room"], | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def generate_room_code(): | ||||||
| letters = u''.join(random.sample(list(u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 5)) | ||||||
| letters = "".join(random.sample(list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 5)) | ||||||
| while letters in games.keys(): | ||||||
| return generate_room_code() | ||||||
|
|
||||||
|
|
@@ -141,5 +148,5 @@ def check_room_code(code): | |||||
| return code in games.keys() | ||||||
|
|
||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
| socketio.run(app, debug=True, host=u'0.0.0.0') | ||||||
| if __name__ == "__main__": | ||||||
| socketio.run(app, debug=False, host="0.0.0.0") | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This should all probably be reading in parameters from a config file or something, but let's keep the original default value. |
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty harmless just in the .gitignore, but what is this for? I think this can be removed.