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/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/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/main.py b/main.py new file mode 100644 index 0000000..e97c5c6 --- /dev/null +++ b/main.py @@ -0,0 +1,73 @@ +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' +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') + 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) + + 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, 'sector': sector_id}).execute() # Added sector ID + + return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0d185cb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +flask>=2.0.0 +gunicorn>=20.1.0 +lightkurve +supabase_py +flask_cors 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!

+ + diff --git a/test.py b/test.py new file mode 100644 index 0000000..fbb05f3 --- /dev/null +++ b/test.py @@ -0,0 +1,72 @@ +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' +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(debug=True) \ No newline at end of file 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 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" + } +}