Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiao committed May 14, 2024
0 parents commit 710148a
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
33 changes: 33 additions & 0 deletions .idx/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


# To learn more about how to use Nix to configure your environment
# see: https://developers.google.com/idx/guides/customize-idx-env
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-23.11"; # or "unstable"
# Use https://search.nixos.org/packages to find packages
packages = [ pkgs.python3 ];
idx = {
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
extensions = [ "ms-python.python" ];
workspace = {
# Runs when a workspace is first created with this `dev.nix` file
onCreate = {
install =
"python -m venv .venv && curl -sSL https://install.python-poetry.org | python -";
};
# To run something each time the environment is rebuilt, use the `onStart` hook
};
# Enable previews and customize configuration
previews = {
enable = true;
previews = {
web = {
command = [ "./devserver.sh" ];
env = { PORT = "$PORT"; };
manager = "web";
};
};
};
};
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Flask

A Flask starter template as per the docs: https://flask.palletsprojects.com/en/3.0.x/quickstart/#a-minimal-application
11 changes: 11 additions & 0 deletions devserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
export PATH="$HOME/.local/bin:$PATH"

poetry install
source .venv/bin/activate

if ! grep -q "$PATH" /home/user/.bashrc; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> /home/user/.bashrc
fi

python -m flask --app src/main run -p $PORT --debug
178 changes: 178 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "python-flask"
version = "0.1.0"
description = "Start a simple web app with the Flask framework for Python"
authors = ["Google LLC"]
packages = [{include = "src"}]

[tool.poetry.dependencies]
python = "^3.11"
Flask = "^3.0.1"

[tool.poetry.scripts]
app = 'src.main:main'

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Binary file added src/__pycache__/main.cpython-311.pyc
Binary file not shown.
12 changes: 12 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hello World</title>
</head>

<body>
<h1>Hello World</h1>
</body>
</html>
33 changes: 33 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

from flask import Flask, send_file

app = Flask(__name__)

@app.route("/")
def index():
return send_file('index.html')

""" Notify receives a GET message
"""
@app.route("/notify")
def notify():
# Get query params
name = request.args.get('name')

# Return a JSON response
return jsonify({'name': name})

""" Notify receives a POST message
"""
@app.route("/notify_post", methods=['POST'])
def notify_post():
#
return jsonify({'name': name})


def main():
app.run(port=int(os.environ.get('PORT', 9005)))

if __name__ == "__main__":
main()

0 comments on commit 710148a

Please sign in to comment.