Skip to content

Commit

Permalink
Fix Otak Otaku not updating the db
Browse files Browse the repository at this point in the history
  • Loading branch information
nattadasu committed Oct 5, 2023
1 parent 4b5aec7 commit 2c6cb64
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions generator/otakotaku.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_latest_anime(self) -> int:
f"Latest anime id: {anime_id}")
return int(anime_id)

def _get_data_index(self, anime_id: int) -> Union[dict[str, Any], None]:
def _get_data(self, anime_id: int) -> Union[dict[str, Any], None]:
"""
Get anime data
Expand Down Expand Up @@ -152,29 +152,29 @@ def get_anime(self) -> list[dict[str, Any]]:
with open(file_path, "r", encoding="utf-8") as file:
anime_list = json.load(file)
try:
raise ConnectionError("Failed to connect to otakotaku.com")
# raise ConnectionError("Failed to connect to otakotaku.com")
latest_id = self.get_latest_anime()
if not latest_id:
raise ConnectionError("Failed to connect to otakotaku.com")
# if not datetime.now().day in [1, 15] and len(anime_list) > 0 and not GITHUB_DISPATCH:
# with open(latest_file_path, "r", encoding="utf-8") as file:
# latest = int(file.read().strip())
# if latest == latest_id:
# pprint.print(
# Platform.OTAKOTAKU,
# Status.PASS,
# "Data is up to date, loading from local file",
# )
# return anime_list
# latest = latest + 1
# loop = latest_id - latest + 1
# else:
anime_list = [] # remove possible duplicate
latest = 1
loop = latest_id
if not datetime.now().day in [1, 15] and len(anime_list) > 0 and not GITHUB_DISPATCH:
with open(latest_file_path, "r", encoding="utf-8") as file:
latest = int(file.read().strip())
if latest == latest_id:
pprint.print(
Platform.OTAKOTAKU,
Status.PASS,
"Data is up to date, loading from local file",
)
return anime_list
latest = latest + 1
loop = latest_id - latest + 1
else:
anime_list = [] # remove possible duplicate
latest = 1
loop = latest_id
with alive_bar(loop, title="Getting data", spinner=None) as bar: # type: ignore
for anime_id in range(latest, latest_id + 1):
data_index = self._get_data_index(anime_id)
data_index = self._get_data(anime_id)
if not data_index:
pprint.print(
Platform.OTAKOTAKU,
Expand Down

0 comments on commit 2c6cb64

Please sign in to comment.