From face7070973ae1a7e512706ccd65185e065e76e9 Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Thu, 25 Jan 2024 17:41:31 +1100 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=8C=AE=F0=9F=AA=B6=20=E2=86=9D=20putt?= =?UTF-8?q?ing=20in=20sample=20app=20[=20GP-12=20]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 8 --- app.txt | 155 +++++++++++++++++++++++++++++++++++++++++++ main.py | 10 +++ requirements.txt | 2 + templates/index.html | 9 +++ 5 files changed, 176 insertions(+), 8 deletions(-) delete mode 100644 app.py create mode 100644 app.txt create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 templates/index.html diff --git a/app.py b/app.py deleted file mode 100644 index dd06d31..0000000 --- a/app.py +++ /dev/null @@ -1,8 +0,0 @@ -from flask import Flask -from flask_sqlalchemy import SQLAlchemy - -db = SQLAlchemy() -app = Flask(__name__) - -app.config["SQLALCHEMY_DATABASE_URI"] = "" -db.init_app(app) \ No newline at end of file diff --git a/app.txt b/app.txt new file mode 100644 index 0000000..6f0f2c4 --- /dev/null +++ b/app.txt @@ -0,0 +1,155 @@ +from flask import Flask, jsonify, request +from supabase_py import create_client +from flask_cors import CORS + +app = Flask(__name__) +CORS(app) + +# app.config["SQLALCHEMY_DATABASE_URI"] = "postgres://postgres.qw" +# db.init_app(app) + +# Create Supabase client +SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' +SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk' +supabase = create_client(SUPABASE_URL, SUPABASE_KEY) + +itemList = { # This should be automated in the `/items` route later + 11: {"name": "Coal", "type": "Minerals"}, + 13: {"name": "Silicates", "type": "Minerals"}, + 15: {"name": "Iron", "type": "Minerals"}, + 17: {"name": "Alloy", "type": "Minerals"}, + 18: {"name": "Fuel", "type": "Minerals"}, + 19: {"name": "Copper", "type": "Minerals"}, + 20: {"name": "Chromium", "type": "Minerals"}, + 16: {"name": "Nickel", "type": "Minerals"}, + 21: {"name": "Water", "type": "Minerals"}, + 14: {"name": "Transiting Telescope", "type": "Structure"}, + 12: {"name": "Telescope Signal Receiver", "type": "Structure"}, +} + +crafting_recipes = [ + {"input": [(11, 1), (13, 1)], "output": (14, 1)}, # Coal + Silicates = Transiting Telescope +] + +# Route to fetch items from inventoryITEMS table +@app.route('/items') +def get_items(): + # Query items from inventoryITEMS table + items = supabase.table('inventoryITEMS').select('*').execute() + return jsonify(items['data'], itemList) + +# Route to fetch user inventory from inventoryUSERS table +@app.route('/inventory/') +def get_user_inventory(user_id): + # Query user inventory from inventoryUSERS table + user_inventory = supabase.table('inventoryUSERS').select('*').eq('owner', user_id).execute() + return jsonify(user_inventory['data'] + itemList) + +@app.route('/craft_structure', methods=['POST']) # In this method, the actual crafting/removal of items would be done in the `client` repo +def craft_structure(): + data = request.json + user_id = data.get('user_id') + structure_id = data.get('structure_id') + + # Retrieve the crafting recipe for the specified structure + recipe = next((recipe for recipe in crafting_recipes if recipe['output'][0] == structure_id), None) + + if recipe is None: + return jsonify({'status': 'fail', 'message': 'Invalid structure ID'}), 400 + + # Check if the user has the required items in their inventory + user_inventory = supabase.table('inventoryUSERS').select('item', 'quantity').eq('owner', user_id).execute() + items_needed = recipe['input'] + items_available = {item['item']: item['quantity'] for item in user_inventory['data']} + + for item_id, quantity_needed in items_needed: + if item_id not in items_available or items_available[item_id] < quantity_needed: + return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}), 400 + + """ + # If the user has the required items, deduct them from the inventory + for item_id, quantity_needed in items_needed: + # Reduce the quantity of the item in the inventory + for item in user_inventory['data']: + if item['item'] == item_id: + remaining_quantity = item['quantity'] - quantity_needed + supabase.table('inventoryUSERS').update({'quantity': remaining_quantity}).eq('owner', user_id).eq('item', item_id).execute() + break + """ + + # Add the crafted structure to the user's inventory + supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1}).execute() + + return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 + # Get user id and structure id from the request + data = request.get_json() + user_id = data.get('user_id') + structure_id = data.get('structure_id') + + # Find the crafting recipe for the specified structure + recipe = None + for crafting_recipe in crafting_recipes: + if crafting_recipe['output'][0] == structure_id: + recipe = crafting_recipe + break + + if not recipe: + return jsonify({'status': 'fail', 'message': 'Structure not found'}) + + # Check if the user has enough of each required item + for item_id, quantity in recipe['input']: + user_items = supabase.table('inventoryUSERS').select('quantity').eq('owner', user_id).eq('item', item_id).execute() + total_quantity = sum([item['quantity'] for item in user_items['data']]) + if total_quantity < quantity: + return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}) + + # Calculate quantities to be deducted from the inventory + deductions = [] + for item_id, quantity in recipe['input']: + quantity_to_deduct = quantity + user_items = supabase.table('inventoryUSERS').select('id', 'quantity').eq('owner', user_id).eq('item', item_id).execute() + for item in user_items['data']: + if item['quantity'] >= quantity_to_deduct: + deductions.append({'id': item['id'], 'quantity': quantity_to_deduct}) + break + else: + quantity_to_deduct -= item['quantity'] + deductions.append({'id': item['id'], 'quantity': item['quantity']}) + + # Construct the response + response = { + 'status': 'proceed', + 'message': 'User can craft the structure', + 'deductions': deductions + } + return jsonify(response) + +""" +# class InventoryUsers(db.Model): +# __tablename__ = 'inventoryUSERS' + +# id = db.Column(db.BigInteger, primary_key=True) +# item = db.Column(db.BigInteger, db.ForeignKey('inventoryITEMS.id')) +# owner = db.Column(db.String, db.ForeignKey('profiles.id')) +# quantity = db.Column(db.Float) +# location = db.Column(db.BigInteger, db.ForeignKey('inventoryPLANETS.id')) +# sector = db.Column(db.BigInteger, db.ForeignKey('basePlanetSectors.id')) +# planetSector = db.Column(db.BigInteger, db.ForeignKey('basePlanetSectors.id')) + +# class InventoryItems(db.Model): +# __tablename__ = 'inventoryITEMS' + +# id = db.Column(db.BigInteger, primary_key=True) +# name = db.Column(db.String) +# description = db.Column(db.Text) +# cost = db.Column(db.Integer) +# icon_url = db.Column(db.String) +# ItemCategory = db.Column(db.String) +# parentItem = db.Column(db.BigInteger) +# itemLevel = db.Column(db.Float, default=1.0) +# oldAssets = db.Column(db.ARRAY(db.Text)) +""" + +# Main function to run the Flask app +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..39393b1 --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ +from flask import Flask, render_template + +app = Flask(__name__) + +@app.route('/') +def index(): + return render_template('index.html') + +if __name__ == '__main__': + app.run(port=5000) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4431900 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask>=2.0.0 +gunicorn>=20.1.0 diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..7df65a7 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,9 @@ + + + + Hello World + + +

