-
-
Save windwarrior/393b64596c6fff1224c135d2069bb26f to your computer and use it in GitHub Desktop.
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
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