revert back to bs4 for item sizes for now due to API being inconsistent

This commit is contained in:
faroukbmiled 2023-09-29 17:29:48 +01:00
parent 29f5770ac6
commit f10efcefe1
2 changed files with 16 additions and 37 deletions

View File

@ -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": []
}
]
}
}

View File

@ -217,13 +217,26 @@ def convert_bytes_to_readable(size_in_bytes, no_symb=None):
size_in_bytes /= 1024.0 size_in_bytes /= 1024.0
def get_workshop_file_size(workshop_id, raw=None): 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: try:
file_size_in_bytes = data['response']['publishedfiledetails'][0]['file_size']
if raw: 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) 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 file_size_in_bytes
return None
except: except:
return None return None