From d4d86e1841bf4808edb99be1eeee5e2ebc075951 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 5 Jan 2020 14:50:33 +0100 Subject: [PATCH 01/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61558e4..d430bc8 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ License ======= MIT License -Copyright (c) 2019 [offish](overutilization@gmail.com) +Copyright (c) 2019 [offish](mailto:overutilization@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 07de211a79cec4545da6c4ca03f85df3d43f639b Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 5 Jan 2020 14:51:34 +0100 Subject: [PATCH 02/10] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 4ea2152..e5e56e6 100644 --- a/setup.py +++ b/setup.py @@ -5,14 +5,14 @@ setuptools.setup( name="steam_community_market", - version="1.0.0", + version="1.1.0", author="offish", author_email="overutilization@gmail.com", description="Easily get item prices and volumes from the Steam Community Market using Python 3", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/offish/steam_community_market", - download_url='https://github.com/offish/steam_community_market/archive/v1.0.0.tar.gz', + download_url='https://github.com/offish/steam_community_market/archive/v1.1.0.tar.gz', packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3", From 61856a5d3929c74e1e94ff5add09962e16b60983 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 5 Jan 2020 14:52:36 +0100 Subject: [PATCH 03/10] Update and rename prices.py to market.py --- steam_community_market/{prices.py => market.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename steam_community_market/{prices.py => market.py} (95%) diff --git a/steam_community_market/prices.py b/steam_community_market/market.py similarity index 95% rename from steam_community_market/prices.py rename to steam_community_market/market.py index e59fa9c..b3288fe 100644 --- a/steam_community_market/prices.py +++ b/steam_community_market/market.py @@ -37,7 +37,7 @@ class ESteamCurrency(enum.IntEnum): AED = 32 -class Prices: +class Market: url = 'http://steamcommunity.com/market/priceoverview' def __init__(self, currency: (str, int) = 1): From f5d527821f62a6576234609737c72df6c2f61d94 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 5 Jan 2020 14:53:51 +0100 Subject: [PATCH 04/10] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d430bc8..65a526f 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,11 @@ pip install steam_community_market Usage ===== ```python -from steam_community_market.prices import Prices +from steam_community_market.market import Market -market = Prices('USD') +market = Market('USD') ``` -`'USD'` can either be `str` or `int`. Find the currencies supported [here](https://github.com/offish/steam_community_market/blob/master/steam_community_market/prices.py#L5). +`'USD'` can either be `str` or `int`. Find the currencies supported [here](https://github.com/offish/steam_community_market/blob/master/steam_community_market/market.py#L5). From 3819444a94d9d1bd20e34aa711952f2637619378 Mon Sep 17 00:00:00 2001 From: offish Date: Fri, 10 Jan 2020 22:44:52 +0100 Subject: [PATCH 05/10] Update example.py --- example.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/example.py b/example.py index 382bda9..776d6e7 100644 --- a/example.py +++ b/example.py @@ -1,8 +1,50 @@ -from steam_community_market.prices import Prices +from steam_community_market.market import Market -market = Prices('USD') -items = ['Prisma Case', 'Danger Zone Case', 'Supermega Case'] -item = market.get_prices(items, 730) -print(item) +market = Market('NOK') # Could either be: 'NOK', 'nok' or 9. +# For USD; leave it empty or use 'USD', 'usd' or 1. +# For all the currencies supported go here: +# https://github.com/offish/steam_community_market/blob/master/steam_community_market/market.py#L5 + + + +# Example using get_price. +# First parameter is the name of the item how it appears on the Steam Community Market. +# Second parameter is the AppID of the game the item is from. +market.get_price('Mann Co. Supply Crate Key', 440) # 440 is TF2's AppID. +# >>> {'success': True, 'lowest_price': '22,12 kr', 'volume': '6,489', 'median_price': '21,75 kr'} + + + +# Example using get_prices with the same AppID. +items = ['Mann Co. Supply Crate Key', 'Tour of Duty Ticket'] +market.get_prices(items, 440) +# >>> {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,36 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, +# 'Tour of Duty Ticket': {'success': True, 'lowest_price': '9,21 kr', 'volume': '668', 'median_price': '9,61 kr'}} + + + +# Example using get_prices with different AppIDs. +items = ['Mann Co. Supply Crate Key', 'AWP | Atheris (Field-Tested)'] +appids = [440, 730] # 440 is TF2, 730 is CSGO. +# These two lists MUST have the same length. In this case they both have 2 elements. +market.get_prices(items, appids) +# >>> {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,01 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, +# 'AWP | Atheris (Field-Tested)': {'success': True, 'lowest_price': '47,68 kr', 'volume': '1,381', 'median_price': '45,39 kr'}} + + + +# Example using get_prices_from_dict. +items = { + "Mann Co. Supply Crate Key": { + "appid": 440 + }, + "AK-47 | Redline (Field-Tested)": { + "appid": 730 + } # Do not add a comma at the end of the last entry. +} + +market.get_prices_from_dict(items) +# >>> {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,36 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, +# 'AK-47 | Redline (Field-Tested)': {'success': True, 'lowest_price': '136,51 kr', 'volume': '749', 'median_price': '131,36 kr'}} From 67705445b563b019948ac91f5211bdbd023a602a Mon Sep 17 00:00:00 2001 From: offish Date: Fri, 10 Jan 2020 22:45:18 +0100 Subject: [PATCH 06/10] Update request.py --- steam_community_market/request.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/steam_community_market/request.py b/steam_community_market/request.py index 454dda6..9141994 100644 --- a/steam_community_market/request.py +++ b/steam_community_market/request.py @@ -5,9 +5,7 @@ def request(url: str, payload: dict) -> dict: r = requests.get(url, payload) - if r.ok: - return r.json() try: return json.loads(r.text) except ValueError: - return {'success': False, 'code': r.status_code, 'reason': r.text} + return {'success': False, 'status_code': r.status_code, 'text': r.text} From eefc63ffbfadf3358e7a9772301cdc71bb7aa3f4 Mon Sep 17 00:00:00 2001 From: offish Date: Fri, 10 Jan 2020 22:46:16 +0100 Subject: [PATCH 07/10] Update market.py --- steam_community_market/market.py | 61 ++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/steam_community_market/market.py b/steam_community_market/market.py index b3288fe..2576c53 100644 --- a/steam_community_market/market.py +++ b/steam_community_market/market.py @@ -1,4 +1,5 @@ from steam_community_market.request import request +from typing import Union import enum @@ -43,18 +44,16 @@ class Market: def __init__(self, currency: (str, int) = 1): """ Sets the currency to be outputted. - :param currency: 1, 'USD' or leave empty for American Dollars. For other currencies take a look at the README. """ if isinstance(currency, str): currency = currency.upper() - for i in ESteamCurrency: - if currency == i.name: - currency = ESteamCurrency[currency].value + if currency in [i.name for i in ESteamCurrency]: + currency = ESteamCurrency[currency].value - elif isinstance(currency, int): + if isinstance(currency, int): if currency > 32 or currency < 1: currency = 1 @@ -76,24 +75,64 @@ def get_price(self, name: str, app_id: int) -> dict: if not isinstance(app_id, int): raise TypeError('app_id must be int') + if self.has_invalid_name(name): + name = self.fix_name(name) + payload = {'appid': app_id, 'market_hash_name': name, 'currency': self.currency} return request(self.url, payload) - def get_prices(self, names: list, app_id: int) -> dict: + def get_prices(self, names: list, app_id: (int, list)) -> dict: """ - Gets the price(s) and volume of each item in the list. - + Gets the price(s) and volume of each item in the list. If both are lists, then they need to have the same amount of elements. :param names: A list of item names how each item appears on the Steam Community Market. - :param app_id: The AppID of all the items. Every item in the list must have the same AppID. + :param app_id: The AppID of the item(s). Either a list or int. For more information check the example.py file. """ prices = {} if not isinstance(names, list): raise TypeError('names must be list') + + if isinstance(app_id, int): + for name in names: + prices[name] = self.get_price(name, app_id) + + elif isinstance(app_id, list): + if len(names) == len(app_id): + for i in range(len(names)): + name = names[i] + prices[name] = self.get_price(name, app_id[i]) + else: + raise IndexError('names and app_id needs to have the same len') + + return prices + + def get_prices_from_dict(self, items: dict) -> dict: + """ + Gets the price(s) and volume of each item in the list. + :param items: A dict including item names and AppIDs. Check example.py file for more information. + """ + + prices = {} + + if not isinstance(items, dict): + raise TypeError('items must be dict') - for name in names: - prices[name] = self.get_price(name, app_id) + for item in items: + prices[item] = self.get_price(item, items[item]['appid']) return prices + + def has_invalid_name(self, name: str) -> bool: + if isinstance(name, str): + try: + return name.index('/') >= 0 + except ValueError: + return False + return False + + def fix_name(self, name: str): + if isinstance(name, str): + return name.replace('/', '-') + return False From ce94d93b4c4093f1751f6a6d069ef4fe8808b964 Mon Sep 17 00:00:00 2001 From: offish Date: Fri, 10 Jan 2020 22:47:04 +0100 Subject: [PATCH 08/10] Update LICENSE.txt --- LICENSE.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 4073462..b1944f6 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 offish +Copyright (c) 2020 offish Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. From 5e48691b9ff9b63c51a29a01b737738b16d70fda Mon Sep 17 00:00:00 2001 From: offish Date: Fri, 10 Jan 2020 22:56:50 +0100 Subject: [PATCH 09/10] Update example.py --- example.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/example.py b/example.py index 776d6e7..e5c0695 100644 --- a/example.py +++ b/example.py @@ -13,15 +13,15 @@ # First parameter is the name of the item how it appears on the Steam Community Market. # Second parameter is the AppID of the game the item is from. market.get_price('Mann Co. Supply Crate Key', 440) # 440 is TF2's AppID. -# >>> {'success': True, 'lowest_price': '22,12 kr', 'volume': '6,489', 'median_price': '21,75 kr'} +# {'success': True, 'lowest_price': '22,12 kr', 'volume': '6,489', 'median_price': '21,75 kr'} # Example using get_prices with the same AppID. items = ['Mann Co. Supply Crate Key', 'Tour of Duty Ticket'] market.get_prices(items, 440) -# >>> {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,36 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, -# 'Tour of Duty Ticket': {'success': True, 'lowest_price': '9,21 kr', 'volume': '668', 'median_price': '9,61 kr'}} +# {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,36 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, +# 'Tour of Duty Ticket': {'success': True, 'lowest_price': '9,21 kr', 'volume': '668', 'median_price': '9,61 kr'}} @@ -30,8 +30,8 @@ appids = [440, 730] # 440 is TF2, 730 is CSGO. # These two lists MUST have the same length. In this case they both have 2 elements. market.get_prices(items, appids) -# >>> {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,01 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, -# 'AWP | Atheris (Field-Tested)': {'success': True, 'lowest_price': '47,68 kr', 'volume': '1,381', 'median_price': '45,39 kr'}} +# {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,01 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, +# 'AWP | Atheris (Field-Tested)': {'success': True, 'lowest_price': '47,68 kr', 'volume': '1,381', 'median_price': '45,39 kr'}} @@ -46,5 +46,5 @@ } market.get_prices_from_dict(items) -# >>> {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,36 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, -# 'AK-47 | Redline (Field-Tested)': {'success': True, 'lowest_price': '136,51 kr', 'volume': '749', 'median_price': '131,36 kr'}} +# {'Mann Co. Supply Crate Key': {'success': True, 'lowest_price': '22,36 kr', 'volume': '6,489', 'median_price': '21,75 kr'}, +# 'AK-47 | Redline (Field-Tested)': {'success': True, 'lowest_price': '136,51 kr', 'volume': '749', 'median_price': '131,36 kr'}} From bbbdf95fdc5e9ad2f7982156c62a2c9706def87c Mon Sep 17 00:00:00 2001 From: offish Date: Fri, 10 Jan 2020 23:08:55 +0100 Subject: [PATCH 10/10] Update README.md --- README.md | 77 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 65a526f..bc4cf51 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # steam_community_market [![Version](https://img.shields.io/pypi/v/steam_community_market.svg)](https://pypi.org/project/steam_community_market/) -[![License](https://img.shields.io/github/license/offish/steam_community_market.svg)](https://github.com/offish/steam_community_market/blob/master/LICENSE.txt) +[![License](https://img.shields.io/github/license/offish/steam_community_market.svg)](https://github.com/offish/steam_community_market/blob/master/LICENSE) [![Stars](https://img.shields.io/github/stars/offish/steam_community_market.svg)](https://github.com/offish/steam_community_market/stargazers) [![Issues](https://img.shields.io/github/issues/offish/steam_community_market.svg)](https://github.com/offish/steam_community_market/issues) +[![Size]('https://img.shields.io/github/repo-size/offish/steam_community_market.svg)]() [![Discord](https://img.shields.io/discord/467040686982692865.svg)](https://discord.gg/t8nHSvA)
[![Steam Donate Button](https://img.shields.io/badge/donate-steam-green.svg)](https://steamcommunity.com/tradeoffer/new/?partner=293059984&token=0-l_idZR "Support this project via Steam") @@ -32,7 +33,7 @@ from steam_community_market.market import Market market = Market('USD') ``` -`'USD'` can either be `str` or `int`. Find the currencies supported [here](https://github.com/offish/steam_community_market/blob/master/steam_community_market/market.py#L5). +`'USD'` can either be `str`, `int` or empty. Find the currencies supported [here](https://github.com/offish/steam_community_market/blob/master/steam_community_market/market.py#L5). @@ -50,12 +51,44 @@ Methods `app_id`: The AppID of the item. -### Get multiple items: +### Get multiple items with different AppIDs: -**get_prices(names: list, app_id: int)** +**get_prices(names: list, app_id: (int, list))** ```python ->>> items = ['Prisma Case', 'Danger Zone Case', 'Supermega Case'] +>>> items = ['Prisma Case', 'Danger Zone Case', 'Spectrum 10 Case'] +>>> appids = [730, 730, 440] +>>> market.get_prices(items, appids) +{ + 'Prisma Case': { + 'success': True, + 'lowest_price': '$0.39', + 'volume': '59,613', + 'median_price': '$0.41' + }, + + 'Danger Zone Case': { + 'success': True, + 'lowest_price': '$0.20', + 'volume': '56,664', + 'median_price': '$0.22' + }, + + 'Spectrum 10 Case': { + 'success': False + } +} +``` +`names`: A list of items how each item name (market_hash_name) appears on the Steam Community Market. + +`app_id`: A list of AppIDs. + +### Get multiple items with the same AppID: + +**get_prices(names: list, app_id: (int, list))** + +```python +>>> items = ['Prisma Case', 'Danger Zone Case', 'Spectrum 10 Case'] >>> market.get_prices(items, 730) { 'Prisma Case': { @@ -72,24 +105,52 @@ Methods 'median_price': '$0.22' }, - 'Supermega Case': { + 'Spectrum 10 Case': { 'success': False } } ``` `names`: A list of items how each item name (market_hash_name) appears on the Steam Community Market. -`app_id`: The AppID of the items. +`app_id`: The AppID of the items. **All of the items listed in `names` must have the same `app_id`.** +### Get multiple items with different AppIDs from dict + +**get_prices_from_dict(items: dict)** +```python +>>> items = { + "Mann Co. Supply Crate Key": { + "appid": 440 + }, + "AK-47 | Redline (Field-Tested)": { + "appid": 730 + } + } +>>> market.get_prices_from_dict(items) +{ + 'Mann Co. Supply Crate Key': { + 'success': True, + 'lowest_price': '$2.50', + 'volume': '6,489', + 'median_price': '$2.45' + }, + 'AK-47 | Redline (Field-Tested)': { + 'success': True, + 'lowest_price': '$15.00', + 'volume': '749', + 'median_price': '$14.78' + } +} +``` License ======= MIT License -Copyright (c) 2019 [offish](mailto:overutilization@gmail.com) +Copyright (c) 2020 [offish](mailto:overutilization@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal