Rewritten in go and python

This commit is contained in:
2024-11-06 01:25:27 +04:00
parent 9f22d9678d
commit d8449237bb
50 changed files with 3824 additions and 879 deletions

38
recommender/config.py Normal file
View File

@@ -0,0 +1,38 @@
import os
def get_postgres_dsn():
user = os.getenv('POSTGRES_USER', None)
if user is None:
raise ValueError('POSTGRES_USER is not set')
password = os.getenv('POSTGRES_PASSWORD', None)
if password is None:
raise ValueError('POSTGRES_PASSWORD is not set')
host = os.getenv('POSTGRES_HOST', None)
if host is None:
raise ValueError('POSTGRES_HOST is not set')
port = os.getenv('POSTGRES_PORT', None)
if port is None:
raise ValueError('POSTGRES_PORT is not set')
try:
port = int(port)
except ValueError:
raise ValueError('POSTGRES_PORT is not an integer')
dbname = os.getenv('POSTGRES_DB', None)
if dbname is None:
raise ValueError('POSTGRES_DB is not set')
return f'postgres://{user}:{password}@{host}:{port}/{dbname}?sslmode=disable'
def get_grpc_port():
port = os.getenv('GRPC_PORT', None)
if port is None:
raise ValueError('GRPC_PORT is not set')
try:
port = int(port)
except ValueError:
raise ValueError('GRPC_PORT is not an integer')
return port