O
O
oneZe2021-08-25 15:03:09
Python
oneZe, 2021-08-25 15:03:09

How to parse Steam sales history?

I am writing a steam trading platform parser. I found a query that returns a massive json list with the item's sales history for the entire time period. How can I extract data from a given array for a certain period of time, a month, a week, or a certain date?

import steam.webauth as wa
user = wa.WebAuth('login')
session = user.cli_login('password')
session.get('https://store.steampowered.com/account/history')

link = 'https://steamcommunity.com/market/pricehistory/?country=DE&currency=3&appid=440&market_hash_name=Specialized%20Killstreak%20Brass%20Beast'

resp = session.get(link)
result = resp.json()
print(result)


Answer:
{'success': True, 'price_prefix': '$', 'price_suffix': '', 'prices': [['Nov 27 2013 01: +0', 16.99, '1'], ['Nov 29 2013 01: +0', 17.205, '2'],.....

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
soremix, 2021-08-25
@oneZe

If it’s simple, then you can simply enter the start and end dates, and then display everything by brute force

start = 'May 29 2014'
end = 'Nov 07 2014'

is_found = False

for data in resp['prices']:
    if data[0].startswith(start):
        is_found = True

    elif data[0].startswith(end):
        is_found = False
        break

    if is_found:
        print(data[1])

If it's complicated - we import datetime, convert the date into a datetime object, and iterate through the list in the same way, while comparing the date objects with the necessary pieces
from datetime import datetime

start = datetime.strptime('May 29 2014', '%b %d %Y')
end = datetime.strptime('Nov 07 2014', '%b %d %Y')

1
12rbah, 2021-08-25
@12rbah

How can I extract data from a given array for a certain period of time, a month, a week, or a certain date?
You move through the
elements of the array and check each date, if it is included in the interval, then take the necessary information from the element, if not, then move on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question