Compare commits
10 Commits
2ecf7ae56d
...
1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 86a03647df | |||
| 73da634029 | |||
| 9424276474 | |||
| 7949312f9a | |||
| f814a1ba00 | |||
| a910bffcc9 | |||
| 06e24e35e1 | |||
| 523ac2228d | |||
| 95a232fb78 | |||
| 355aff8cf3 |
@ -8,8 +8,8 @@ services:
|
||||
DB_NAME: postgres
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
HOST_NAME: "localhost"
|
||||
PG_PORT: "8000"
|
||||
HOST_NAME: postgres
|
||||
PG_PORT: 5432
|
||||
LOGGING_LEVEL: "INFO"
|
||||
ENABLE_API_DOCS: "True"
|
||||
UVI_LOGGING_LEVEL: "info"
|
||||
@ -27,7 +27,7 @@ services:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
ports:
|
||||
- "4001:5432"
|
||||
- :5432
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "postgres"]
|
||||
interval: 5s
|
||||
|
||||
@ -2,10 +2,12 @@ FROM python:3.13-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev build-essential
|
||||
|
||||
COPY requirements.txt ./
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["python", "src/main.py"]
|
||||
|
||||
@ -17,6 +17,7 @@ def set_connection():
|
||||
logger.info('Connection to PostreSQL DB set successfully')
|
||||
except psycopg2.Error as e:
|
||||
logger.error(f'Failed to set connection to the PostgreSQL DB: {e.pgerror}')
|
||||
exit()
|
||||
|
||||
|
||||
def close_connection(connection):
|
||||
|
||||
@ -12,12 +12,15 @@ if config.enable_api_docs:
|
||||
else:
|
||||
docs_url = None
|
||||
|
||||
schema_name = 'harticle'
|
||||
table_name = 'articles'
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
DBwork.set_connection()
|
||||
DBwork.schema_creator(config.schema_name, db.connection)
|
||||
DBwork.table_creator(config.schema_name, config.table_name, db.connection)
|
||||
DBwork.schema_creator(schema_name, db.connection)
|
||||
DBwork.table_creator(schema_name, table_name, db.connection)
|
||||
yield
|
||||
DBwork.close_connection(db.connection)
|
||||
|
||||
|
||||
@ -6,8 +6,6 @@ postgres_user = config('POSTGRES_USER')
|
||||
postgres_password = config('POSTGRES_PASSWORD')
|
||||
host_name = config('HOST_NAME')
|
||||
port = config('PG_PORT')
|
||||
schema_name = config('SCHEMA_NAME')
|
||||
table_name = config('TABLE_NAME')
|
||||
|
||||
enable_api_docs = config('ENABLE_API_DOCS', cast=bool)
|
||||
|
||||
|
||||
@ -5,4 +5,4 @@ from app_creator import create_app
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = create_app()
|
||||
uvicorn.run(app=app, host="127.0.0.1", port=8000, log_level=uvicorn_logging_level.lower())
|
||||
uvicorn.run(app=app, host="0.0.0.0", port=8000, log_level=uvicorn_logging_level.lower())
|
||||
|
||||
@ -11,6 +11,7 @@ router = APIRouter(prefix='/api')
|
||||
|
||||
|
||||
class Entry(BaseModel):
|
||||
username: str
|
||||
url: str
|
||||
rating: int | None = None
|
||||
|
||||
@ -47,6 +48,7 @@ async def save_rating(entry: Entry, response: Response):
|
||||
message = 'internal server error'
|
||||
finally:
|
||||
return {'message': message,
|
||||
'username': entry.username,
|
||||
'url': entry.url,
|
||||
'rating': entry.rating
|
||||
}
|
||||
@ -68,14 +70,14 @@ async def remove_rating(entry: Entry, response: Response):
|
||||
async def get_article_html(article: Article, response: Response = None):
|
||||
html_string = await scraper.get_article_html(article.url)
|
||||
b64_string = base64.b64encode(html_string.encode('utf-8')).decode('utf-8')
|
||||
return Response(content=article.url + '\r\n' + b64_string, media_type='text/plain')
|
||||
return {article.url: b64_string}
|
||||
|
||||
|
||||
@router.post('/article/get/md')
|
||||
async def get_article_md(article: Article, response: Response = None):
|
||||
md_string = await scraper.get_article_html(article.url, md=True)
|
||||
b64_string = base64.b64encode(md_string.encode('utf-8')).decode('utf-8')
|
||||
return Response(content=article.url + '\r\n' + b64_string, media_type='text/plain')
|
||||
return {article.url: b64_string}
|
||||
|
||||
|
||||
@router.post('/articles/get/html')
|
||||
|
||||
Reference in New Issue
Block a user