-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/gamesreleasedtoday #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Liad-n
wants to merge
21
commits into
PythonFreeCourse:develop
Choose a base branch
from
Liad-n:feature/gamesreleasedtoday
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ed40267
Added game releases
96adc87
Fixed merging conflicts
1714078
Partial game release form
5da84ed
Fixed merging conflicts
1a84c51
Added game release utils, added games to calendar, before pull
df20fbb
Added annotations to game adding function, before pull
47b0c86
Merge branch 'develop' of github.com:PythonFreeCourse/calendar into f…
3d83e49
Added tests to game releases, current user still doesnt work in tests
8725759
Fixed CR comments
6b74798
Fixed merging conflicts
70f63a3
Removed is_active=True in game releases, to be added only for users
6bc1251
changed request type in one test
0c27fe5
fixed isort confusing import condition
66f8282
fixed more CR change requests by Yam
28b61ba
fixed CR change requests
01cc534
Merge branch 'develop' of github.com:PythonFreeCourse/calendar into f…
7144971
fixed CR change requests
9d4239f
Merge branch 'develop' of github.com:PythonFreeCourse/calendar into f…
7a0af20
Fixed calendar grid test with game releases, added cached API call an…
0351e35
Fixed calendar grid test with game releases, added cached API call an…
896fc8d
Added typing to util function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List, TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from app.routers.calendar_grid import Week, Day | ||
|
||
from datetime import datetime | ||
|
||
from collections import defaultdict | ||
|
||
from loguru import logger | ||
|
||
import requests | ||
|
||
# from app.routers.calendar_grid import Week | ||
|
||
|
||
def add_game_events_to_weeks(weeks: List["Week"], is_active: bool = True): | ||
Liad-n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not is_active: | ||
return weeks | ||
first_week: Week = weeks[0] | ||
last_week: Week = weeks[-1] | ||
first_day: Day = first_week.days[0] | ||
last_day: Day = last_week.days[-1] | ||
first_day_str = datetime.strptime(first_day.set_id(), "%d-%B-%Y") | ||
last_day_str = datetime.strptime(last_day.set_id(), "%d-%B-%Y") | ||
games_released = get_games_data_separated_by_days( | ||
start_date=first_day_str.strftime("%Y-%m-%d"), | ||
end_date=last_day_str.strftime("%Y-%m-%d"), | ||
) | ||
for week in weeks: | ||
for day in week.days: | ||
if day.set_id() in games_released.keys(): | ||
day.dailyevents.append( | ||
( | ||
f"GR!- {(games_released[day.set_id()][0])[:10]}", | ||
(games_released[day.set_id()][0]), | ||
), | ||
) | ||
|
||
|
||
def get_games_data_separated_by_days(start_date, end_date): | ||
Liad-n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logger.debug((start_date, end_date)) | ||
Liad-n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
current_day_games = requests.get( | ||
f"https://api.rawg.io/api/games?dates={start_date},{end_date}", | ||
Liad-n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
current_day_games = current_day_games.json()["results"] | ||
games_data = defaultdict(list) | ||
for result in current_day_games: | ||
current = {} | ||
current["name"] = result["name"] | ||
current["platforms"] = [] | ||
for platform in result["platforms"]: | ||
current["platforms"].append(platform["platform"]["name"]) | ||
ybd_release_date = translate_ymd_date_to_dby(result["released"]) | ||
games_data[ybd_release_date].append(current) | ||
return get_formatted_games_in_days(games_data) | ||
|
||
|
||
def get_formatted_games_in_days( | ||
separated_games_dict: dict, | ||
Liad-n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with_platforms: bool = False, | ||
): | ||
formatted_games = defaultdict(list) | ||
|
||
for date, game_data in separated_games_dict.items(): | ||
for game in game_data: | ||
formatted_game_str = "" | ||
formatted_game_str += game["name"] | ||
if with_platforms: | ||
formatted_game_str += "-Platforms-<br>" | ||
for platform in game["platforms"]: | ||
formatted_game_str += f"{platform}," | ||
formatted_games[date].append(formatted_game_str) | ||
Liad-n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return formatted_games | ||
|
||
|
||
def translate_ymd_date_to_dby(ymd_str: str): | ||
ymd_time = datetime.strptime(ymd_str, "%Y-%m-%d") | ||
return ymd_time.strftime("%d-%B-%Y") | ||
|
||
|
||
def translate_dby_date_to_ymd(dby_str: str): | ||
dby_time = datetime.strptime(dby_str, "%d-%B-%Y") | ||
return dby_time.strftime("%Y-%m-%d") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.