Skip to content

Commit

Permalink
1.1.7v
Browse files Browse the repository at this point in the history
Merge pull request #41 from suchencjusz/1.1.7v
  • Loading branch information
suchencjusz authored Dec 3, 2024
2 parents 420cfcf + ff4e205 commit acc3591
Show file tree
Hide file tree
Showing 90 changed files with 579 additions and 324 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![GitHub License](https://img.shields.io/github/license/suchencjusz/filman2) ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/suchencjusz/filman2) ![GitHub Action Docker](https://img.shields.io/github/actions/workflow/status/suchencjusz/filman2/docker-build.yml) ![Black format](https://img.shields.io/badge/code%20style-black-000000.svg)
![Black format](https://img.shields.io/badge/code%20style-black-000000.svg) ![GitHub License](https://img.shields.io/github/license/suchencjusz/filman2) ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/suchencjusz/filman2) ![GitHub Action Docker](https://img.shields.io/github/actions/workflow/status/suchencjusz/filman2/docker-build.yml) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/804ea9aa4ef147688ce59a0ab4342a09)](https://app.codacy.com/gh/suchencjusz/filman2/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)

[Link z zaproszeniem bota na serwer discord](https://discord.com/oauth2/authorize?client_id=1182371658347065394&scope=bot&permissions=2147929152)

Expand Down
Binary file removed prof/combined.prof
Binary file not shown.
Binary file removed prof/test_add_user_to_guild.prof
Binary file not shown.
Binary file removed prof/test_add_watched_movie.prof
Binary file not shown.
Binary file removed prof/test_add_watched_series.prof
Binary file not shown.
Binary file removed prof/test_configure_guild.prof
Binary file not shown.
Binary file removed prof/test_create_filmweb_movie.prof
Binary file not shown.
Binary file removed prof/test_create_filmweb_movie_existing.prof
Binary file not shown.
Binary file removed prof/test_create_filmweb_series.prof
Binary file not shown.
Binary file removed prof/test_create_filmweb_series_existing.prof
Binary file not shown.
Binary file removed prof/test_create_filmweb_watched_movie.prof
Binary file not shown.
Binary file not shown.
Binary file removed prof/test_create_filmweb_watched_series.prof
Binary file not shown.
Binary file not shown.
Binary file removed prof/test_create_task.prof
Binary file not shown.
Binary file removed prof/test_delete_filmweb_mapping.prof
Binary file not shown.
Binary file removed prof/test_delete_filmweb_watched_movies.prof
Binary file not shown.
Binary file removed prof/test_delete_filmweb_watched_series_all.prof
Binary file not shown.
Binary file removed prof/test_delete_guild.prof
Binary file not shown.
Binary file removed prof/test_delete_user_destination.prof
Binary file not shown.
Binary file removed prof/test_delete_user_destinations.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_mapping_by_discord_id.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_mapping_by_discord_id2.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_mapping_by_filmweb_id.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_mapping_by_filmweb_id2.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_mapping_by_user_id.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_mapping_by_user_id2.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_mapping_no_parameters.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_movie_by_id.prof
Binary file not shown.
Binary file removed prof/test_get_filmweb_series_by_id.prof
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed prof/test_get_filmweb_watched_movie_by_id.prof
Binary file not shown.
Binary file not shown.
Binary file removed prof/test_get_filmweb_watched_series_by_id.prof
Binary file not shown.
Binary file not shown.
Binary file removed prof/test_get_guild_by_id.prof
Binary file not shown.
Binary file removed prof/test_get_guild_members.prof
Binary file not shown.
Binary file removed prof/test_get_guilds.prof
Binary file not shown.
Binary file removed prof/test_get_user.prof
Binary file not shown.
Binary file removed prof/test_get_user_by_discord_id.prof
Binary file not shown.
Binary file removed prof/test_get_user_by_filmweb_id.prof
Binary file not shown.
Binary file removed prof/test_get_user_by_id.prof
Binary file not shown.
Binary file removed prof/test_get_user_by_non_existent_discord_id.prof
Binary file not shown.
Binary file removed prof/test_get_user_by_non_existent_filmweb_id.prof
Binary file not shown.
Binary file removed prof/test_get_user_by_non_existent_id.prof
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed prof/test_get_user_destinations_by_user_id.prof
Binary file not shown.
Binary file removed prof/test_get_user_empty_database.prof
Binary file not shown.
Binary file removed prof/test_get_user_no_parameters.prof
Binary file not shown.
Binary file removed prof/test_read_main.prof
Binary file not shown.
Binary file removed prof/test_remove_user_from_all_guilds.prof
Binary file not shown.
Binary file removed prof/test_remove_user_from_guild.prof
Binary file not shown.
Binary file removed prof/test_sentry_debug.prof
Binary file not shown.
Binary file removed prof/test_set_filmweb_mapping.prof
Binary file not shown.
Binary file removed prof/test_set_filmweb_mapping2.prof
Binary file not shown.
Binary file removed prof/test_set_guild.prof
Binary file not shown.
Binary file removed prof/test_set_user_destination.prof
Binary file not shown.
Binary file removed prof/test_start.prof
Binary file not shown.
Binary file removed prof/test_task_update_task_status.prof
Binary file not shown.
Binary file removed prof/test_tasks_new_scrap_filmweb_movies.prof
Binary file not shown.
Binary file removed prof/test_tasks_new_scrap_filmweb_series.prof
Binary file not shown.
Binary file removed prof/test_tasks_new_scrap_filmweb_users_movies.prof
Binary file not shown.
Binary file removed prof/test_tasks_new_scrap_filmweb_users_series.prof
Binary file not shown.
Binary file removed prof/test_tasks_to_do_get.prof
Binary file not shown.
Binary file removed prof/test_tasks_to_do_head.prof
Binary file not shown.
Binary file removed prof/test_tasks_update_old_tasks.prof
Binary file not shown.
Binary file removed prof/test_tasks_update_stuck_tasks.prof
Binary file not shown.
Binary file removed prof/test_update_filmweb_movie.prof
Binary file not shown.
Binary file removed prof/test_update_filmweb_series.prof
Binary file not shown.
Binary file removed prof/test_update_movie.prof
Binary file not shown.
Binary file removed prof/test_update_series.prof
Binary file not shown.
Binary file removed prof/test_user_mapping_delete.prof
Binary file not shown.
31 changes: 13 additions & 18 deletions src/filman_crawler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# FROM python:3.11-slim-bullseye
FROM python:3.11-alpine

# RUN apt update
# RUN apt install -y pkg-config default-libmysqlclient-dev build-essential
RUN apk update && apk add --no-cache \
gcc \
musl-dev \
libffi-dev \
openssl-dev \
mariadb-dev \
build-base

# WORKDIR /src/filman_crawler

# COPY requirements.txt requirements.txt
# RUN pip3 install -r requirements.txt

# COPY /src/filman_crawler .

# ENV PYTHONPATH=/src

# CMD [ "python3", "-m", "filman_crawler.main"]

FROM python:3.11-slim-bullseye
RUN apt update
RUN apt install -y pkg-config default-libmysqlclient-dev build-essential
WORKDIR /src

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

COPY /src/filman_server /src/filman_server
COPY /src/filman_crawler /src/filman_crawler

ENV PYTHONPATH=/src/filman_server:/src/filman_crawler

CMD [ "python3", "-m", "filman_crawler.main" ]
11 changes: 0 additions & 11 deletions src/filman_crawler/tasks/scrap_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ def scrap(self, task: Task):
task_id=task.task_id,
)

# update = self.update_data(
# task.task_job,
# title,
# year,
# other_year,
# poster_url,
# community_rate,
# critics_rate,
# task.task_id,
# )

if update:
logging.info(f"Updated series {title} ({year})")
else:
Expand Down
13 changes: 9 additions & 4 deletions src/filman_discord/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
FROM python:3.11-slim-bullseye
FROM python:3.11-alpine

RUN apt update
RUN apt install -y pkg-config default-libmysqlclient-dev build-essential
RUN apk update && apk add --no-cache \
gcc \
musl-dev \
libffi-dev \
openssl-dev \
mariadb-dev \
build-base

WORKDIR /src/filman_discord

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

COPY /src/filman_discord .

Expand Down
2 changes: 1 addition & 1 deletion src/filman_discord/endpoints/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def info_command(ctx: lightbulb.SlashContext) -> None:

embed.add_field(
name="Wersja i ostatnia aktualizacja",
value="`1.1.6` - `2024-12-01`",
value="`1.1.7` - `2024-12-03`",
)

embed.add_field(
Expand Down
10 changes: 8 additions & 2 deletions src/filman_discord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from lightbulb.ext import tasks

LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN")

logging.basicConfig(
level=LOG_LEVEL,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
Expand All @@ -18,8 +20,12 @@
logging.getLogger("lightbulb").setLevel(LOG_LEVEL)
logging.getLogger("hikari").setLevel(LOG_LEVEL)

if DISCORD_TOKEN == None or DISCORD_TOKEN == "": # todo check this
logging.error("Provide DISCORD_TOKEN!")
exit(-1)

bot = lightbulb.BotApp(
os.environ.get("DISCORD_TOKEN"),
DISCORD_TOKEN,
intents=hikari.Intents.ALL,
banner=None,
)
Expand Down Expand Up @@ -50,7 +56,7 @@ async def presence(app: lightbulb.BotApp) -> None:
)


@tasks.task(s=2, auto_start=True, pass_app=True, max_consecutive_failures=9999)
@tasks.task(s=2, auto_start=True, pass_app=True, max_consecutive_failures=9999) # test and refactor this is sometime
async def notifications_task(app: lightbulb.BotApp) -> None:
def filmweb_movie_url_generator(movie_title: str, movie_year: int, movie_id: int) -> str:
movie_title = movie_title.replace(" ", "+")
Expand Down
15 changes: 10 additions & 5 deletions src/filman_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
FROM python:3.11-slim-bullseye
FROM python:3.11-alpine

RUN apt update
RUN apt install -y pkg-config default-libmysqlclient-dev build-essential
RUN apk update && apk add --no-cache \
gcc \
musl-dev \
libffi-dev \
openssl-dev \
mariadb-dev \
build-base

WORKDIR /src/filman_server

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

COPY /src/filman_server .

ENV PYTHONPATH=/src

CMD [ "python3", "-m", "filman_server.main" ]
CMD ["python3", "-m", "filman_server.main"]
14 changes: 6 additions & 8 deletions src/filman_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
logging.getLogger("uvicorn").setLevel(LOG_LEVEL)
logging.getLogger("uvicorn.access").setLevel(LOG_LEVEL)


models.Base.metadata.create_all(bind=engine)

if os.environ.get("SENTRY_ENABLED", "false") == "true":
sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN"),
Expand All @@ -36,19 +33,16 @@
],
)

cron = Cron()
cron.start()
models.Base.metadata.create_all(bind=engine)

cron = Cron()
app = FastAPI()

app.include_router(users.users_router)
app.include_router(discord.discord_router)
app.include_router(filmweb.filmweb_router)
app.include_router(tasks.tasks_router)

logging.debug("Application has started")
logging.info("X") # todo: remove


@app.get("/")
async def root():
Expand All @@ -61,4 +55,8 @@ async def trigger_error():


if __name__ == "__main__":
logging.info("Filman server started")
uvicorn.run(app, host="0.0.0.0", port=8000)
logging.debug("uvicorn running")
cron.start()
logging.debug("cron running")
7 changes: 6 additions & 1 deletion src/filman_server/routes/filmweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session

from urllib.parse import quote

from filman_server.database import crud, schemas
from filman_server.database.db import get_db

Expand Down Expand Up @@ -107,7 +109,10 @@ async def set_user_mapping(
user_mapping: schemas.FilmWebUserMappingCreate,
db: Session = Depends(get_db),
):
r = requests.get(f"https://www.filmweb.pl/api/v1/user/{user_mapping.filmweb_id}/preview")

filmweb_id_encoded = quote(user_mapping.filmweb_id)

r = requests.get(f"https://www.filmweb.pl/api/v1/user/{filmweb_id_encoded}/preview")

if r.status_code != 200:
raise HTTPException(status_code=404, detail="Filmweb user not found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)


# Override the get_db dependency to use the test database
def override_get_db():
try:
db = TestingSessionLocal()
yield db
finally:
db.close()
db.close_all()


app.dependency_overrides[get_db] = override_get_db
Expand All @@ -39,6 +38,7 @@ def test_client():

@pytest.fixture(autouse=True)
def clear_database():
engine = create_engine(SQLALCHEMY_DATABASE_URL)
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)

Expand Down
Loading

0 comments on commit acc3591

Please sign in to comment.