-
Notifications
You must be signed in to change notification settings - Fork 0
/
comic.py
executable file
·63 lines (51 loc) · 1.45 KB
/
comic.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
#!/usr/bin/env python3
from comicGetter import comicGetter
from pdfWriter import pdfWriter
import json
import yaml
import signal
import os.path
# so that if ^C is pressed, the script can clean up
killed = False
def signalHandler(signum, frame):
global killed
if killed:
exit()
print('stopped; cleaning up...')
killed = True
signal.signal(signal.SIGINT, signalHandler)
filename = 'comic.json' if os.path.isfile('comic.json') else 'comic.yml'
with open(filename, 'r') as file:
info = json.load(file) if filename == 'comic.json' else yaml.safe_load(file)
name = info["name"]
author = info["author"]
pageColor = info["pageColor"]
textColor = info["textColor"]
firstURL = info["firstURL"]
height = info.get("optionalHeight")
width = info.get("optionalWidth")
jpgQuality = info.get("jpgQuality")
limit = info.get("limit")
pdf = pdfWriter(name, author, pageColor, textColor, height, width, jpgQuality)
comic = comicGetter(info)
comic.setURLifUnset(firstURL)
def limitReached():
return limit and pdf.comicNumber + 1 >= limit
try:
while comic.validURL() and not killed and not limitReached():
pdf.addComic(comic)
comic.save()
pdf.save()
print("\n")
print(pdf.comicNumber + 1)
print("****\t****\t****")
comic.advance()
except RuntimeError:
print("Warning: pressing ^C when running javascript could have unintended consequences")
if not killed:
print("finishing")
if pdf.comicNumber == 0:
pdf.addComic(comic)
comic.save()
pdf.save()
pdf.finish()