From f10efcefe136e61ea026202aba94c16c95634825 Mon Sep 17 00:00:00 2001 From: faroukbmiled Date: Fri, 29 Sep 2023 17:29:48 +0100 Subject: [PATCH] revert back to bs4 for item sizes for now due to API being inconsistent --- boiiiwd_package/info.json | 34 ---------------------------------- boiiiwd_package/src/helpers.py | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 37 deletions(-) delete mode 100644 boiiiwd_package/info.json diff --git a/boiiiwd_package/info.json b/boiiiwd_package/info.json deleted file mode 100644 index 6b60c8f..0000000 --- a/boiiiwd_package/info.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "response": { - "result": 1, - "resultcount": 1, - "publishedfiledetails": [ - { - "publishedfileid": "770675911", - "result": 1, - "creator": "76561198294963547", - "creator_app_id": 455130, - "consumer_app_id": 311210, - "filename": "", - "file_size": 0, - "file_url": "", - "hcontent_file": "3845203201590843337", - "preview_url": "https://steamuserimages-a.akamaihd.net/ugc/262722490466018040/361198F0A8D4F1479CD8F75E7A4A78354592EAF3/", - "hcontent_preview": "262722490466018040", - "title": "Zombies Life Timer", - "description": "On-screen text that tells you how long you've been alive in Zombies. Only works in user-created maps.", - "time_created": 1474934901, - "time_updated": 1474934901, - "visibility": 0, - "banned": 0, - "ban_reason": "", - "subscriptions": 4900, - "favorited": 33, - "lifetime_subscriptions": 10835, - "lifetime_favorited": 46, - "views": 9038, - "tags": [] - } - ] - } -} \ No newline at end of file diff --git a/boiiiwd_package/src/helpers.py b/boiiiwd_package/src/helpers.py index 4fc62a3..3a23b77 100644 --- a/boiiiwd_package/src/helpers.py +++ b/boiiiwd_package/src/helpers.py @@ -217,13 +217,26 @@ def convert_bytes_to_readable(size_in_bytes, no_symb=None): size_in_bytes /= 1024.0 def get_workshop_file_size(workshop_id, raw=None): - data = item_steam_api(workshop_id) + url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}&searchtext=" + response = requests.get(url) + soup = BeautifulSoup(response.text, "html.parser") + file_size_element = soup.find("div", class_="detailsStatRight") + try: - file_size_in_bytes = data['response']['publishedfiledetails'][0]['file_size'] if raw: + file_size_text = file_size_element.get_text(strip=True) + file_size_text = file_size_text.replace(",", "") + file_size_in_mb = float(file_size_text.replace(" MB", "")) + file_size_in_bytes = int(file_size_in_mb * 1024 * 1024) return convert_bytes_to_readable(file_size_in_bytes) - else: + + if file_size_element: + file_size_text = file_size_element.get_text(strip=True) + file_size_text = file_size_text.replace(",", "") + file_size_in_mb = float(file_size_text.replace(" MB", "")) + file_size_in_bytes = int(file_size_in_mb * 1024 * 1024) return file_size_in_bytes + return None except: return None