fix: TimeDelta calculations#270
Conversation
|
Merged my branches together but here are my comments so they are easy to find:
|
|
@AxelMurilllo could you please provide a code example for testing? |
|
Heres a simple script for testing TimeDelta and uninitiated objects .max_level attribute. I used the "Barbarian" as an example as it is the only home village troop with an upgrade time in minutes. Make sure that your static data is updated!
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the TimeDelta class to simplify its time normalization logic and adds handling for None types. Additionally, it updates the APK download process to use synchronous requests with BeautifulSoup for parsing and adjusts the upgrade_time initialization in the JSON meta loader to match the new TimeDelta API.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| coc/static/update_static.py | Updated the APK download function to use requests and improved error handling in download logic. |
| coc/static/apk_source.py | Added a new function to retrieve the direct APK download URL from APKMirror. |
| coc/miscmodels.py | Refactored the TimeDelta class to calculate total seconds in a single calculation. |
| coc/abc.py | Modified upgrade_time initialization to use the updated TimeDelta constructor parameters. |
Comments suppressed due to low confidence (1)
coc/abc.py:281
- If the API provides an 'UpgradeTimeS', consider including it in the TimeDelta initialization to maintain consistency with the previous behavior.
TimeDelta(
|
|
||
| # download the APK using the direct URL | ||
| print("[+] Downloading APK file...") | ||
| response = session.get(direct_url, stream=True) |
There was a problem hiding this comment.
Consider verifying the HTTP response status (e.g., checking response.status_code) before processing the content to ensure the request succeeded.
| response = session.get(direct_url, stream=True) | |
| response = session.get(direct_url, stream=True) | |
| response.raise_for_status() # Ensure the request was successful |
|
|
||
| dl_button = variant_soup.select_one("a.downloadButton") | ||
| if not dl_button: | ||
| raise Exception("ERROR:Download button not found on variant page") |
There was a problem hiding this comment.
Consider adding a space after 'ERROR:' in the exception message for consistency.
| raise Exception("ERROR:Download button not found on variant page") | |
| raise Exception("ERROR: Download button not found on variant page") |
Previous TimeDelta class constructor: