Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎓💳 ↝ Successful microservice deployment #11

Merged
merged 10 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FLASK_APP=app.py
FLASK_DEBUG=1
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn main:app
121 changes: 4 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,119 +1,6 @@
<div align="center">
<p><a href="https://kee.so/" target="_blank"><img src="https://i.imgur.com/x5SRUoo.png" alt="kee.so" /></a></p>
# 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.

</div>

---

<div align="center">
<h1>Paper <sup><sup><sub>6.21</sub></sup></sup></h1>

Demo → [hugo-paper.vercel.app](https://hugo-paper.vercel.app/)

A simple, clean, customizable Hugo theme.

⚡️ Fast | 👒 Customizable | 🫙 Smooth

</div>

## 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/<USERNAME>/<REPONAME>
```

Add paper theme ad dependency of your site:

```bash
hugo mod init github.com/<USERNAME>/<REPONAME>
```

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)
8 changes: 0 additions & 8 deletions app.py

This file was deleted.

73 changes: 73 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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/<user_id>', 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)
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flask>=2.0.0
gunicorn>=20.1.0
lightkurve
supabase_py
flask_cors
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
72 changes: 72 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -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/<user_id>', 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)
52 changes: 52 additions & 0 deletions tests/kurve-parse.py
Original file line number Diff line number Diff line change
@@ -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)
Loading