Skip to content

Commit

Permalink
Merge pull request #13 from ngoclong19/develop
Browse files Browse the repository at this point in the history
Fix duplicated bots data is saved
  • Loading branch information
woctezuma authored Jun 26, 2023
2 parents 91552e6 + 437f6d9 commit 7f2aaaa
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 33 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Byte-compiled / optimized / DLL files
__pycache__/

# Unit test / coverage reports
htmlcov/
.coverage
coverage.xml

# Environments
venv/

data/
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.formatting.provider": "black",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Steam Trade Finder


[![Build status][build-image]][build]
[![Code coverage][codecov-image]][codecov]
[![Code Quality][codacy-image]][codacy]
Expand All @@ -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
Expand All @@ -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+
```
Expand All @@ -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]

<!-- Definitions -->

[build]: <https://github.com/woctezuma/steam-trade-finder/actions>
[build]: https://github.com/woctezuma/steam-trade-finder/actions
[build-image]: <https://github.com/woctezuma/steam-trade-finder/workflows/Python package/badge.svg?branch=master>

[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/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
Empty file added data/.gitkeep
Empty file.
File renamed without changes.
4 changes: 2 additions & 2 deletions display_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down Expand Up @@ -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 = []
Expand Down
15 changes: 8 additions & 7 deletions download_bot_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool.black]
skip-string-normalization = true

[tool.pytest.ini_options]
# addopts = "--cov=./ --cov-report=html"
python_files = "tests.py"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
beautifulsoup4
requests
beautifulsoup4
5 changes: 5 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-r requirements.txt
black
pytest
pytest-cov
ruff

0 comments on commit 7f2aaaa

Please sign in to comment.