Browse Source

cleanup

ansible-setup-and-deploy
Alex 7 years ago
parent
commit
223a64738d
  1. 5
      .gitignore
  2. BIN
      app/__init__.pyc
  3. BIN
      app/__pycache__/__init__.cpython-36.pyc
  4. BIN
      app/__pycache__/forms.cpython-36.pyc
  5. BIN
      app/__pycache__/models.cpython-36.pyc
  6. BIN
      app/__pycache__/views.cpython-36.pyc
  7. 56
      app/cover.py
  8. BIN
      app/forms.pyc
  9. BIN
      app/models.pyc
  10. 37
      app/templates/edit_book_detail.html
  11. 30
      app/templates/red_link.html
  12. BIN
      app/views.pyc

5
.gitignore

@ -0,0 +1,5 @@
__pycache__/
*.pyc
*~
app/uploads/
app/mydatabase.db

BIN
app/__init__.pyc

Binary file not shown.

BIN
app/__pycache__/__init__.cpython-36.pyc

Binary file not shown.

BIN
app/__pycache__/forms.cpython-36.pyc

Binary file not shown.

BIN
app/__pycache__/models.cpython-36.pyc

Binary file not shown.

BIN
app/__pycache__/views.cpython-36.pyc

Binary file not shown.

56
app/cover.py

@ -0,0 +1,56 @@
import PyPDF2
from wand.image import Image
import io
import os
def pdf_page_to_png(src_pdf, pagenum = 0, resolution = 72,):
"""
Returns specified PDF page as wand.image.Image png.
:param PyPDF2.PdfFileReader src_pdf: PDF from which to take pages.
:param int pagenum: Page number to take.
:param int resolution: Resolution for resulting png in DPI.
"""
dst_pdf = PyPDF2.PdfFileWriter()
dst_pdf.addPage(src_pdf.getPage(pagenum))
pdf_bytes = io.BytesIO()
dst_pdf.write(pdf_bytes)
pdf_bytes.seek(0)
img = Image(file = pdf_bytes, resolution = resolution)
img.convert("png")
return img
def get_cover(file_path, filename):
# Main
# ====
print(file_path)
src_filename = file_path
src_pdf = PyPDF2.PdfFileReader(open(src_filename, "rb"))
# What follows is a lookup table of page numbers within sample_log.pdf and the corresponding filenames.
pages = [{"pagenum": 0, "filename": filename}]
# Convert each page to a png image.
for page in pages:
big_filename = "app/uploads/cover/"+page["filename"] + "_cover.png"
small_filename = "app/uploads/cover/"+page["filename"] + "cover_small" + ".png"
img = pdf_page_to_png(src_pdf, pagenum = page["pagenum"], resolution = 300)
img.save(filename = big_filename)
# Ensmallen
img.transform("", "200")
img.save(filename = small_filename)
return page["filename"] + "_cover.png"
#---
#epub
#https://ebooks.stackexchange.com/questions/6517/command-line-extraction-of-metadata-title-author-from-epub-file
#https://hackage.haskell.org/package/epub-tools
#http://stackoverflow.com/questions/9751475/extract-cover-image-from-chm-and-epub-files

BIN
app/forms.pyc

Binary file not shown.

BIN
app/models.pyc

Binary file not shown.

37
app/templates/edit_book_detail.html

@ -0,0 +1,37 @@
{% extends 'base.html' %}
{% block main %}
<div class="container">
<a href="{{ url_for('show_book_by_id', id=book.id )}}">back</a>
<form method="POST" action="{{ url_for('edit_book_by_id', id=book.id )}}">
{{ form.csrf_token }}
<div class="form-group"><h1 class="header">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</h1></div>
<img src="../../uploads/cover/{{ book.cover }}" width="200">
<br> <br>
<div data-toggle="fieldset" id="phone-fieldset">
{{ form.author.label }} <button type="button" data-toggle="fieldset-add-row"
data-target="#phone-fieldset">+</button>
<table>
<tr>
<th></th>
<th></th>
</tr>
{% for author in form.author %}
<tr data-toggle="fieldset-entry">
<td>{{ author.author_name }}</td>
<td><button type="button" data-toggle="fieldset-remove-row" id="phone-{{loop.index0}}-remove">-</button></td>
</tr>
{% endfor %}
</table>
</div>
<br>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
{% endblock %}

30
app/templates/red_link.html

@ -0,0 +1,30 @@
{% extends "base.html" %}
{% block title %}Red link page{% endblock %}
{% block css %}
<style type="text/css">
body{
padding-top: 40px;
}
h1, p{
text-align:center;
}
h1{
font-size:44px;
margin:75px 0 50px;
}
p{
font-size:14px;
margin:15px 0;
}
</style>
{% endblock %}
{% block header %}{% endblock %}
{% block main %}
<h1>ID: {{ id }}</h1>
<p>red link page</p>
<p><a href="{{ url_for('home') }}">go back home</a>?</p>
{% endblock %}

BIN
app/views.pyc

Binary file not shown.
Loading…
Cancel
Save