2016-03-28 18:30:05 +00:00
|
|
|
import requests
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
mobigen_url = settings.MOBIGEN_URL
|
|
|
|
mobigen_user_id = settings.MOBIGEN_USER_ID
|
|
|
|
mobigen_password = settings.MOBIGEN_PASSWORD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_to_mobi(input_url, input_format="application/epub+zip"):
|
|
|
|
|
|
|
|
"""
|
|
|
|
return a string with the output of mobigen computation
|
|
|
|
|
|
|
|
"""
|
2018-11-03 21:23:07 +00:00
|
|
|
|
2016-03-28 18:30:05 +00:00
|
|
|
# using verify=False since at the moment, using a self-signed SSL cert.
|
|
|
|
|
2018-06-09 19:54:14 +00:00
|
|
|
payload = requests.get(input_url).content
|
2016-03-28 18:30:05 +00:00
|
|
|
|
|
|
|
headers = {'Content-Type': input_format}
|
|
|
|
r = requests.post(mobigen_url, auth=(mobigen_user_id, mobigen_password),
|
2018-06-09 19:54:14 +00:00
|
|
|
data=payload, headers=headers)
|
2016-03-28 18:30:05 +00:00
|
|
|
|
|
|
|
# if HTTP reponse code is ok, the output is the mobi file; else error message
|
|
|
|
if r.status_code == 200:
|
|
|
|
return r.content
|
|
|
|
else:
|
|
|
|
raise Exception("{0}: {1}".format(r.status_code, r.content))
|
|
|
|
|