Skip to content

Commit 99af279

Browse files
committed
first commit
0 parents  commit 99af279

File tree

1,826 files changed

+177774
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,826 files changed

+177774
-0
lines changed

.github/workflows/build.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Docker
2+
3+
on:
4+
# schedule:
5+
# - cron: '28 5 * * *'
6+
push:
7+
branches: [ "main" ]
8+
# Publish semver tags as releases.
9+
tags: [ 'v*.*.*' ]
10+
pull_request:
11+
branches: [ "main" ]
12+
workflow_dispatch: # Allows manual triggering of the workflow
13+
14+
env:
15+
# Use ghcr.io
16+
REGISTRY: ghcr.io
17+
# github.repository as <account>/<repo>
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
21+
jobs:
22+
build:
23+
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Extract version from version.py
34+
run: |
35+
version=$(grep 'version = ' version.py | sed -E "s/version = \"([^\"]+)\"/\1/")
36+
echo "APPLICATION_VERSION=$version" >> $GITHUB_ENV
37+
38+
- name: Log in to the Container registry
39+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
40+
with:
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
# Extract metadata (tags, labels) for Docker
46+
# https://github.com/docker/metadata-action
47+
- name: Extract metadata (tags, labels) for Docker
48+
id: meta
49+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
50+
with:
51+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
52+
tags: |
53+
type=ref,event=branch
54+
type=raw,value=${{ env.APPLICATION_VERSION }}
55+
56+
# Build and push Docker image with Buildx (don't push on PR)
57+
# https://github.com/docker/build-push-action
58+
- name: Build and push Docker image
59+
id: build-and-push
60+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
61+
with:
62+
context: .
63+
push: true
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}
66+
67+
- name: Output image digest
68+
id: output-digest
69+
run: |
70+
echo "##[group]Digest"
71+
echo "digest: ${{ steps.build-and-push.outputs.digest }} size:"
72+
echo "##[endgroup]"

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.10
2+
3+
WORKDIR /app
4+
COPY . /app
5+
6+
RUN apt-get update && apt-get upgrade -y && apt-get clean
7+
8+
# Upgrade pip to latest version
9+
RUN pip install --upgrade pip
10+
RUN pip3 install -r requirements.txt
11+
12+
# Ensure SQLite is installed
13+
RUN apt-get install -y sqlite3
14+
15+
EXPOSE 5000
16+
17+
HEALTHCHECK CMD curl --fail http://localhost:5000 || exit 1
18+
19+
CMD python ./index.py
20+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PYTHON FLASK DYNAMODB

index.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from flask import Flask, render_template, request, redirect, url_for, flash, jsonify
2+
import sqlite3
3+
from version import version
4+
import os
5+
6+
app = Flask(__name__)
7+
app.secret_key = "supersecretkey"
8+
9+
DATABASE = 'database.db'
10+
11+
def get_db():
12+
conn = sqlite3.connect(DATABASE)
13+
conn.row_factory = sqlite3.Row
14+
return conn
15+
16+
def init_db():
17+
conn = get_db()
18+
with app.open_resource('schema.sql', mode='r') as f:
19+
conn.cursor().executescript(f.read())
20+
conn.commit()
21+
22+
@app.route('/')
23+
def index():
24+
conn = get_db()
25+
cur = conn.cursor()
26+
cur.execute("SELECT * FROM customers_data")
27+
customers = cur.fetchall()
28+
return render_template('index.html', customers=customers)
29+
30+
@app.route('/customer/new', methods=['GET', 'POST'])
31+
def new_customer():
32+
if request.method == 'POST':
33+
conn = get_db()
34+
cur = conn.cursor()
35+
customer = (
36+
request.form['name'],
37+
request.form['phone'],
38+
request.form['address'],
39+
request.form['contact']
40+
)
41+
cur.execute("INSERT INTO customers_data (name, phone, address, contact) VALUES (?, ?, ?, ?)", customer)
42+
conn.commit()
43+
flash('Customer added successfully!', 'success')
44+
return redirect(url_for('index'))
45+
return render_template('new_customer.html')
46+
47+
@app.route('/customer/edit/<id>', methods=['GET', 'POST'])
48+
def edit_customer(id):
49+
conn = get_db()
50+
cur = conn.cursor()
51+
if request.method == 'POST':
52+
updated_customer = (
53+
request.form['name'],
54+
request.form['phone'],
55+
request.form['address'],
56+
request.form['contact'],
57+
id
58+
)
59+
cur.execute("UPDATE customers_data SET name = ?, phone = ?, address = ?, contact = ? WHERE id = ?", updated_customer)
60+
conn.commit()
61+
flash('Customer updated successfully!', 'success')
62+
return redirect(url_for('index'))
63+
cur.execute("SELECT * FROM customers_data WHERE id = ?", (id,))
64+
customer = cur.fetchone()
65+
return render_template('edit_customer.html', customer=customer)
66+
67+
@app.route('/customer/delete/<id>', methods=['POST'])
68+
def delete_customer(id):
69+
conn = get_db()
70+
cur = conn.cursor()
71+
cur.execute("DELETE FROM customers_data WHERE id = ?", (id,))
72+
conn.commit()
73+
flash('Customer deleted successfully!', 'success')
74+
return redirect(url_for('index'))
75+
76+
@app.route('/actuator/info', methods=['GET', 'POST'])
77+
def info():
78+
return jsonify({"build": {"version": version}})
79+
80+
if __name__ == "__main__":
81+
init_db() # Initialize the database before starting the app
82+
app.run(host="0.0.0.0", port=5000, debug=True)

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask
2+
jasypt4py
3+
django==3.2.8

schema.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE IF NOT EXISTS customers_data (
2+
id INTEGER PRIMARY KEY AUTOINCREMENT,
3+
name TEXT NOT NULL,
4+
phone TEXT NOT NULL,
5+
address TEXT NOT NULL,
6+
contact TEXT NOT NULL
7+
);

0 commit comments

Comments
 (0)