Skip to content

Commit

Permalink
Avoid using boolean positional arguments when defining functions
Browse files Browse the repository at this point in the history
  • Loading branch information
woctezuma committed Dec 3, 2024
1 parent 09f3e4d commit 11653dd
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 14 deletions.
1 change: 1 addition & 0 deletions market_arbitrage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


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,
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
1 change: 1 addition & 0 deletions market_buzz_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


def main(
*,
retrieve_listings_from_scratch: bool = False,
retrieve_market_orders_online: bool = False,
force_update_from_steam_card_exchange: bool = False,
Expand Down
1 change: 1 addition & 0 deletions market_gamble_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@


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,
Expand Down
3 changes: 3 additions & 0 deletions 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
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 save_data_from_steam_card_exchange(

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 compute_gem_amount_required_to_craft_booster_pack(num_cards_per_set: int) ->

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 @@ def parse_data_from_steam_card_exchange(
return dico


def main(force_update: bool = False) -> bool:
def main(*, force_update: bool = False) -> bool:
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 @@ def download_user_data() -> dict | None:
return result


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

owned_apps = result["rgOwnedApps"] if result else []
Expand All @@ -49,7 +49,7 @@ def download_owned_apps(verbose: bool = True) -> list[str]:
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]:
if method == "price":
data = steamspypi.load()

Expand Down Expand Up @@ -81,7 +81,7 @@ def download_free_apps(method: str = "price", verbose: bool = True) -> set[str]:
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]:
all_listings = load_all_listings()

apps_with_trading_cards = [
Expand All @@ -97,6 +97,7 @@ def load_apps_with_trading_cards(verbose: bool = True) -> list[str]:
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 @@ def load_free_apps_with_trading_cards(
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]:
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 @@ def write_to_file(
file_name: str,
asf_username: str,
group_size: int = 25,
*,
verbose: bool = True,
) -> None:
output = group_concatenate_to_str(
Expand Down
9 changes: 9 additions & 0 deletions src/inventory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def load_steam_inventory_from_disk(profile_id: str | None = None) -> dict | None

def load_steam_inventory(
profile_id: str | None = None,
*,
update_steam_inventory: bool = False,
) -> dict | None:
if profile_id is None:
Expand All @@ -76,6 +77,7 @@ def load_steam_inventory(

def download_steam_inventory(
profile_id: str | None = None,
*,
save_to_disk: bool = True,
) -> dict | None:
if profile_id is None:
Expand Down Expand Up @@ -128,6 +130,7 @@ def get_steam_booster_pack_creation_url() -> str:
def get_booster_pack_creation_parameters(
app_id: str,
session_id: str,
*,
is_marketable: bool = True,
) -> dict[str, str]:
booster_pack_creation_parameters = {}
Expand All @@ -144,6 +147,7 @@ def get_booster_pack_creation_parameters(

def create_booster_pack(
app_id: str,
*,
is_marketable: bool = True,
verbose: bool = True,
) -> dict | None:
Expand Down Expand Up @@ -233,6 +237,7 @@ def get_request_headers() -> dict[str, str]:
def sell_booster_pack(
asset_id: str,
price_in_cents: int, # this is the money which you, as the seller, will receive
*,
verbose: bool = True,
) -> dict | None:
cookie = get_cookie_dict()
Expand Down Expand Up @@ -295,6 +300,7 @@ def sell_booster_pack(
def retrieve_asset_id(
listing_hash: str,
steam_inventory: dict | None = None,
*,
focus_on_marketable_items: bool = True,
profile_id: str | None = None,
verbose: bool = True,
Expand Down Expand Up @@ -372,6 +378,7 @@ def create_booster_packs_for_batch(listing_hashes: list[str]) -> dict[str, dict

def sell_booster_packs_for_batch(
price_dict_for_listing_hashes: dict[str, int],
*,
update_steam_inventory: bool = True,
focus_on_marketable_items: bool = True,
profile_id: str | None = None,
Expand Down Expand Up @@ -401,6 +408,7 @@ def sell_booster_packs_for_batch(

def create_then_sell_booster_packs_for_batch(
price_dict_for_listing_hashes: dict[str, int],
*,
update_steam_inventory: bool = True,
focus_on_marketable_items: bool = True,
profile_id: str | None = None,
Expand All @@ -423,6 +431,7 @@ def create_then_sell_booster_packs_for_batch(

def update_and_save_next_creation_times(
creation_results: dict[str, dict | None],
*,
verbose: bool = True,
next_creation_time_file_name: str | None = None,
) -> dict[str, str]:
Expand Down
8 changes: 7 additions & 1 deletion src/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ def load_json(fname: str) -> dict:
return json.load(f)


def save_json(data: dict, fname: str, prettify: bool = True, indent: int = 4) -> None:
def save_json(
data: dict,
fname: str,
*,
prettify: bool = True,
indent: int = 4,
) -> None:
with Path(fname).open("w", encoding="utf8") as f:
if prettify:
json.dump(data, f, indent=indent)
Expand Down
2 changes: 2 additions & 0 deletions src/list_possible_lures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def filter_app_ids_with_potential_profit(
sell_prices_without_fee: dict[str, float],
gem_amounts_for_a_booster_pack: dict[str, int],
gem_sack_price_in_euros: float | None = None,
*,
verbose: bool = True,
) -> list[str]:
# Filter out appIDs for which the sell price (without fee) is lower than the cost to craft a Booster Pack.
Expand Down Expand Up @@ -117,6 +118,7 @@ def filter_app_ids_with_potential_profit(
def remove_app_ids_previously_processed(
filtered_app_ids: list[str],
app_ids_previously_processed: list[str] | None = None,
*,
verbose: bool = True,
) -> list[str]:
# Manually remove previously processed appIDs from the list of returned appIDs of interest.
Expand Down
8 changes: 8 additions & 0 deletions src/market_arbitrage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def determine_whether_booster_pack_was_crafted_at_least_once(badge_data: dict) -

def filter_out_badges_never_crafted(
aggregated_badge_data: dict[str, dict],
*,
verbose: bool = True,
) -> dict[str, dict]:
# Filter out games for which a booster pack was never crafted (according to 'data/next_creation_times.json'),
Expand All @@ -43,6 +44,7 @@ def filter_out_badges_never_crafted(

def filter_out_badges_recently_crafted(
aggregated_badge_data: dict[str, dict],
*,
verbose: bool = True,
) -> dict[str, dict]:
# Filter out games for which a booster pack was crafted less than 24 hours ago,
Expand Down Expand Up @@ -114,6 +116,7 @@ def filter_out_badges_with_low_sell_price(
aggregated_badge_data: dict[str, dict],
user_chosen_price_threshold: float | None = None,
category_name: str | None = None,
*,
verbose: bool = True,
) -> dict[str, dict]:
# Filter out games for which the sell price (ask) is lower than the gem price,
Expand Down Expand Up @@ -160,6 +163,7 @@ def filter_out_badges_with_low_sell_price(
def find_badge_arbitrages(
badge_data: dict,
market_order_dict: dict[str, dict] | None = None,
*,
verbose: bool = False,
) -> dict[str, dict]:
if market_order_dict is None:
Expand Down Expand Up @@ -250,6 +254,7 @@ def find_badge_arbitrages(

def print_arbitrages(
badge_arbitrages: dict[str, dict],
*,
use_numbered_bullet_points: bool = False,
use_hyperlink: bool = False,
) -> None:
Expand Down Expand Up @@ -302,6 +307,7 @@ def print_arbitrages(
def convert_arbitrages_for_batch_create_then_sell(
badge_arbitrages: dict[str, dict],
profit_threshold: float = 0.01, # profit in euros
*,
verbose: bool = True,
) -> dict[str, int]:
# Code inspired from print_arbitrages()
Expand Down Expand Up @@ -334,6 +340,7 @@ def convert_arbitrages_for_batch_create_then_sell(
def update_badge_arbitrages_with_latest_market_order_data(
badge_data: dict[str, dict],
arbitrage_data: dict[str, dict],
*,
retrieve_market_orders_online: bool = True,
verbose: bool = False,
) -> dict[str, dict]:
Expand Down Expand Up @@ -361,6 +368,7 @@ def update_badge_arbitrages_with_latest_market_order_data(


def get_filtered_badge_data(
*,
retrieve_listings_from_scratch: bool = True,
enforced_sack_of_gems_price: float | None = None,
minimum_allowed_sack_of_gems_price: float | None = None,
Expand Down
2 changes: 2 additions & 0 deletions src/market_buzz_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def filter_listings(
min_sell_price: int = 30, # in cents
min_num_listings: int = 20,
# to remove listings with very few sellers, who chose unrealistic sell prices
*,
verbose: bool = True,
) -> list[str]:
if all_listings is None:
Expand Down Expand Up @@ -157,6 +158,7 @@ def print_packs_with_high_buzz(
def fill_in_badge_data_with_data_from_steam_card_exchange(
all_listings: dict[str, dict],
aggregated_badge_data: dict[str, dict] | None = None,
*,
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,
Expand Down
Loading

0 comments on commit 11653dd

Please sign in to comment.