Skip to content

Commit

Permalink
🦔🐚 ↝ New server container (simplified API call for use as Next proxy …
Browse files Browse the repository at this point in the history
…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
Gizmotronn committed Mar 8, 2023
1 parent e387dec commit 605ac1a
Show file tree
Hide file tree
Showing 21 changed files with 9,390 additions and 20 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
url = https://github.com/foundry-rs/forge-std.git
[submodule "Server/client"]
path = Server/client
url = https://github.com/signal-k/client
url = https://github.com/signal-k/client
9,279 changes: 9,279 additions & 0 deletions Archive/yarn.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Container/.flaskenv
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.
2 changes: 1 addition & 1 deletion Generator/geometry.py → Container/Generator/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def dot(a, b):
x1, y1, z1 = a
x2, y2, z2 = b
return x1 * x2 + y1 * y2 + z1 * z2

x

def cos_vec(a, b):
return dot(a, b) / np.sqrt(dot(a, a) * dot(b, b))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions Container/app.py
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 added Container/database/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions Container/database/datastore.py
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'
}
]
27 changes: 27 additions & 0 deletions Container/database/store.py
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
1 change: 1 addition & 0 deletions Server/client
Submodule client added at 9be1e7
12 changes: 0 additions & 12 deletions hardhat 2.config.js

This file was deleted.

6 changes: 0 additions & 6 deletions postcss 2.config.js

This file was deleted.

0 comments on commit 605ac1a

Please sign in to comment.