Compare commits
No commits in common. "main" and "master" have entirely different histories.
4 changed files with 3281 additions and 3 deletions
|
@ -1,3 +0,0 @@
|
|||
# Bookshelf
|
||||
|
||||
Downloader für raspi bookshelf
|
1608
magpi all.json
Normal file
1608
magpi all.json
Normal file
File diff suppressed because it is too large
Load diff
1608
magpi.json
Normal file
1608
magpi.json
Normal file
File diff suppressed because it is too large
Load diff
65
main.py
Normal file
65
main.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
|
||||
import requests
|
||||
import xmltodict
|
||||
import json
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
|
||||
os.makedirs('magpis', exist_ok=True)
|
||||
os.makedirs('hackspaces', exist_ok=True)
|
||||
os.makedirs('books', exist_ok=True)
|
||||
|
||||
# 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