Compare commits
3 Commits
4ed1dc9d31
...
f5fe578a88
| Author | SHA1 | Date | |
|---|---|---|---|
| f5fe578a88 | |||
| 1e024cc937 | |||
| 656e9257cc |
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
.idea/
|
||||
|
||||
.env
|
||||
src/.DS_Store
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
from minio import Minio
|
||||
from random import randint
|
||||
import dbwork
|
||||
import DBwork
|
||||
import config
|
||||
|
||||
def _setClient():
|
||||
minio_client = Minio(
|
||||
"localhost:9000",
|
||||
access_key="minioadmin",
|
||||
secret_key="minioadmin",
|
||||
secure=False
|
||||
config.IS_address,
|
||||
access_key = config.acc_key,
|
||||
secret_key = config.sec_key,
|
||||
secure = False
|
||||
)
|
||||
return minio_client
|
||||
|
||||
@ -23,12 +24,12 @@ def downloadImage(currentDay, username):
|
||||
client.fget_object(bucket_name, getImageName(currentDay), username + '.jpeg')
|
||||
|
||||
def downloadForAll(currentDay):
|
||||
cur, conn = DBwork.set_connection()
|
||||
counter = 1
|
||||
user = dbwork.get_user(counter)
|
||||
user = DBwork.get_user(counter, cur)
|
||||
while(user != 'Error'):
|
||||
downloadImage(currentDay, user)
|
||||
counter += 1
|
||||
user = dbwork.get_user(counter)
|
||||
user = DBwork.get_user(counter, cur)
|
||||
DBwork.close_connection(conn, cur)
|
||||
|
||||
Day = 'Tuesday'
|
||||
downloadForAll(Day)
|
||||
8
src/Backend/config.py
Normal file
8
src/Backend/config.py
Normal file
@ -0,0 +1,8 @@
|
||||
IS_address = "localhost:9000"
|
||||
acc_key = "minioadmin"
|
||||
sec_key = "minioadmin"
|
||||
db_name = "postgres_db"
|
||||
postgres_user = "postgres_user"
|
||||
postgres_password = "postgres_password"
|
||||
host_name = "localhost"
|
||||
port = "5430"
|
||||
@ -1,67 +1,47 @@
|
||||
import psycopg2
|
||||
import config
|
||||
|
||||
def _get_last_id(cursor):
|
||||
cursor.execute("SELECT MAX(id) FROM usernames")
|
||||
id = cursor.fetchall()[0][0]
|
||||
return id
|
||||
|
||||
def add_user(username):
|
||||
def set_connection():
|
||||
connection = psycopg2.connect(
|
||||
dbname="postgres_db",
|
||||
user="postgres_user",
|
||||
password="postgres_password",
|
||||
host="localhost",
|
||||
port="5430"
|
||||
dbname = config.db_name,
|
||||
user = config.postgres_user,
|
||||
password = config.postgres_password,
|
||||
host = config.host_name,
|
||||
port = config.port
|
||||
)
|
||||
cursor = connection.cursor()
|
||||
return cursor, connection
|
||||
|
||||
def close_connection(connection, cursor):
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
#Functions don't close connection automatically, it has to be closed manually
|
||||
def add_user(username, connection, cursor):
|
||||
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"
|
||||
)
|
||||
def delete_user(username, connection, cursor):
|
||||
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"
|
||||
)
|
||||
def change_name(old_username, new_username, connection, cursor):
|
||||
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()
|
||||
def get_user(id, 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
|
||||
return username, cursor
|
||||
|
||||
Reference in New Issue
Block a user