Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform various tool-assisted fixes #83

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f0df92e
Update pre-commit config for ruff
woctezuma Nov 15, 2024
e21e674
Use static method in tests
woctezuma Nov 25, 2024
086f992
Add type annotations
woctezuma Nov 25, 2024
8550f02
Add utils for rate limits
woctezuma Nov 25, 2024
a91abe2
Add utils for tag drop rate numbers
woctezuma Nov 25, 2024
8e3d122
Add type for market order data
woctezuma Nov 25, 2024
9eef4c2
Add constants for default argument values
woctezuma Dec 1, 2024
5096b60
Add types for drop-rate estimates
woctezuma Dec 1, 2024
c05cfa8
Define dict in a more concise way
woctezuma Dec 1, 2024
8c6bf94
Loop over dict items
woctezuma Dec 1, 2024
a4d75e6
Fix bug: add parentheses before computing modulo
woctezuma Dec 1, 2024
44981f4
Fix bug: type of argument is not float, but int
woctezuma Dec 3, 2024
5658006
Minor formatting for unused variables
woctezuma Dec 3, 2024
1d4705b
Minor formatting for imports
woctezuma Dec 3, 2024
08be54a
Minor formatting for print()
woctezuma Dec 3, 2024
7530a09
Simplify return of functions
woctezuma Dec 3, 2024
c75bc83
Simplify code with dict comprehension
woctezuma Dec 3, 2024
db32eb8
Simplify code with dict initialization
woctezuma Dec 3, 2024
95ebbdc
Update Python version in Github Action
woctezuma Dec 3, 2024
09f3e4d
Minor formatting: rewrite dictionary creation as a dictionary literal
woctezuma Dec 3, 2024
11653dd
Avoid using boolean positional arguments when defining functions
woctezuma Nov 25, 2024
d157b24
Fix errors: avoid using boolean positional arguments when calling fun…
woctezuma Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
python-version: ["3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ repos:
--fix,
--unsafe-fixes,
--exit-non-zero-on-fix,
--target-version, "py312",
--target-version, "py313",
--select, "ALL",
--ignore, "ANN101,C90,D,E501,ERA001,FBT,PLR091,PLR2004,RUF001,S101,T20"
--ignore, "A004,C901,CPY001,D,DOC,E501,ERA001,INP001,PLR091,PLR2004,RUF001,S101,T201"
]
- id: ruff-format

Expand Down
11 changes: 8 additions & 3 deletions market_arbitrage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Objective: find market arbitrages, e.g. sell a pack for more (fee excluded) than the cost to craft it (fee included).


from typing import Annotated