Hello World!

+ + From e3744398073b494d8b3b46b0f7501d917ffd42e7 Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Fri, 26 Jan 2024 17:50:30 +1100 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=A7=B9=F0=9F=92=9A=20=E2=86=9D=20prev?= =?UTF-8?q?ious=20deployment=20didn't=20work,=20trying=20again=20->=20putt?= =?UTF-8?q?ing=20in=20sample=20app=20[=20GP-12=20]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 21 +++++++++ Procfile | 1 + README.md | 121 ++-------------------------------------------------- main.py | 4 +- vercel.json | 19 +++++++++ 5 files changed, 47 insertions(+), 119 deletions(-) create mode 100644 LICENSE create mode 100644 Procfile create mode 100644 vercel.json diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7748ae0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Alphasec + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..1945201 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn main:app diff --git a/README.md b/README.md index 6a70365..f99a7bf 100644 --- a/README.md +++ b/README.md @@ -1,119 +1,6 @@ -
-

kee.so

+# flask +A minimal Flask web application. -Create now ➫ [🔗 kee.so](https://kee.so/) +For a step-by-step guide to deploying on [Railway](https://railway.app/?referralCode=alphasec), see [this](https://alphasec.io/how-to-deploy-a-python-flask-app-on-railway/) post, or click the button below. -
- ---- - -
-

Paper 6.21

