This repository was archived by the owner on Jul 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck_downloader.py
More file actions
executable file
·75 lines (62 loc) · 2.34 KB
/
deck_downloader.py
File metadata and controls
executable file
·75 lines (62 loc) · 2.34 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
# !/usr/bin/env python3
from bs4 import BeautifulSoup
from lib.classes import Card, Deck
from deck_importer import DeckImporter
import argparse
import requests
import sys
class DeckDownloader(object):
def __init__(self, url, importer=False):
self.deck = Deck()
self.filename = url.rsplit('/', 1)[-1]
self.path = ""
self.url = url
self.importer = importer
def run(self):
self.check()
self.deck.save(path="%s%s" % (self.path, self.filename))
if self.importer:
importer = DeckImporter(filename="%s%s" % (self.path, self.filename))
importer.run()
def check(self):
websites = ("hearthpwn.com/decks/",
"icy-veins.com/hearthstone/")
if any(item in self.url for item in websites):
self.download()
else:
sys.exit("[-] unknown website: %s" % self.url)
def download(self):
print("[+] Downloading deck from %s" % self.url)
if "hearthpwn" in self.url:
self.path = "_decks/hearthpwn/"
data = requests.get(self.url).text
data = BeautifulSoup(data, 'html.parser')
data = data.findAll("aside", {"class": "infobox"})
data = data[0].findAll('a')
for item in data:
if item.has_attr('data-count'):
c = Card(item.string[7:-6], "", "")
self.deck.take_card(c)
if int(item["data-count"]) == 2:
self.deck.take_card(c)
elif "icy-veins" in self.url:
self.path = "_decks/icyveins/"
data = requests.get(self.url).text
data = BeautifulSoup(data, 'html.parser')
data = data.findAll("table", {"class": "deck_card_list"})
data = data[0].findAll('li')
for item in data:
c = Card(item.a.text, "", "")
self.deck.take_card(c)
if int(item.text[0]) == 2:
self.deck.take_card(c)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("url", type=str)
parser.add_argument("-i", "--importer", action="store_true")
args = parser.parse_args()
downloader = DeckDownloader(url=args.url, importer=args.importer)
downloader.run()
if __name__ == '__main__':
main()