Skip to content

Commit 7469264

Browse files
committed
Add flask example for setting identities
1 parent 146bc3d commit 7469264

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
/.idea
1+
.idea
22
*.iml
33
node_modules
44
ui/public/bundle*
55
ui/bundle*
66
*.DS_Store
77
.env
8+
.venv
89
data
910
jam-config
11+
__pycache__

examples/flask-set-identities/app.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# app.py
2+
3+
from flask import Flask, render_template
4+
from base64 import urlsafe_b64encode
5+
from string import ascii_lowercase
6+
import json
7+
import random
8+
9+
radio_channel = ''.join(random.choice(ascii_lowercase) for x in range(24))
10+
11+
app = Flask('Red Squadron')
12+
13+
MEMBERS = {
14+
"Wedge": "https://static.giantbomb.com/uploads/scale_medium/0/118/541218-wedge_antilles.jpg",
15+
"Luke": "https://www.banthaskull.com/images/Yavin/b5lukeskywalker.jpg",
16+
"Ackbar": "https://www.rebelscum.com/GG/admiral-ackbar/header.jpg",
17+
}
18+
19+
20+
@app.route("/radio/<name>", methods=['GET'])
21+
def radio(name):
22+
if name in MEMBERS:
23+
identity = {
24+
"name": name,
25+
"avatar": MEMBERS[name]
26+
}
27+
jam_info = {
28+
"identity": identity
29+
}
30+
jam_hash = urlsafe_b64encode(json.dumps(jam_info).encode('utf-8')).decode('ascii')
31+
return render_template('radio.html', radio_channel=radio_channel, jam_hash=jam_hash)
32+
else:
33+
return "You are not in the squad"
34+
35+
36+
app.run(debug = True)
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Red Squadron Radio</title>
6+
</head>
7+
<body>
8+
<h1>Red Squadron Radio</h1>
9+
<h2>{{name}}</h2>
10+
<iframe style="height: 640px; width: 480px"
11+
allow="microphone;*"
12+
src="https://jam.systems/{{radio_channel}}#{{jam_hash}}">
13+
</iframe>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)