Last active
August 9, 2018 21:06
-
-
Save nv1t/b3cb40644ad44bbd697cfe0bab6c590a to your computer and use it in GitHub Desktop.
Takes the ID (param) from a Kiosk Magazin from the media.niu.de Entertainment Center as first Argument (https://media.niu.de/magazine.html?param=42281), downloads the pages of this magazine and generates a pdf with imagemagicks convert.
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 sys | |
import os | |
import requests | |
import subprocess | |
import urllib3 | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
param=sys.argv[1] | |
baseUrl = "https://media.niu.de/magazines/%s" % (param) | |
url="%s/magazine.json" % (baseUrl) | |
r = requests.get(url, verify=False) | |
magazin = r.json() | |
pages = magazin['pages'] | |
path = magazin["changeDate"]+"."+magazin["magazineTitle"] | |
os.mkdir("./%s" % (path)) | |
print("Downloading %s" % (path)) | |
for i in pages: | |
pageUrl = "%s/%s" % (baseUrl, i["image"]) | |
pageResponse = requests.get(pageUrl, verify=False) | |
if pageResponse.status_code == 200: | |
with open("%s/%s" % (path,i['image']), "wb") as f: | |
f.write(pageResponse.content) | |
print("Page %s saved" % (i["image"])) | |
print("Converting to PDF") | |
os.system("/usr/bin/convert \"%s/*.jpg\" \"%s.pdf\"" % (path,path)) | |
os.system("rm -rf \"%s\"" % (path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment