-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🦔🐚 ↝ New server container (simplified API call for use as Next proxy …
…in signal-k/client) Signal-K/Silfur#24 -> now user inputs from /client/planets -> "CreatePlanet" can be sent and received in Flask #32 -> Flask will receive inputs and generate a TIC id based on the inputs #30 -> We'll set up a python call to the IPFS page on /client #18 -> Thirdweb/moralis package to call contract functions (which are defined in the IPFS bucket/postgres (centralised) db
- Loading branch information
1 parent
e387dec
commit 605ac1a
Showing
21 changed files
with
9,390 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FLASK_ENV=development | ||
FLASK_APP=main.py | ||
SUPABASE_URL= | ||
SUPABASE_KEY= |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from flask import Flask, request, make_response, jsonify, Blueprint | ||
|
||
import base64 | ||
from io import BytesIO | ||
|
||
from database.store import planets, add_planet_to_DB | ||
# from Generator import gen_image # add this to a blueprint | ||
|
||
from database.datastore import solObjects # get this from database.store / supabase-py in prod | ||
|
||
import time | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def index(): | ||
return jsonify(solObjects) | ||
|
||
@app.route('/planet', methods=['GET', 'POST']) | ||
def index(): | ||
return jsonify(planets) | ||
|
||
@app.route('/time') | ||
def get_current_time(): | ||
return {'time': time.time()} | ||
|
||
# GET request -> return all planets in storage/db in JSON format | ||
@app.route('/planets') | ||
def get_planets(): | ||
return jsonify({ | ||
'planets': planets, # Then present this on react frontend, port 5000 -> 3000 | ||
}) | ||
|
||
@app.route('/planets/<planet_id>') | ||
def find_planet_by_id(planet_id): | ||
for planet in planets: | ||
if planet["id"] == int(planet_id): | ||
return jsonify({ | ||
"planet": planet, | ||
}) | ||
|
||
@app.route('/planets/add', methods=['POST']) | ||
def add_planet(): | ||
data = request.get_json() | ||
try: | ||
title = data['title'] | ||
if title: | ||
data = add_planet_to_DB(title) | ||
return jsonify(data), 201 | ||
except: | ||
return Response('''{"message": "Bad Request"}''', status=400, mimetype='application/json') | ||
|
||
@app.route('/generator') | ||
def generate(): | ||
# Generate the figure **without using pyplot**. | ||
res = 2048 # see generate blueprint above | ||
"""fig = Figure() | ||
ax = fig.subplots() | ||
ax.plot([1, 2]) | ||
# Save it to a temporary buffer. | ||
buf = BytesIO() | ||
fig.savefig(buf, format="png") | ||
# Embed the result in the html output. | ||
data = base64.b64encode(buf.getbuffer()).decode("ascii") | ||
return f"<img src='data:image/png;base64,{data}'/>"""#" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
solObjects = [ | ||
{ | ||
'id': 0, | ||
'name': 'Sol', | ||
'type': 'Star', | ||
}, | ||
{ | ||
'id': 1, | ||
'name': 'Mercury', | ||
'type': 'Planet' | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from supabase_py import client, create_client | ||
|
||
url: str = os.environ.get("SUPABASE_URL") | ||
key: str = os.environ.get("SUPABASE_ANON_KEY") | ||
|
||
url = "https://afwwxlhknelxylrfvexi.supabase.co" | ||
key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFmd3d4bGhrbmVseHlscmZ2ZXhpIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjY0MzQ4MTgsImV4cCI6MTk4MjAxMDgxOH0.gk1F8Br9__04cvzqYIeeQ-U08KATiHovAw3r3ofNGAo" | ||
|
||
supabase: client = create_client(url, key) | ||
|
||
# Function to retrieve planet data from supa | ||
def find_all_planets(): # Right now this is just demo data, we'll push this data to Supa from Lightkurve later | ||
data = supabase.table("Planets").select("*").execute() | ||
return data['data'] | ||
|
||
planets = find_all_planets() | ||
print(planets) | ||
|
||
# Function to add a new planet to the store/supa | ||
def add_planet_to_DB(title) -> dict: # See `models/TIC.py` | ||
planet = { | ||
"title": title, | ||
} | ||
data = supabase.table("Planets").insert(planet).execute() | ||
|
||
return data['data'] |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.