-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts.py
executable file
·46 lines (40 loc) · 1.29 KB
/
ts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
from __future__ import print_function
import json
import os
import sys
import requests
import pprint
from bs4 import BeautifulSoup
pp = pprint.PrettyPrinter(indent=4)
post_url = 'https://tempostorm.com/deck'
def get_cards_from_card_list(card_list):
cards = dict()
count = 0
for x in card_list:
card = x['card']['name']
count_str = x['qty']
count = int(count_str)
#print("%s x %d" % (card, count))
cards[card] = count
return cards
def url_to_decklist(url):
slug = url.split('/')[-1]
headers = { 'Content-type' : 'application/json' } # , 'Accept' : 'text/plain' }
payload = { 'slug' : slug }
r = requests.post(post_url, data=json.dumps(payload), headers=headers)
data = json.loads(r.content.decode('utf-8'))
#pp.pprint(data)
card_list = data['deck']['cards']
#print(card_list.prettify().encode('utf-8'))
decklist = get_cards_from_card_list(card_list)
return decklist
def print_decklist(decklist):
for card, count in decklist.items():
print("%s x %d" % (card, count))
if __name__ == "__main__":
#url = 'https://tempostorm.com/hearthstone/decks/era-control-mage'
url = sys.argv[1].rstrip()
decklist = url_to_decklist(url)
#pp.pprint(decklist)
print_decklist(decklist)