my commit
This commit is contained in:
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
34
src/Backend/ISwork.py
Normal file
34
src/Backend/ISwork.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from minio import Minio
|
||||||
|
from random import randint
|
||||||
|
import dbwork
|
||||||
|
|
||||||
|
def _setClient():
|
||||||
|
minio_client = Minio(
|
||||||
|
"localhost:9000",
|
||||||
|
access_key="minioadmin",
|
||||||
|
secret_key="minioadmin",
|
||||||
|
secure=False
|
||||||
|
)
|
||||||
|
return minio_client
|
||||||
|
|
||||||
|
def getImageName(currentDay):
|
||||||
|
maxFiles = 2
|
||||||
|
fileNumber = randint(1, maxFiles)
|
||||||
|
desiredFile = currentDay + '/' + str(fileNumber) + '.jpeg'
|
||||||
|
return desiredFile
|
||||||
|
|
||||||
|
def downloadImage(currentDay, username):
|
||||||
|
bucket_name = "cat-images"
|
||||||
|
client = _setClient()
|
||||||
|
client.fget_object(bucket_name, getImageName(currentDay), username + '.jpeg')
|
||||||
|
|
||||||
|
def downloadForAll(currentDay):
|
||||||
|
counter = 1
|
||||||
|
user = dbwork.get_user(counter)
|
||||||
|
while(user != 'Error'):
|
||||||
|
downloadImage(currentDay, user)
|
||||||
|
counter += 1
|
||||||
|
user = dbwork.get_user(counter)
|
||||||
|
|
||||||
|
Day = 'Tuesday'
|
||||||
|
downloadForAll(Day)
|
||||||
67
src/Backend/dbwork.py
Normal file
67
src/Backend/dbwork.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import psycopg2
|
||||||
|
|
||||||
|
def _get_last_id(cursor):
|
||||||
|
cursor.execute("SELECT MAX(id) FROM usernames")
|
||||||
|
id = cursor.fetchall()[0][0]
|
||||||
|
return id
|
||||||
|
|
||||||
|
def add_user(username):
|
||||||
|
connection = psycopg2.connect(
|
||||||
|
dbname="postgres_db",
|
||||||
|
user="postgres_user",
|
||||||
|
password="postgres_password",
|
||||||
|
host="localhost",
|
||||||
|
port="5430"
|
||||||
|
)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("INSERT INTO usernames VALUES (%s, %s);", (_get_last_id(cursor) + 1, username))
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def delete_user(username):
|
||||||
|
connection = psycopg2.connect(
|
||||||
|
dbname="postgres_db",
|
||||||
|
user="postgres_user",
|
||||||
|
password="postgres_password",
|
||||||
|
host="localhost",
|
||||||
|
port="5430"
|
||||||
|
)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("DELETE FROM usernames WHERE username = %s;", (username,))
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def change_name(old_username, new_username):
|
||||||
|
connection = psycopg2.connect(
|
||||||
|
dbname="postgres_db",
|
||||||
|
user="postgres_user",
|
||||||
|
password="postgres_password",
|
||||||
|
host="localhost",
|
||||||
|
port="5430"
|
||||||
|
)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("UPDATE usernames SET username = %s WHERE username = %s;", (new_username, old_username))
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def get_user(id):
|
||||||
|
connection = psycopg2.connect(
|
||||||
|
dbname="postgres_db",
|
||||||
|
user="postgres_user",
|
||||||
|
password="postgres_password",
|
||||||
|
host="localhost",
|
||||||
|
port="5430"
|
||||||
|
)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
max_id = _get_last_id(cursor)
|
||||||
|
if id <= max_id:
|
||||||
|
cursor.execute("SELECT username FROM usernames WHERE id = %s", (id,))
|
||||||
|
username = cursor.fetchall()[0][0]
|
||||||
|
else:
|
||||||
|
username = 'Error'
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return username
|
||||||
43
src/Backend/docker-compose1.yml
Normal file
43
src/Backend/docker-compose1.yml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
version: '3.9'
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:latest
|
||||||
|
container_name: postgres_container
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: postgres_user
|
||||||
|
POSTGRES_PASSWORD: postgres_password
|
||||||
|
POSTGRES_DB: postgres_db
|
||||||
|
PGDATA: /var/lib/postgresql/data/pgdata
|
||||||
|
ports:
|
||||||
|
- "5430:5432"
|
||||||
|
volumes:
|
||||||
|
- ./pgdata:/var/lib/postgresql/data/pgdata
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '0.50'
|
||||||
|
memory: 512M
|
||||||
|
reservations:
|
||||||
|
cpus: '0.25'
|
||||||
|
memory: 256M
|
||||||
|
command: >
|
||||||
|
postgres -c max_connections=1000
|
||||||
|
-c shared_buffers=256MB
|
||||||
|
-c effective_cache_size=768MB
|
||||||
|
-c maintenance_work_mem=64MB
|
||||||
|
-c checkpoint_completion_target=0.7
|
||||||
|
-c wal_buffers=16MB
|
||||||
|
-c default_statistics_target=100
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD-SHELL", "pg_isready -U postgres_user -d postgres_db" ]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 5
|
||||||
|
restart: unless-stopped
|
||||||
|
tty: true
|
||||||
|
stdin_open: true
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pgdata:
|
||||||
|
driver: local
|
||||||
22
src/Backend/docker-compose2.yml
Normal file
22
src/Backend/docker-compose2.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
version: "3.9"
|
||||||
|
services:
|
||||||
|
minio:
|
||||||
|
image: minio/minio:latest
|
||||||
|
ports:
|
||||||
|
- "9000:9000"
|
||||||
|
- "9001:9001"
|
||||||
|
environment:
|
||||||
|
MINIO_ACCESS_KEY: minioadmin
|
||||||
|
MINIO_SECRET_KEY: minioadmin
|
||||||
|
MINIO_ROOT_USER: minioadmin
|
||||||
|
MINIO_ROOT_PASSWORD: minioadmin
|
||||||
|
MINIO_BROWSER: "on"
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
command: server /data --console-address ":9001"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 20s
|
||||||
|
retries: 3
|
||||||
|
restart: unless-stopped
|
||||||
BIN
src/Frontend/.DS_Store
vendored
Normal file
BIN
src/Frontend/.DS_Store
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user