- -Demo → [hugo-paper.vercel.app](https://hugo-paper.vercel.app/) - -A simple, clean, customizable Hugo theme. - -⚡️ Fast | 👒 Customizable | 🫙 Smooth - -
- -## Links - -Product Hunt: [producthunt.com/posts/hugo-paper-6](https://www.producthunt.com/posts/hugo-paper-6) - -Hugo themes: [themes.gohugo.io/hugo-paper](https://themes.gohugo.io/hugo-paper/) - -## Overview - -![](./images/screenshot.png) -![](./images/screenshot_dark.png) -![](./images/screenshot_mobile.png) -![](./images/pagespeed.png) - -## Options - -Available options to `config.toml` or `hugo.toml`: - -```toml -disqusShortname = 'YOUR_DISQUS_SHORTNAME' # use disqus comments - -[params] - # color style - color = 'linen' # linen, wheat, gray, light - - # header social icons - twitter = 'YOUR_TWITTER_ID' # twitter.com/YOUR_TWITTER_ID - github = 'YOUR_GITHUB_ID' # github.com/YOUR_GITHUB_ID - instagram = 'YOUR_INSTAGRAM_ID' # instagram.com/YOUR_INSTAGRAM_ID - linkedin = 'YOUR_LINKEDIN_ID' # linkedin.com/in/YOUR_LINKEDIN_ID - mastodon = 'YOUR_MASTODON_LINK' # e.g. 'https://mastodon.instance/@xxx' - rss = true # show rss icon - - # home page profile - avatar = 'GRAVATAR_EMAIL' # gravatar email or image url - name = 'YOUR_NAME' - bio = 'YOUR_BIO' - - - # misc - disableHLJS = true # disable highlight.js - disablePostNavigation = true # disable post navigation - monoDarkIcon = true # show monochrome dark mode icon - gravatarCdn = 'GRAVATAR_CDN_LINK' # e.g. 'https://cdn.v2ex.com/gravatar/' - graphCommentId = "YOUR_GRAPH_COMMENT_ID" # use graph comment (disqus alternative) - math = true # enable KaTeX math typesetting globally -``` - -Available options to front matter: - -```toml -comments = false # disable comments for a specific page -math = true # enable KaTeX math typesetting for a specific page -``` - -## Install - -### As hugo module - -Inside the folder of your Hugo project, run: - -```bash -hugo mod init github.com// -``` - -Add paper theme ad dependency of your site: - -```bash -hugo mod init github.com// -``` - -Open `config.toml` or `hugo.toml`, remove the `theme` line (if present) and add module section at the bottom of the file: - -```toml -[module] - [[module.imports]] - path = "github.com/nanxiaobei/hugo-paper" -``` - -For more information, please read the [official guide](https://gohugo.io/hugo-modules/use-modules/#use-a-module-for-a-theme) of Hugo. - -### As git submodule - -Inside the folder of your Hugo project, run: - -```bash -git submodule add https://github.com/nanxiaobei/hugo-paper themes/paper -``` - -Open `config.toml` or `hugo.toml`, change `theme` to `"paper"`: - -```toml -theme = "paper" -``` - -For more information, please read the [official guide](https://gohugo.io/getting-started/quick-start/#configure-the-site) of Hugo. - -## License - -[MIT License](https://github.com/nanxiaobei/hugo-paper/blob/main/LICENSE) (c) [nanxiaobei](https://lee.so/) +[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/igzwwg?referralCode=alphasec) diff --git a/main.py b/main.py index 39393b1..b6dfda6 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ @app.route('/') def index(): - return render_template('index.html') + return render_template('index.html') if __name__ == '__main__': - app.run(port=5000) \ No newline at end of file + app.run(port=5000) diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..1dff1d1 --- /dev/null +++ b/vercel.json @@ -0,0 +1,19 @@ +{ + "version": 2, + "builds": [ + { + "src": "main.py", + "use": "@vercel/python" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "/main.py" + } + ], + "env": { + "FLASK_ENV": "production", + "FLASK_APP": "main.py" + } +} From d89735fba17b73818b9ea82feac7f899364b5bfa Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Fri, 26 Jan 2024 17:30:50 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=8C=A6=EF=B8=8F=F0=9F=A5=88=20?= =?UTF-8?q?=E2=86=9D=20Adding=20some=20tests=20from=20https://github.com/s?= =?UTF-8?q?ignal-k/sytizen/23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flaskenv | 2 + main.py | 127 ++++++++++++++++++++++++++++++++++++++++++- requirements.txt | 3 + app.txt => test.py | 0 tests/kurve-parse.py | 52 ++++++++++++++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 .flaskenv rename app.txt => test.py (100%) create mode 100644 tests/kurve-parse.py diff --git a/.flaskenv b/.flaskenv new file mode 100644 index 0000000..c80b622 --- /dev/null +++ b/.flaskenv @@ -0,0 +1,2 @@ +FLASK_APP=app.py +FLASK_DEBUG=1 \ No newline at end of file diff --git a/main.py b/main.py index b6dfda6..1bbab8b 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,135 @@ -from flask import Flask, render_template +from flask import Flask, render_template, jsonify, request +from supabase_py import create_client +from flask_cors import CORS +# App setup app = Flask(__name__) +CORS(app) + +# Supabase Client +SUPABASE_URL = ' ' +SUPABASE_KEY = " " +supabase = create_client(SUPABASE_URL, SUPABASE_KEY) + +# Lists, structs & development environment setup -> mirror of data/content server-side +itemList = { # This should be automated in the `/items` route later + 11: {"name": "Coal", "type": "Minerals"}, + 13: {"name": "Silicates", "type": "Minerals"}, + 15: {"name": "Iron", "type": "Minerals"}, + 17: {"name": "Alloy", "type": "Minerals"}, + 18: {"name": "Fuel", "type": "Minerals"}, + 19: {"name": "Copper", "type": "Minerals"}, + 20: {"name": "Chromium", "type": "Minerals"}, + 16: {"name": "Nickel", "type": "Minerals"}, + 21: {"name": "Water", "type": "Minerals"}, + 14: {"name": "Transiting Telescope", "type": "Structure"}, + 12: {"name": "Telescope Signal Receiver", "type": "Structure"}, +} + +crafting_recipes = [ + {"input": [(11, 1), (13, 1)], "output": (14, 1)}, # Coal + Silicates = Transiting Telescope +] + +# Routes/requests @app.route('/') def index(): return render_template('index.html') +# Route to fetch items from inventoryITEMS table +@app.route('/items') +def get_items(): + # Query items from inventoryITEMS table + items = supabase.table('inventoryITEMS').select('*').execute() + return jsonify(items['data'], itemList) + +# Route to fetch user inventory from inventoryUSERS table +@app.route('/inventory/') +def get_user_inventory(user_id): + # Query user inventory from inventoryUSERS table + user_inventory = supabase.table('inventoryUSERS').select('*').eq('owner', user_id).execute() + return jsonify(user_inventory['data'] + itemList) + +@app.route('/craft_structure', methods=['POST']) # In this method, the actual crafting/removal of items would be done in the `client` repo +def craft_structure(): + data = request.json + user_id = data.get('user_id') + structure_id = data.get('structure_id') + + # Retrieve the crafting recipe for the specified structure + recipe = next((recipe for recipe in crafting_recipes if recipe['output'][0] == structure_id), None) + + if recipe is None: + return jsonify({'status': 'fail', 'message': 'Invalid structure ID'}), 400 + + # Check if the user has the required items in their inventory + user_inventory = supabase.table('inventoryUSERS').select('item', 'quantity').eq('owner', user_id).execute() + items_needed = recipe['input'] + items_available = {item['item']: item['quantity'] for item in user_inventory['data']} + + for item_id, quantity_needed in items_needed: + if item_id not in items_available or items_available[item_id] < quantity_needed: + return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}), 400 + + """ + # If the user has the required items, deduct them from the inventory + for item_id, quantity_needed in items_needed: + # Reduce the quantity of the item in the inventory + for item in user_inventory['data']: + if item['item'] == item_id: + remaining_quantity = item['quantity'] - quantity_needed + supabase.table('inventoryUSERS').update({'quantity': remaining_quantity}).eq('owner', user_id).eq('item', item_id).execute() + break + """ + + # Add the crafted structure to the user's inventory + supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1}).execute() + + return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 + # Get user id and structure id from the request + data = request.get_json() + user_id = data.get('user_id') + structure_id = data.get('structure_id') + + # Find the crafting recipe for the specified structure + recipe = None + for crafting_recipe in crafting_recipes: + if crafting_recipe['output'][0] == structure_id: + recipe = crafting_recipe + break + + if not recipe: + return jsonify({'status': 'fail', 'message': 'Structure not found'}) + + # Check if the user has enough of each required item + for item_id, quantity in recipe['input']: + user_items = supabase.table('inventoryUSERS').select('quantity').eq('owner', user_id).eq('item', item_id).execute() + total_quantity = sum([item['quantity'] for item in user_items['data']]) + if total_quantity < quantity: + return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}) + + # Calculate quantities to be deducted from the inventory + deductions = [] + for item_id, quantity in recipe['input']: + quantity_to_deduct = quantity + user_items = supabase.table('inventoryUSERS').select('id', 'quantity').eq('owner', user_id).eq('item', item_id).execute() + for item in user_items['data']: + if item['quantity'] >= quantity_to_deduct: + deductions.append({'id': item['id'], 'quantity': quantity_to_deduct}) + break + else: + quantity_to_deduct -= item['quantity'] + deductions.append({'id': item['id'], 'quantity': item['quantity']}) + + # Construct the response + response = { + 'status': 'proceed', + 'message': 'User can craft the structure', + 'deductions': deductions + } + + return jsonify(response) + +# Main function to run the Flask app. if __name__ == '__main__': app.run(port=5000) diff --git a/requirements.txt b/requirements.txt index 4431900..d9a8094 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ flask>=2.0.0 gunicorn>=20.1.0 +lightkurve +supabase_py +flask_cors \ No newline at end of file diff --git a/app.txt b/test.py similarity index 100% rename from app.txt rename to test.py diff --git a/tests/kurve-parse.py b/tests/kurve-parse.py new file mode 100644 index 0000000..bce1d86 --- /dev/null +++ b/tests/kurve-parse.py @@ -0,0 +1,52 @@ +from flask import Flask, jsonify, request +import requests +import psycopg2 +import lightkurve as lk +import matplotlib.pyplot as plt +from thirdweb import ThirdwebSDK + +# Flask Initialisation +app = Flask(__name__) + +# Lightcurve initialisation +planetTic = "" + +# Contract Initialisation +sdk = ThirdwebSDK("mumbai") +contract = sdk.get_contract("0xed6e837Fda815FBf78E8E7266482c5Be80bC4bF9") +_receiver = "" +_tokenId = 0 +_quantity = 0 +data = contract.call("claim", 0xCdc5929e1158F7f0B320e3B942528E6998D8b25c, 2, 1) + +# Flask/api routes +@app.route('/planet') +def planet(): + return jsonify({'planet' : 'planet'}) + +@app.post('/select_planet') +def select_planet(): + data = request.get_json() + planetId = data['planetId'] + planetName = data['planetName'] + planetTic = data['planetTic'] + sector_data = lk.search_lightcurve(planetTic, author = 'SPOC', sector = 23) + #lc = sector_data.download() + #lc.plot() + return sector_data + +# Show planet data on frontend +@app.post('/show_planet') # Can we do some calculation for nft revealing using this (i.e. mint nft after classification) +def show_tic(): + lc = sector_data.plot() + return lc + +@app.post('/mint-planet') +def mint_planet(): + data = request.get_json() + _receiver = data['profileAddress'] + _tokenId = data['tokenId'] + _quantity = 1 + data = contract.call("claim", _receiver, _tokenId, _quantity) + +app.run(host='0.0.0.0', port=8080) \ No newline at end of file From b09729366aeb61bc8e8877b6e75b5a677bb2acdb Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Sat, 27 Jan 2024 17:59:57 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=90=A6=E2=80=8D=E2=AC=9B=F0=9F=8E=80?= =?UTF-8?q?=20=E2=86=9D=20Structure=20crafted=20successfully?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 105 ++++++++---------------------------------- requirements.txt | 3 +- test.py | 117 +++++++---------------------------------------- 3 files changed, 38 insertions(+), 187 deletions(-) diff --git a/main.py b/main.py index 1bbab8b..3336794 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,15 @@ -from flask import Flask, render_template, jsonify, request +from flask import Flask, jsonify, request from supabase_py import create_client -from flask_cors import CORS -# App setup app = Flask(__name__) -CORS(app) -# Supabase Client -SUPABASE_URL = ' ' -SUPABASE_KEY = " " +# Initialize Supabase client +SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' +SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk' supabase = create_client(SUPABASE_URL, SUPABASE_KEY) -# Lists, structs & development environment setup -> mirror of data/content server-side -itemList = { # This should be automated in the `/items` route later +# Define item list +item_list = { 11: {"name": "Coal", "type": "Minerals"}, 13: {"name": "Silicates", "type": "Minerals"}, 15: {"name": "Iron", "type": "Minerals"}, @@ -26,110 +23,48 @@ 12: {"name": "Telescope Signal Receiver", "type": "Structure"}, } +# Define crafting recipes crafting_recipes = [ {"input": [(11, 1), (13, 1)], "output": (14, 1)}, # Coal + Silicates = Transiting Telescope ] -# Routes/requests - -@app.route('/') -def index(): - return render_template('index.html') - # Route to fetch items from inventoryITEMS table -@app.route('/items') +@app.route('/items', methods=['GET']) def get_items(): - # Query items from inventoryITEMS table - items = supabase.table('inventoryITEMS').select('*').execute() - return jsonify(items['data'], itemList) + return jsonify(item_list) # Route to fetch user inventory from inventoryUSERS table -@app.route('/inventory/') +@app.route('/inventory/', methods=['GET']) def get_user_inventory(user_id): - # Query user inventory from inventoryUSERS table user_inventory = supabase.table('inventoryUSERS').select('*').eq('owner', user_id).execute() - return jsonify(user_inventory['data'] + itemList) + return jsonify(user_inventory['data']) -@app.route('/craft_structure', methods=['POST']) # In this method, the actual crafting/removal of items would be done in the `client` repo +# Route to craft structure +@app.route('/craft_structure', methods=['POST']) def craft_structure(): data = request.json user_id = data.get('user_id') structure_id = data.get('structure_id') - + # Retrieve the crafting recipe for the specified structure recipe = next((recipe for recipe in crafting_recipes if recipe['output'][0] == structure_id), None) - + if recipe is None: return jsonify({'status': 'fail', 'message': 'Invalid structure ID'}), 400 - + # Check if the user has the required items in their inventory user_inventory = supabase.table('inventoryUSERS').select('item', 'quantity').eq('owner', user_id).execute() items_needed = recipe['input'] items_available = {item['item']: item['quantity'] for item in user_inventory['data']} - + for item_id, quantity_needed in items_needed: if item_id not in items_available or items_available[item_id] < quantity_needed: - return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}), 400 + return jsonify({'status': 'fail', 'message': f'Insufficient {item_list[item_id]["name"]}'}), 400 - """ - # If the user has the required items, deduct them from the inventory - for item_id, quantity_needed in items_needed: - # Reduce the quantity of the item in the inventory - for item in user_inventory['data']: - if item['item'] == item_id: - remaining_quantity = item['quantity'] - quantity_needed - supabase.table('inventoryUSERS').update({'quantity': remaining_quantity}).eq('owner', user_id).eq('item', item_id).execute() - break - """ - # Add the crafted structure to the user's inventory supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1}).execute() - - return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 - # Get user id and structure id from the request - data = request.get_json() - user_id = data.get('user_id') - structure_id = data.get('structure_id') - - # Find the crafting recipe for the specified structure - recipe = None - for crafting_recipe in crafting_recipes: - if crafting_recipe['output'][0] == structure_id: - recipe = crafting_recipe - break - if not recipe: - return jsonify({'status': 'fail', 'message': 'Structure not found'}) - - # Check if the user has enough of each required item - for item_id, quantity in recipe['input']: - user_items = supabase.table('inventoryUSERS').select('quantity').eq('owner', user_id).eq('item', item_id).execute() - total_quantity = sum([item['quantity'] for item in user_items['data']]) - if total_quantity < quantity: - return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}) - - # Calculate quantities to be deducted from the inventory - deductions = [] - for item_id, quantity in recipe['input']: - quantity_to_deduct = quantity - user_items = supabase.table('inventoryUSERS').select('id', 'quantity').eq('owner', user_id).eq('item', item_id).execute() - for item in user_items['data']: - if item['quantity'] >= quantity_to_deduct: - deductions.append({'id': item['id'], 'quantity': quantity_to_deduct}) - break - else: - quantity_to_deduct -= item['quantity'] - deductions.append({'id': item['id'], 'quantity': item['quantity']}) - - # Construct the response - response = { - 'status': 'proceed', - 'message': 'User can craft the structure', - 'deductions': deductions - } - - return jsonify(response) + return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 -# Main function to run the Flask app. if __name__ == '__main__': - app.run(port=5000) + app.run(debug=True) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index d9a8094..294ffed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ flask>=2.0.0 gunicorn>=20.1.0 lightkurve supabase_py -flask_cors \ No newline at end of file +flask_cors +supabase-py==2.3.5 diff --git a/test.py b/test.py index 6f0f2c4..3336794 100644 --- a/test.py +++ b/test.py @@ -1,19 +1,15 @@ from flask import Flask, jsonify, request from supabase_py import create_client -from flask_cors import CORS app = Flask(__name__) -CORS(app) -# app.config["SQLALCHEMY_DATABASE_URI"] = "postgres://postgres.qw" -# db.init_app(app) - -# Create Supabase client +# Initialize Supabase client SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk' supabase = create_client(SUPABASE_URL, SUPABASE_KEY) -itemList = { # This should be automated in the `/items` route later +# Define item list +item_list = { 11: {"name": "Coal", "type": "Minerals"}, 13: {"name": "Silicates", "type": "Minerals"}, 15: {"name": "Iron", "type": "Minerals"}, @@ -27,129 +23,48 @@ 12: {"name": "Telescope Signal Receiver", "type": "Structure"}, } +# Define crafting recipes crafting_recipes = [ {"input": [(11, 1), (13, 1)], "output": (14, 1)}, # Coal + Silicates = Transiting Telescope ] # Route to fetch items from inventoryITEMS table -@app.route('/items') +@app.route('/items', methods=['GET']) def get_items(): - # Query items from inventoryITEMS table - items = supabase.table('inventoryITEMS').select('*').execute() - return jsonify(items['data'], itemList) + return jsonify(item_list) # Route to fetch user inventory from inventoryUSERS table -@app.route('/inventory/') +@app.route('/inventory/', methods=['GET']) def get_user_inventory(user_id): - # Query user inventory from inventoryUSERS table user_inventory = supabase.table('inventoryUSERS').select('*').eq('owner', user_id).execute() - return jsonify(user_inventory['data'] + itemList) + return jsonify(user_inventory['data']) -@app.route('/craft_structure', methods=['POST']) # In this method, the actual crafting/removal of items would be done in the `client` repo +# Route to craft structure +@app.route('/craft_structure', methods=['POST']) def craft_structure(): data = request.json user_id = data.get('user_id') structure_id = data.get('structure_id') - + # Retrieve the crafting recipe for the specified structure recipe = next((recipe for recipe in crafting_recipes if recipe['output'][0] == structure_id), None) - + if recipe is None: return jsonify({'status': 'fail', 'message': 'Invalid structure ID'}), 400 - + # Check if the user has the required items in their inventory user_inventory = supabase.table('inventoryUSERS').select('item', 'quantity').eq('owner', user_id).execute() items_needed = recipe['input'] items_available = {item['item']: item['quantity'] for item in user_inventory['data']} - + for item_id, quantity_needed in items_needed: if item_id not in items_available or items_available[item_id] < quantity_needed: - return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}), 400 + return jsonify({'status': 'fail', 'message': f'Insufficient {item_list[item_id]["name"]}'}), 400 - """ - # If the user has the required items, deduct them from the inventory - for item_id, quantity_needed in items_needed: - # Reduce the quantity of the item in the inventory - for item in user_inventory['data']: - if item['item'] == item_id: - remaining_quantity = item['quantity'] - quantity_needed - supabase.table('inventoryUSERS').update({'quantity': remaining_quantity}).eq('owner', user_id).eq('item', item_id).execute() - break - """ - # Add the crafted structure to the user's inventory supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1}).execute() - - return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 - # Get user id and structure id from the request - data = request.get_json() - user_id = data.get('user_id') - structure_id = data.get('structure_id') - - # Find the crafting recipe for the specified structure - recipe = None - for crafting_recipe in crafting_recipes: - if crafting_recipe['output'][0] == structure_id: - recipe = crafting_recipe - break - - if not recipe: - return jsonify({'status': 'fail', 'message': 'Structure not found'}) - - # Check if the user has enough of each required item - for item_id, quantity in recipe['input']: - user_items = supabase.table('inventoryUSERS').select('quantity').eq('owner', user_id).eq('item', item_id).execute() - total_quantity = sum([item['quantity'] for item in user_items['data']]) - if total_quantity < quantity: - return jsonify({'status': 'fail', 'message': f'Insufficient {itemList[item_id]["name"]}'}) - - # Calculate quantities to be deducted from the inventory - deductions = [] - for item_id, quantity in recipe['input']: - quantity_to_deduct = quantity - user_items = supabase.table('inventoryUSERS').select('id', 'quantity').eq('owner', user_id).eq('item', item_id).execute() - for item in user_items['data']: - if item['quantity'] >= quantity_to_deduct: - deductions.append({'id': item['id'], 'quantity': quantity_to_deduct}) - break - else: - quantity_to_deduct -= item['quantity'] - deductions.append({'id': item['id'], 'quantity': item['quantity']}) - - # Construct the response - response = { - 'status': 'proceed', - 'message': 'User can craft the structure', - 'deductions': deductions - } - return jsonify(response) -""" -# class InventoryUsers(db.Model): -# __tablename__ = 'inventoryUSERS' - -# id = db.Column(db.BigInteger, primary_key=True) -# item = db.Column(db.BigInteger, db.ForeignKey('inventoryITEMS.id')) -# owner = db.Column(db.String, db.ForeignKey('profiles.id')) -# quantity = db.Column(db.Float) -# location = db.Column(db.BigInteger, db.ForeignKey('inventoryPLANETS.id')) -# sector = db.Column(db.BigInteger, db.ForeignKey('basePlanetSectors.id')) -# planetSector = db.Column(db.BigInteger, db.ForeignKey('basePlanetSectors.id')) - -# class InventoryItems(db.Model): -# __tablename__ = 'inventoryITEMS' - -# id = db.Column(db.BigInteger, primary_key=True) -# name = db.Column(db.String) -# description = db.Column(db.Text) -# cost = db.Column(db.Integer) -# icon_url = db.Column(db.String) -# ItemCategory = db.Column(db.String) -# parentItem = db.Column(db.BigInteger) -# itemLevel = db.Column(db.Float, default=1.0) -# oldAssets = db.Column(db.ARRAY(db.Text)) -""" + return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 -# Main function to run the Flask app if __name__ == '__main__': app.run(debug=True) \ No newline at end of file From 44181b6ab40b706191f1dbcc223a8b8331678820 Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Sun, 28 Jan 2024 18:54:28 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=8C=AF=F0=9F=A5=95=20=E2=86=9D=20Samp?= =?UTF-8?q?le=20app=20for=20re-deployment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 70 +++++---------------------------------------------------- 1 file changed, 5 insertions(+), 65 deletions(-) diff --git a/main.py b/main.py index 3336794..39393b1 100644 --- a/main.py +++ b/main.py @@ -1,70 +1,10 @@ -from flask import Flask, jsonify, request -from supabase_py import create_client +from flask import Flask, render_template app = Flask(__name__) -# Initialize Supabase client -SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' -SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk' -supabase = create_client(SUPABASE_URL, SUPABASE_KEY) - -# Define item list -item_list = { - 11: {"name": "Coal", "type": "Minerals"}, - 13: {"name": "Silicates", "type": "Minerals"}, - 15: {"name": "Iron", "type": "Minerals"}, - 17: {"name": "Alloy", "type": "Minerals"}, - 18: {"name": "Fuel", "type": "Minerals"}, - 19: {"name": "Copper", "type": "Minerals"}, - 20: {"name": "Chromium", "type": "Minerals"}, - 16: {"name": "Nickel", "type": "Minerals"}, - 21: {"name": "Water", "type": "Minerals"}, - 14: {"name": "Transiting Telescope", "type": "Structure"}, - 12: {"name": "Telescope Signal Receiver", "type": "Structure"}, -} - -# Define crafting recipes -crafting_recipes = [ - {"input": [(11, 1), (13, 1)], "output": (14, 1)}, # Coal + Silicates = Transiting Telescope -] - -# Route to fetch items from inventoryITEMS table -@app.route('/items', methods=['GET']) -def get_items(): - return jsonify(item_list) - -# Route to fetch user inventory from inventoryUSERS table -@app.route('/inventory/', methods=['GET']) -def get_user_inventory(user_id): - user_inventory = supabase.table('inventoryUSERS').select('*').eq('owner', user_id).execute() - return jsonify(user_inventory['data']) - -# Route to craft structure -@app.route('/craft_structure', methods=['POST']) -def craft_structure(): - data = request.json - user_id = data.get('user_id') - structure_id = data.get('structure_id') - - # Retrieve the crafting recipe for the specified structure - recipe = next((recipe for recipe in crafting_recipes if recipe['output'][0] == structure_id), None) - - if recipe is None: - return jsonify({'status': 'fail', 'message': 'Invalid structure ID'}), 400 - - # Check if the user has the required items in their inventory - user_inventory = supabase.table('inventoryUSERS').select('item', 'quantity').eq('owner', user_id).execute() - items_needed = recipe['input'] - items_available = {item['item']: item['quantity'] for item in user_inventory['data']} - - for item_id, quantity_needed in items_needed: - if item_id not in items_available or items_available[item_id] < quantity_needed: - return jsonify({'status': 'fail', 'message': f'Insufficient {item_list[item_id]["name"]}'}), 400 - - # Add the crafted structure to the user's inventory - supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1}).execute() - - return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 +@app.route('/') +def index(): + return render_template('index.html') if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + app.run(port=5000) \ No newline at end of file From fc25f9e594b9ad051e94f895f3247e4283f10f07 Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Mon, 29 Jan 2024 18:55:58 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=98=8A=F0=9F=91=A8=F0=9F=8F=BB?= =?UTF-8?q?=E2=80=8D=E2=9A=96=EF=B8=8F=20=E2=86=9D=20Sample=20app=20for=20?= =?UTF-8?q?re-deployment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 294ffed..0d185cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ gunicorn>=20.1.0 lightkurve supabase_py flask_cors -supabase-py==2.3.5 From 4812d91702cca3dae601c49563b1ccf8f705f66e Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Tue, 30 Jan 2024 20:49:41 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=99=8A=F0=9F=9A=9F=20=E2=86=9D=20Samp?= =?UTF-8?q?le=20app=20for=20re-deployment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 39393b1..3336794 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,70 @@ -from flask import Flask, render_template +from flask import Flask, jsonify, request +from supabase_py import create_client app = Flask(__name__) -@app.route('/') -def index(): - return render_template('index.html') +# Initialize Supabase client +SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' +SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk' +supabase = create_client(SUPABASE_URL, SUPABASE_KEY) + +# Define item list +item_list = { + 11: {"name": "Coal", "type": "Minerals"}, + 13: {"name": "Silicates", "type": "Minerals"}, + 15: {"name": "Iron", "type": "Minerals"}, + 17: {"name": "Alloy", "type": "Minerals"}, + 18: {"name": "Fuel", "type": "Minerals"}, + 19: {"name": "Copper", "type": "Minerals"}, + 20: {"name": "Chromium", "type": "Minerals"}, + 16: {"name": "Nickel", "type": "Minerals"}, + 21: {"name": "Water", "type": "Minerals"}, + 14: {"name": "Transiting Telescope", "type": "Structure"}, + 12: {"name": "Telescope Signal Receiver", "type": "Structure"}, +} + +# Define crafting recipes +crafting_recipes = [ + {"input": [(11, 1), (13, 1)], "output": (14, 1)}, # Coal + Silicates = Transiting Telescope +] + +# Route to fetch items from inventoryITEMS table +@app.route('/items', methods=['GET']) +def get_items(): + return jsonify(item_list) + +# Route to fetch user inventory from inventoryUSERS table +@app.route('/inventory/', methods=['GET']) +def get_user_inventory(user_id): + user_inventory = supabase.table('inventoryUSERS').select('*').eq('owner', user_id).execute() + return jsonify(user_inventory['data']) + +# Route to craft structure +@app.route('/craft_structure', methods=['POST']) +def craft_structure(): + data = request.json + user_id = data.get('user_id') + structure_id = data.get('structure_id') + + # Retrieve the crafting recipe for the specified structure + recipe = next((recipe for recipe in crafting_recipes if recipe['output'][0] == structure_id), None) + + if recipe is None: + return jsonify({'status': 'fail', 'message': 'Invalid structure ID'}), 400 + + # Check if the user has the required items in their inventory + user_inventory = supabase.table('inventoryUSERS').select('item', 'quantity').eq('owner', user_id).execute() + items_needed = recipe['input'] + items_available = {item['item']: item['quantity'] for item in user_inventory['data']} + + for item_id, quantity_needed in items_needed: + if item_id not in items_available or items_available[item_id] < quantity_needed: + return jsonify({'status': 'fail', 'message': f'Insufficient {item_list[item_id]["name"]}'}), 400 + + # Add the crafted structure to the user's inventory + supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1}).execute() + + return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 if __name__ == '__main__': - app.run(port=5000) \ No newline at end of file + app.run(debug=True) \ No newline at end of file From 3c8c77f98d5bb1b6d3e00caf579dd90c40f49a0d Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Thu, 1 Feb 2024 21:53:10 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=91=A6=E2=80=8D?= =?UTF-8?q?=F0=9F=91=A6=F0=9F=AA=B7=20=E2=86=9D=20CORS=20for=20testing=20w?= =?UTF-8?q?ith=20local=20client/web=20app=20[=20GP-11=20GP-10=20]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 ++ test.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/main.py b/main.py index 3336794..fbb05f3 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,9 @@ from flask import Flask, jsonify, request from supabase_py import create_client +from flask_cors import CORS app = Flask(__name__) +CORS(app) # Initialize Supabase client SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' diff --git a/test.py b/test.py index 3336794..fbb05f3 100644 --- a/test.py +++ b/test.py @@ -1,7 +1,9 @@ from flask import Flask, jsonify, request from supabase_py import create_client +from flask_cors import CORS app = Flask(__name__) +CORS(app) # Initialize Supabase client SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' From 053135575fd31c8423f48e92a6bc5977f9e1d0a4 Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Sat, 3 Feb 2024 00:30:36 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=AA=B8=F0=9F=A4=B8=F0=9F=8F=BB?= =?UTF-8?q?=E2=80=8D=E2=99=82=EF=B8=8F=20=E2=86=9D=20I=20just=20realised?= =?UTF-8?q?=20that=20the=20sector=20isn't=20configured...until=20now=20GP-?= =?UTF-8?q?10=20CPW-2=20CPW-8=20GP-11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index fbb05f3..e97c5c6 100644 --- a/main.py +++ b/main.py @@ -47,7 +47,8 @@ def craft_structure(): data = request.json user_id = data.get('user_id') structure_id = data.get('structure_id') - + sector_id = data.get('sector_id') # Added sector ID + # Retrieve the crafting recipe for the specified structure recipe = next((recipe for recipe in crafting_recipes if recipe['output'][0] == structure_id), None) @@ -64,7 +65,7 @@ def craft_structure(): return jsonify({'status': 'fail', 'message': f'Insufficient {item_list[item_id]["name"]}'}), 400 # Add the crafted structure to the user's inventory - supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1}).execute() + supabase.table('inventoryUSERS').insert({'item': structure_id, 'owner': user_id, 'quantity': 1, 'sector': sector_id}).execute() # Added sector ID return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200