Last active
January 7, 2018 00:34
-
-
Save rneiss/55bc4cd085a5d1bc075e8b3b90447fe3 to your computer and use it in GitHub Desktop.
Generate printed Mishnah Sheets from Sefaria
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 pdfkit | |
import requests | |
import json | |
pdf_options = { | |
'page-size': 'Letter', | |
'margin-top': '0.5in', | |
'margin-right': '0.75in', | |
'margin-bottom': '0.5in', | |
'margin-left': '0.75in', | |
'encoding': "UTF-8", | |
} | |
bookRefList = ["Mishnah_Bava_Kamma","Mishnah_Bava_Metzia","Mishnah_Bava_Batra","Mishnah_Sanhedrin", "Mishnah_Makkot","Mishnah_Shevuot","Mishnah_Eduyot","Mishnah_Avodah_Zarah","Pirkei_Avot","Mishnah_Horayot"] | |
def loop_through_chapter(ref): | |
url = 'http://www.sefaria.org/api/texts/'+ref | |
params = dict( | |
commentary=0, | |
context=0 | |
) | |
resp = requests.get(url=url, params=params) | |
data = json.loads(resp.text) | |
en = data["text"] | |
he = data["he"] | |
text = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<h1 style='text-align:center'> | |
""" + data["sectionRef"] + "</h1><hr><br>" | |
for i in range(0, len(he)): | |
text = text + "<div style='text-align:center'>-"+ str(i+1) +"-</div><p style='text-align: right; direction: rtl;'>"+he[i]+"</p>" +"<p>"+en[i]+ "</p><br>" | |
text = text + "<div style='text-align:center'><img src='http://www.sefaria.org/static/img/samekh.png' height=100><div>Made with the Sefaria API</div></div></body></html>" | |
pdfkit.from_string(text, data["sectionRef"]+'.pdf', options=pdf_options) | |
if data["next"]: | |
loop_through_chapter(data["next"]) | |
for book in bookRefList: | |
loop_through_chapter(book) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment