0
0
mirror of https://github.com/HamletDuFromage/switch-cheats-db.git synced 2025-04-24 08:25:17 +00:00

make date fetcher more robust

This commit is contained in:
HamletDuFromage 2024-09-01 13:39:41 +02:00
parent 75e33d371e
commit 26b1809348
3 changed files with 6 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
venv/
VERSION VERSION
DATE DATE
NX-60FPS-RES-GFX-Cheats-main NX-60FPS-RES-GFX-Cheats-main

View File

@ -6,7 +6,7 @@ import cloudscraper
import json import json
import shutil import shutil
from pathlib import Path from pathlib import Path
from datetime import date from datetime import date, datetime
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import process_cheats import process_cheats
@ -40,12 +40,10 @@ class GbatempCheatsInfo:
self.gbatemp_version = self.fetch_gbatemp_version() self.gbatemp_version = self.fetch_gbatemp_version()
def fetch_gbatemp_version(self): def fetch_gbatemp_version(self):
page = self.scraper.get(self.page_url) page = self.scraper.get(f"{self.page_url}/updates")
soup = BeautifulSoup(page.content, "html.parser") soup = BeautifulSoup(page.content, "html.parser")
# There are two occurances of the version, we pick the biggest one version = datetime.fromisoformat(soup.find("div", {"class": "block-container"}).find("time").get("datetime"))
version1 = version_parser(soup.find("ol", {"class": "block-body"}).find("div").getText()) return version.date()
version2 = version_parser(soup.find("span", {"class": "u-muted"}).getText())
return max(version1, version2)
def has_new_cheats(self, database_version): def has_new_cheats(self, database_version):
return self.gbatemp_version > database_version return self.gbatemp_version > database_version

View File

@ -39,7 +39,7 @@ class ProcessCheats:
lines = cheatSheet.readlines() lines = cheatSheet.readlines()
for i in range(len(lines)): for i in range(len(lines)):
titles = re.search("(\[.+\]|\{.+\})", lines[i]) titles = re.search(r"(\[.+\]|\{.+\})", lines[i])
if titles: if titles:
pos.append(i) pos.append(i)