diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62bcdfd --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ + +# Unit test / coverage reports +htmlcov/ +.coverage +coverage.xml + +# Environments +venv/ + +data/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..de56308 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "python.formatting.provider": "black", + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} diff --git a/README.md b/README.md index 3db2369..0525f2c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Steam Trade Finder - [![Build status][build-image]][build] [![Code coverage][codecov-image]][codecov] [![Code Quality][codacy-image]][codacy] @@ -19,8 +18,8 @@ The objective of the tool provided in this repository is to ease the search for ## Requirements -- Install the latest version of [Python 3.X](https://www.python.org/downloads/). -- Install the required packages: +- Install the latest version of [Python 3.X](https://www.python.org/downloads/). +- Install the required packages: ```bash pip install -r requirements.txt @@ -45,24 +44,28 @@ python download_bot_listing.py #### HTML Alternatively, one could manually download the HTML code from [a public listing of ASF bots](https://asf.justarchi.net/STM). -Then edit it as follows, using for instance Visual Studio Code, with regular expressions allowed: +Then edit it as follows, using for instance Visual Studio Code, with regular expressions allowed: + +1. Remove HTML lines [which do not contain the word](https://stackoverflow.com/a/7024359) "steamtradematcher": -1. Remove HTML lines [which do not contain the word]((https://stackoverflow.com/a/7024359)) "steamtradematcher": ```regexp ^(?!.*steamtradematcher.*).+$ ``` 2. Trim the beginning of lines: + ```regexp ^.*/specscan/ ``` 3. Trim the end of lines: + ```regexp " target.*$ ``` 4. Replace the following with `\n`, in order to remove empty lines: + ```regexp \n+ ``` @@ -83,25 +86,21 @@ The default market appID is `448720` for [Puzzle Box](https://www.steamcardexcha ## References -- [Wiki: **neutral** Steam trades](https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Trading#steamtradematcher), -- [Steam Trade Matcher (STM)](https://www.steamtradematcher.com/), -- [Wiki: automated STM based on ArchiSteamFarm (ASF)](https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Statistics#public-asf-stm-listing), -- [A public listing of ASF bots](https://asf.justarchi.net/STM). -- [Official API for the public listing ASF bots][api-for-asf-bots] +- [Wiki: **neutral** Steam trades](https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Trading#steamtradematcher), +- [Steam Trade Matcher (STM)](https://www.steamtradematcher.com/), +- [Wiki: automated STM based on ArchiSteamFarm (ASF)](https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Statistics#public-asf-stm-listing), +- [A public listing of ASF bots](https://asf.justarchi.net/STM). +- [Official API for the public listing ASF bots][api-for-asf-bots] -[build]: +[build]: https://github.com/woctezuma/steam-trade-finder/actions [build-image]: - -[pyup]: -[dependency-image]: -[python3-image]: - -[codecov]: -[codecov-image]: - -[codacy]: -[codacy-image]: - -[api-for-asf-bots]: +[pyup]: https://pyup.io/repos/github/woctezuma/steam-trade-finder/ +[dependency-image]: https://pyup.io/repos/github/woctezuma/steam-trade-finder/shield.svg +[python3-image]: https://pyup.io/repos/github/woctezuma/steam-trade-finder/python-3-shield.svg +[codecov]: https://codecov.io/gh/woctezuma/steam-trade-finder +[codecov-image]: https://codecov.io/gh/woctezuma/steam-trade-finder/branch/master/graph/badge.svg +[codacy]: https://www.codacy.com/app/woctezuma/steam-trade-finder +[codacy-image]: https://api.codacy.com/project/badge/Grade/038afb64dd404f8f978ff8ba41b65aef +[api-for-asf-bots]: https://asf.justarchi.net/Api/Listing/Bots diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/asf_bots.json b/data/asf_bots.test.json similarity index 100% rename from data/asf_bots.json rename to data/asf_bots.test.json diff --git a/display_results.py b/display_results.py index 89be258..bd84685 100644 --- a/display_results.py +++ b/display_results.py @@ -35,7 +35,7 @@ def get_user_markdown(profile_id): def get_offer_markdown(profile_id, trade_offers=None): if trade_offers is None: - trade_offers = load_bot_listing_from_disk() + trade_offers = load_bot_listing_from_disk('data/asf_bots.test.json') profile_trade_offer = trade_offers[str(profile_id)] @@ -64,7 +64,7 @@ def display_results_with_markdown( hard_coded_market_dict = get_hard_coded_market_dict() if trade_offers is None: - trade_offers = load_bot_listing_from_disk() + trade_offers = load_bot_listing_from_disk('data/asf_bots.test.json') if blacklisted_profile_ids is None: blacklisted_profile_ids = [] diff --git a/download_bot_listing.py b/download_bot_listing.py index 66e3f35..8f76645 100644 --- a/download_bot_listing.py +++ b/download_bot_listing.py @@ -117,9 +117,7 @@ def parse_bot_listing(html_doc, stm_url_prefix=None, steam_trade_offer_url_prefi # Second, the URL with the scan by StreamTradeMatcher: if target_url.startswith(stm_url_prefix): - user_id_as_str = remove_prefix_from_str(target_url, stm_url_prefix) - - user_id = int(user_id_as_str) + user_id = remove_prefix_from_str(target_url, stm_url_prefix) trade_offers[user_id] = {} trade_offers[user_id]['partner'] = latest_trade_offer['partner'] @@ -168,10 +166,13 @@ def load_bot_listing_from_disk(bot_listing_file_name=None): if bot_listing_file_name is None: bot_listing_file_name = get_bot_listing_file_name() - with open(bot_listing_file_name) as f: - original_trade_offers = json.load(f) + try: + with open(bot_listing_file_name) as f: + original_trade_offers = json.load(f) - return original_trade_offers + return original_trade_offers + except FileNotFoundError: + return {} def save_bot_listing_to_disk(trade_offers, bot_listing_file_name=None): @@ -217,7 +218,7 @@ def update_and_save_bot_listing_to_disk( def main(): - latest_trade_offers = download_and_parse_bot_listing() + download_and_parse_bot_listing() return True diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..68a50dd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.black] +skip-string-normalization = true + +[tool.pytest.ini_options] +# addopts = "--cov=./ --cov-report=html" +python_files = "tests.py" diff --git a/requirements.txt b/requirements.txt index a98ae43..1f3e778 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ +beautifulsoup4 requests -beautifulsoup4 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..e3ee4f6 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,5 @@ +-r requirements.txt +black +pytest +pytest-cov +ruff