from src.inventory_utils import create_then_sell_booster_packs_for_batch
from src.market_arbitrage_utils import (
convert_arbitrages_for_batch_create_then_sell,
Expand All @@ -15,12 +17,13 @@


def apply_workflow(
*, # enforce keyword arguments
retrieve_listings_from_scratch: bool = True,
retrieve_market_orders_online: bool = True,
enforced_sack_of_gems_price: float | None = None,
minimum_allowed_sack_of_gems_price: float | None = None,
automatically_create_then_sell_booster_packs: bool = False,
profit_threshold: float = 0.01, # profit in euros
profit_threshold: Annotated[float, "profit in euros"] = 0.01,
quick_check_with_tracked_booster_packs: bool = False,
enforce_update_of_marketability_status: bool = False,
from_javascript: bool = False,
Expand All @@ -34,7 +37,9 @@
retrieve_market_orders_online = True

print(
f"Overwriting two arguments:\n\ti) retrieve listings: {retrieve_listings_from_scratch},\n\tii) retrieve market orders: {retrieve_market_orders_online}.",
f"Overwriting two arguments:\n"
f"\ti) retrieve listings: {retrieve_listings_from_scratch},\n"
f"\tii) retrieve market orders: {retrieve_market_orders_online}.",
)

filtered_badge_data = get_filtered_badge_data(
Expand Down Expand Up @@ -107,7 +112,7 @@
profit_threshold=profit_threshold,
)

creation_results, sale_results = create_then_sell_booster_packs_for_batch(
_creation_results, _sale_results = create_then_sell_booster_packs_for_batch(

Check warning on line 115 in market_arbitrage.py

View check run for this annotation

Codecov / codecov/patch

market_arbitrage.py#L115

Added line #L115 was not covered by tests
price_dict_for_listing_hashes,
focus_on_marketable_items=True,
profile_id=profile_id,
Expand Down
1 change: 1 addition & 0 deletions market_arbitrage_with_foil_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


def apply_workflow_for_foil_cards(
*,
retrieve_listings_from_scratch: bool = False,
price_threshold_in_cents_for_a_foil_card: float | None = None,
retrieve_gem_price_from_scratch: bool = False,
Expand Down
15 changes: 11 additions & 4 deletions market_buzz_detector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Objective: detect the buzz, for games which I do not own yet, i.e. find packs which are likely to have high bid orders

from typing import Final

Check warning on line 3 in market_buzz_detector.py

View check run for this annotation

Codecov / codecov/patch

market_buzz_detector.py#L3

Added line #L3 was not covered by tests

from src.market_arbitrage_utils import (
filter_out_badges_with_low_sell_price,
find_badge_arbitrages,
Expand All @@ -17,17 +19,22 @@
from src.market_search import load_all_listings, update_all_listings
from src.market_utils import filter_out_dubious_listing_hashes

DEFAULT_MIN_SELL_PRICE: Final[int] = 30
DEFAULT_MIN_NUM_LISTINGS: Final[int] = 3
DEFAULT_NUM_PACKS_TO_DISPLAY: Final[int] = 10

Check warning on line 24 in market_buzz_detector.py

View check run for this annotation

Codecov / codecov/patch

market_buzz_detector.py#L22-L24

Added lines #L22 - L24 were not covered by tests


def main(
*,
retrieve_listings_from_scratch: bool = False,
retrieve_market_orders_online: bool = False,
force_update_from_steam_card_exchange: bool = False,
enforced_sack_of_gems_price: float | None = None,
minimum_allowed_sack_of_gems_price: float | None = None,
use_a_constant_price_threshold: bool = False,
min_sell_price: float = 30,
min_num_listings: int = 3,
num_packs_to_display: int = 10,
min_sell_price: int = DEFAULT_MIN_SELL_PRICE,
min_num_listings: int = DEFAULT_MIN_NUM_LISTINGS,
num_packs_to_display: int = DEFAULT_NUM_PACKS_TO_DISPLAY,
verbose: bool = False,
) -> None:
# Load list of all listing hashes
Expand Down Expand Up @@ -94,7 +101,7 @@

(
marketable_market_order_dict,
unknown_market_order_dict,
_unknown_market_order_dict,
) = filter_out_unmarketable_packs(market_order_dict)

# Sort by bid value
Expand Down
15 changes: 8 additions & 7 deletions market_gamble_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
sort_according_to_buzz,
)
from src.market_gamble_utils import (
DropRateEstimates,
count_listing_hashes_per_app_id,
enumerate_item_rarity_patterns,
filter_out_candidates_whose_ask_price_is_below_threshold,
Expand All @@ -39,14 +40,14 @@


def main(
*,
look_for_profile_backgrounds: bool = True, # if True, profile backgrounds, otherwise, emoticons.
retrieve_listings_from_scratch: bool = False,
retrieve_listings_with_another_rarity_tag_from_scratch: bool = False,
retrieve_market_orders_online: bool = True,
focus_on_listing_hashes_never_seen_before: bool = True,
price_threshold_in_cents: float | None = None,
drop_rate_estimates_for_common_rarity: dict[tuple[int, int, int], float]
| None = None,
drop_rate_estimates_for_common_rarity: DropRateEstimates | None = None,
num_packs_to_display: int = 10,
enforce_cooldown: bool = True,
allow_to_skip_dummy_data: bool = False,
Expand Down Expand Up @@ -134,10 +135,10 @@ def main(

market_order_dict = get_market_orders(
filtered_badge_data,
retrieve_market_orders_online,
focus_on_listing_hashes_never_seen_before,
listing_details_output_file_name,
market_order_output_file_name,
retrieve_market_orders_online=retrieve_market_orders_online,
focus_on_listing_hashes_never_seen_before=focus_on_listing_hashes_never_seen_before,
listing_details_output_file_name=listing_details_output_file_name,
market_order_output_file_name=market_order_output_file_name,
enforce_cooldown=enforce_cooldown,
allow_to_skip_dummy_data=allow_to_skip_dummy_data,
verbose=verbose,
Expand All @@ -147,7 +148,7 @@ def main(

(
marketable_market_order_dict,
unknown_market_order_dict,
_unknown_market_order_dict,
) = filter_out_unmarketable_packs(market_order_dict)

# Sort by bid value
Expand Down
32 changes: 32 additions & 0 deletions src/api_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Final

from src.utils import get_cushioned_cooldown_in_seconds

INTER_REQUEST_COOLDOWN_FIELD: Final[str] = "cooldown_between_each_request"


def get_rate_limits(
api_type: str,
*,
has_secured_cookie: bool = False,
) -> dict[str, int]:
if has_secured_cookie:
base_limits = {

Check warning on line 14 in src/api_utils.py

View check run for this annotation

Codecov / codecov/patch

src/api_utils.py#L14

Added line #L14 was not covered by tests
"market_order": {"queries": 50, "minutes": 1},
"market_search": {"queries": 50, "minutes": 1},
"market_listing": {"queries": 25, "minutes": 3},
}
else:
base_limits = {
"market_order": {"queries": 25, "minutes": 5},
"market_search": {"queries": 25, "minutes": 5},
"market_listing": {"queries": 25, "minutes": 5},
}

limits = base_limits[api_type]

return {
"max_num_queries": limits["queries"],
"cooldown": get_cushioned_cooldown_in_seconds(num_minutes=limits["minutes"]),
INTER_REQUEST_COOLDOWN_FIELD: 0,
}
5 changes: 4 additions & 1 deletion src/batch_create_packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get_manually_selected_app_ids() -> list[str]:

def filter_app_ids_based_on_badge_data(
manually_selected_app_ids: list[str],
*,
check_ask_price: bool = False,
filtered_badge_data: dict[str, dict] | None = None,
) -> tuple[list[str], dict[str, dict]]:
Expand Down Expand Up @@ -44,6 +45,7 @@ def filter_app_ids_based_on_badge_data(
def create_packs_for_app_ids(
manually_selected_app_ids: list[str],
filtered_badge_data: dict[str, dict] | None = None,
*,
check_ask_price: bool = False,
is_a_simulation: bool = True,
# Caveat: if False, then packs will be crafted, which costs money!
Expand Down Expand Up @@ -111,6 +113,7 @@ def create_packs_for_app_ids(


def main(
*,
retrieve_listings_from_scratch: bool = False,
# Set to True & run once if you get "No match found for" games you own.
is_a_simulation: bool = True, # Caveat: if False, then packs will be crafted, which costs money!
Expand Down Expand Up @@ -140,7 +143,7 @@ def main(
from_javascript=from_javascript,
)

creation_results, next_creation_times = create_packs_for_app_ids(
_creation_results, _next_creation_times = create_packs_for_app_ids(
manually_selected_app_ids,
filtered_badge_data=filtered_badge_data,
check_ask_price=check_ask_price,
Expand Down
4 changes: 3 additions & 1 deletion src/creation_time_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def load_next_creation_time_data(

def fill_in_badges_with_next_creation_times_loaded_from_disk(
aggregated_badge_data: dict[str, dict],
*,
verbose: bool = True,
) -> dict[str, dict]:
next_creation_times_loaded_from_disk = load_next_creation_time_data()
Expand Down Expand Up @@ -63,7 +64,7 @@ def to_timestamp(date: datetime.datetime) -> int:
return int(date.timestamp())


def get_creation_time_format(prepend_year: bool = False) -> str:
def get_creation_time_format(*, prepend_year: bool = False) -> str:
# Reference: https://docs.python.org/3/library/time.html#time.strftime

# The format used in: "14 Sep @ 10:48pm"
Expand Down Expand Up @@ -98,6 +99,7 @@ def prepend_year_to_time_as_str(

def get_time_struct_from_str(
formatted_time_as_str: str,
*,
use_current_year: bool = False,
) -> datetime.datetime:
if use_current_year:
Expand Down
4 changes: 3 additions & 1 deletion src/download_steam_card_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

def download_data_from_steam_card_exchange(
steam_card_exchange_file_name: str | None = None,
*,
save_to_disk: bool = True,
) -> dict | None:
if steam_card_exchange_file_name is None:
Expand Down Expand Up @@ -97,6 +98,7 @@

def parse_data_from_steam_card_exchange(
response: dict | None = None,
*,
force_update_from_steam_card_exchange: bool = False,
steam_card_exchange_file_name: str | None = None,
) -> dict[str, dict]:
Expand Down Expand Up @@ -140,7 +142,7 @@
return dico


def main(force_update: bool = False) -> bool:
def main(*, force_update: bool = False) -> bool:

Check warning on line 145 in src/download_steam_card_exchange.py

View check run for this annotation

Codecov / codecov/patch

src/download_steam_card_exchange.py#L145

Added line #L145 was not covered by tests
if force_update:
response = download_data_from_steam_card_exchange()
else:
Expand Down
7 changes: 5 additions & 2 deletions src/drop_rate_estimates.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def clamp_proportion(input_proportion: float) -> float:
return min(1.0, max(0.0, input_proportion))


def get_drop_rate_estimates_based_on_item_rarity_pattern(verbose: bool = True) -> dict:
def get_drop_rate_estimates_based_on_item_rarity_pattern(
*,
verbose: bool = True,
) -> dict:
# Drop-rate estimates conditionally on the item rarity pattern C/UC/R (the numbers of possible items of each rarity)

drop_rate_estimates: dict = {}
Expand Down Expand Up @@ -162,7 +165,7 @@ def get_drop_rate_estimates_based_on_item_rarity_pattern(verbose: bool = True) -
return drop_rate_estimates


def get_drop_rate_estimates(verbose: bool = True) -> dict:
def get_drop_rate_estimates(*, verbose: bool = True) -> dict:
# Drop-rate estimates conditionally on the category (profile backgrounds, emoticons)

drop_rate_estimates: dict = {}
Expand Down
10 changes: 6 additions & 4 deletions src/free_games_with_trading_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
return result


def download_owned_apps(verbose: bool = True) -> list[str]:
def download_owned_apps(*, verbose: bool = True) -> list[str]:

Check warning on line 41 in src/free_games_with_trading_cards.py

View check run for this annotation

Codecov / codecov/patch

src/free_games_with_trading_cards.py#L41

Added line #L41 was not covered by tests
result = download_user_data()

owned_apps = result["rgOwnedApps"] if result else []
Expand All @@ -49,7 +49,7 @@
return [str(i) for i in owned_apps]


def download_free_apps(method: str = "price", verbose: bool = True) -> set[str]:
def download_free_apps(method: str = "price", *, verbose: bool = True) -> set[str]:

Check warning on line 52 in src/free_games_with_trading_cards.py

View check run for this annotation

Codecov / codecov/patch

src/free_games_with_trading_cards.py#L52

Added line #L52 was not covered by tests
if method == "price":
data = steamspypi.load()

Expand Down Expand Up @@ -81,7 +81,7 @@
return free_apps


def load_apps_with_trading_cards(verbose: bool = True) -> list[str]:
def load_apps_with_trading_cards(*, verbose: bool = True) -> list[str]:

Check warning on line 84 in src/free_games_with_trading_cards.py

View check run for this annotation

Codecov / codecov/patch

src/free_games_with_trading_cards.py#L84

Added line #L84 was not covered by tests
all_listings = load_all_listings()

apps_with_trading_cards = [
Expand All @@ -97,6 +97,7 @@
def load_free_apps_with_trading_cards(
free_apps: set[str] | None = None,
list_of_methods: list[str] | None = None,
*,
verbose: bool = True,
) -> set[str]:
if list_of_methods is None:
Expand All @@ -123,7 +124,7 @@
return free_apps_with_trading_cards


def load_file(file_name: str, verbose: bool = True) -> list[str]:
def load_file(file_name: str, *, verbose: bool = True) -> list[str]:

Check warning on line 127 in src/free_games_with_trading_cards.py

View check run for this annotation

Codecov / codecov/patch

src/free_games_with_trading_cards.py#L127

Added line #L127 was not covered by tests
with Path(file_name).open(encoding="utf-8") as f:
data = [line.strip() for line in f]

Expand Down Expand Up @@ -189,6 +190,7 @@
file_name: str,
asf_username: str,
group_size: int = 25,
*,
verbose: bool = True,
) -> None:
output = group_concatenate_to_str(
Expand Down
Loading
Loading