init
This commit is contained in:
commit
adced9d215
1 changed files with 62 additions and 0 deletions
62
main.py
Normal file
62
main.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
|
||||
import requests
|
||||
import xmltodict
|
||||
import json
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
# Laden der XML-Daten
|
||||
#bookshelf_xml = requests.get("https://magpi.raspberrypi.com/bookshelf.xml")
|
||||
#bookshelf_dict = xmltodict.parse(bookshelf_xml.content)
|
||||
#bookshelf_json = json.dumps(magpi_dict, indent=4)
|
||||
bookshelf_json = json.dumps(open("magpi.json","r").read())
|
||||
|
||||
for item in bookshelf_dict["PUBS"]["MAGPI"]["ITEM"]:
|
||||
title = item["TITLE"]
|
||||
pdf_url = item["PDF"]
|
||||
|
||||
print(f"Downloading MagPi:{title}... ")#, end="", flush=True)
|
||||
|
||||
# Herunterladen der PDF-Datei mit Fortschrittsanzeige
|
||||
response = requests.get(pdf_url, stream=True)
|
||||
total_size = int(response.headers.get('content-length', 0))
|
||||
block_size = 1024 # 1 Kibibyte
|
||||
|
||||
with open(f"magpis/{title}.pdf", "wb") as pdf:
|
||||
for data in tqdm(response.iter_content(block_size), total=total_size//block_size, unit='KiB', unit_scale=True):
|
||||
pdf.write(data)# Herunterladen der Magazine
|
||||
|
||||
|
||||
|
||||
for item in bookshelf_dict["PUBS"]["HACKSPACE"]["ITEM"]:
|
||||
title = item["TITLE"]
|
||||
pdf_url = item["PDF"]
|
||||
|
||||
print(f"Downloading Hackspace:{title}... ")#, end="", flush=True)
|
||||
|
||||
# Herunterladen der PDF-Datei mit Fortschrittsanzeige
|
||||
response = requests.get(pdf_url, stream=True)
|
||||
total_size = int(response.headers.get('content-length', 0))
|
||||
block_size = 1024 # 1 Kibibyte
|
||||
|
||||
with open(f"hackspaces/{title}.pdf", "wb") as pdf:
|
||||
for data in tqdm(response.iter_content(block_size), total=total_size//block_size, unit='KiB', unit_scale=True):
|
||||
pdf.write(data)
|
||||
|
||||
|
||||
|
||||
for item in bookshelf_dict["PUBS"]["BOOKS"]["ITEM"]:
|
||||
title = item["TITLE"]
|
||||
pdf_url = item["PDF"]
|
||||
|
||||
print(f"Downloading Book:{title}... ")#, end="", flush=True)
|
||||
|
||||
# Herunterladen der PDF-Datei mit Fortschrittsanzeige
|
||||
response = requests.get(pdf_url, stream=True)
|
||||
total_size = int(response.headers.get('content-length', 0))
|
||||
block_size = 1024 # 1 Kibibyte
|
||||
|
||||
with open(f"books/{title}.pdf", "wb") as pdf:
|
||||
for data in tqdm(response.iter_content(block_size), total=total_size//block_size, unit='KiB', unit_scale=True):
|
||||
pdf.write(data)
|
Loading…
Reference in a new issue