testing steam api to get item info instead of using bs4

This commit is contained in:
faroukbmiled 2023-09-29 15:00:07 +01:00
parent 572070b18f
commit 59905f7e34
3 changed files with 30 additions and 21 deletions

View File

@ -381,14 +381,11 @@ def check_item_date(down_date, date_updated):
except ValueError:
download_datetime = datetime.strptime(down_date + f", {current_year}", date_format_with_added_year)
try:
upload_datetime = datetime.strptime(date_updated, date_format_with_year)
except ValueError:
upload_datetime = datetime.strptime(date_updated + f", {current_year}", date_format_with_added_year)
date_updated_datetime = datetime.fromtimestamp(date_updated)
if upload_datetime >= download_datetime:
if date_updated_datetime >= download_datetime:
return True
elif upload_datetime < download_datetime:
elif date_updated_datetime < download_datetime:
return False
except:
return False
@ -414,4 +411,25 @@ def save_window_size_to_registry(width, height, x, y):
except Exception as e:
print(f"Error saving to registry: {e}")
def item_steam_api(id):
try:
url = ITEM_INFO_API
data = {
"itemcount": 1,
"publishedfileids[0]": int(id),
}
info = requests.post(url, data=data)
return info.json()
except Exception as e:
print(e)
return False
def get_item_date(data):
try:
time_updated = data["response"]["publishedfiledetails"][0]["time_updated"]
return time_updated
except:
return None
# End helper functions

View File

@ -38,6 +38,7 @@ else:
CONFIG_FILE_PATH = "config.ini"
GITHUB_REPO = "faroukbmiled/BOIIIWD"
ITEM_INFO_API = "https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/"
LATEST_RELEASE_URL = "https://github.com/faroukbmiled/BOIIIWD/releases/latest/download/Release.zip"
LIBRARY_FILE = "boiiiwd_library.json"
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), '..', 'resources')

View File

@ -851,21 +851,11 @@ class LibraryTab(ctk.CTkScrollableFrame):
def if_id_needs_update(item_id, item_date, text):
try:
headers = {'Cache-Control': 'no-cache'}
url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={item_id}"
response = requests.get(url, headers=headers)
response.raise_for_status()
content = response.text
soup = BeautifulSoup(content, "html.parser")
details_stats_container = soup.find("div", class_="detailsStatsContainerRight")
details_stat_elements = details_stats_container.find_all("div", class_="detailsStatRight")
try:
date_updated = details_stat_elements[2].text.strip()
except:
try:
date_updated = details_stat_elements[1].text.strip()
except:
return False
item_data = item_steam_api(item_id)
date_updated = get_item_date(item_data)
if not date_updated:
return False
if check_item_date(item_date, date_updated):
self.to_update.add(text + f" | Updated: {date_updated}")