-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNCP.py
64 lines (46 loc) · 1.46 KB
/
NCP.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json, requests, shutil, os, subprocess
# Fetch NRDB api etc
nrdburl = "https://netrunnerdb.com/api/2.0/public/cards"
nrdb_card_api = requests.get(nrdburl).json()
imgdict = {}
for item in nrdb_card_api["data"]:
name = item['title']
if "image_url" in item:
imgdict[name] = (item["image_url"], item["code"])
else:
imgdict[name] = ("https://netrunnerdb.com/card_image/{}.png".format(item["code"]), item["code"])
listOfCards = []
listOfCodes = []
with open("cards.txt", 'r') as f:
for line in f:
s = line.split()
num = int(s[0])
name = " ".join(s[1:])
listOfCards.append((name, num))
for name, num in listOfCards:
(img, code) = imgdict[name]
response = requests.get(img, stream=True)
with open("tmp/{}.png".format(code), 'wb') as f:
shutil.copyfileobj(response.raw, f)
for i in range(num):
listOfCodes.append(code)
# Create LaTeX doc here
texdoc = """\documentclass[a4paper]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{graphicx}
\\begin{document}
\pagestyle{empty}
\\noindent
"""
imgstr = "\includegraphics[height=89mm]{{tmp/{0}}}\hspace{{-1mm}}\n"
for code in listOfCodes:
texdoc += imgstr.format(code)
texdoc += "\end{document}"
with open("NCP.tex", "w+") as f:
f.write(texdoc)
process = subprocess.Popen(["pdflatex", "NCP.tex"])
process.communicate()
for filename in os.listdir("tmp"):
os.unlink("tmp/"+filename)