-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor after updating python version (#311)
- Loading branch information
1 parent
092c1f8
commit d540b3d
Showing
16 changed files
with
558 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,61 @@ | ||
from json import dump | ||
import json | ||
|
||
from steampy.client import SteamClient, InvalidCredentials | ||
from steampy.models import GameOptions | ||
|
||
#Your steam username | ||
|
||
# Your Steam username | ||
username = '' | ||
|
||
#Path to steam guard file | ||
# Path to Steamguard file | ||
steam_guard_path = '' | ||
|
||
#Your steam password | ||
# Your Steam password | ||
password = '' | ||
|
||
#Your steam api key (http://steamcommunity.com/dev/apikey) | ||
# Your Steam api key (http://steamcommunity.com/dev/apikey) | ||
steam_key = '' | ||
|
||
#The game's app id. If not supplied, it will ask for input later | ||
# The game's app id. If not supplied, it will ask for input later | ||
app_id = '' | ||
|
||
#The game's context id. If not supplied, it will ask for input later | ||
# The game's context id. If not supplied, it will ask for input later | ||
context_id = '' | ||
|
||
#Log into steam. First, we create the SteamClient object, then we login | ||
print("Logging into steam") | ||
|
||
# Log in into Steam. First, we create the SteamClient object, then we log in. | ||
print('Logging in into Steam...') | ||
steam_client = SteamClient(steam_key) | ||
try: | ||
steam_client.login(username, password, steam_guard_path) | ||
except (ValueError, InvalidCredentials): | ||
print('Your login credentials are invalid') | ||
print('Your login credentials are invalid!') | ||
exit(1) | ||
print("Finished! Logged into steam") | ||
else: | ||
print('Finished! Logged in into Steam') | ||
|
||
#we will ask them for the game's app id and context id of the inventory | ||
|
||
# We'll ask them for the game's app id and context id of the inventory | ||
if not app_id: | ||
app_id = input('What is the app id?\n') | ||
if not context_id: | ||
context_id = input('What is the context id of that game\'s inventory? (usually 2)\n') | ||
context_id = input("What is the context id of that game's inventory? (usually 2)\n") | ||
|
||
|
||
#get all the items in inventory, and save each name of item and the amount | ||
# Get all the items in the inventory. Save name and amount for each item. | ||
print('Obtaining inventory...') | ||
item_amounts = {} | ||
inventory = steam_client.get_my_inventory(GameOptions(app_id,context_id)) | ||
inventory = steam_client.get_my_inventory(GameOptions(app_id, context_id)) | ||
for item in inventory.values(): | ||
if item["market_name"] in item_amounts: | ||
if item['market_name'] in item_amounts: | ||
item_amounts[item['market_name']] += 1 | ||
else: | ||
item_amounts[item['market_name']] = 1 | ||
print('Done reading inventory for game: {}'.format(app_id)) | ||
print(f'Done obtaining inventory for the game: {app_id}') | ||
|
||
|
||
#dump all the information into inventory_(app_id)_(context_id).json file | ||
print('Saving information....') | ||
with open('inventory_{0}_{1}.json'.format(app_id, context_id), 'w') as file: | ||
dump(item_amounts, file) | ||
print('Done! Saved to file: inventory_{0}_{1}.json'.format(app_id, context_id)) | ||
# Dump all the info to inventory_(app_id)_(context_id).json file | ||
print('Saving information...') | ||
with open(f'inventory_{app_id}_{context_id}.json', 'w') as file: | ||
json.dump(item_amounts, file) | ||
print(f'Done! Saved to file: inventory_{app_id}_{context_id}.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.