Skip to content

Instantly share code, notes, and snippets.

@windwarrior
Created January 11, 2017 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save windwarrior/393b64596c6fff1224c135d2069bb26f to your computer and use it in GitHub Desktop.
Save windwarrior/393b64596c6fff1224c135d2069bb26f to your computer and use it in GitHub Desktop.
import requests
import datetime
from functools import reduce
from operator import add
def main():
max_pages = 3
i = 0
running_total = 0
while i < max_pages:
request_string = "https://api.guildwars2.com/v2/commerce/listings?page={}&page_size=200".format(i)
print("Requesting page {} of {}".format(i, max_pages))
result = requests.get(request_string)
max_pages = int(result.headers['X-Page-Total'])
item_array = result.json()
running_total += reduce(add,
map(lambda x: reduce(add,
map(lambda y: y["listings"] * y["unit_price"] * y["quantity"], x["buys"]),
0),
item_array),
0)
print(running_total)
i += 1
print("Total there is {} on the TP".format(running_total))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment