separate downloads and personal stash

This commit is contained in:
Bryan Bailey
2019-11-07 12:17:38 -05:00
parent fbcf6769ce
commit bbe2d7a8f7
5 changed files with 25 additions and 5 deletions

View File

@@ -16,7 +16,7 @@ login_manager.login_view = 'auth.login'
def create_app(config_name):
app = Flask(__name__)
app = Flask(__name__, static_url_path='')
app.config.from_object(config[config_name])
config[config_name].init_app(app)

View File

@@ -1,4 +1,5 @@
import os
from shutil import copyfile
from flask import render_template, session, redirect, url_for, flash, request, current_app
from . import main
from .forms import Ripper
@@ -16,7 +17,7 @@ def download_comic_files(soup):
comic_files = []
# set the image_folder name to the title of the comic
image_folder = os.path.join(current_app.config['STASH_FOLDER'], ripper.get_title(soup))
image_folder = os.path.join(current_app.config['DOWNLOAD_FOLDER'], ripper.get_title(soup))
print(image_folder)
# append each comic link found in the bs4 response to the comic file list
@@ -24,11 +25,21 @@ def download_comic_files(soup):
comic_files.append(link)
# download the completed comic list
ripper.download_img_links(comic_files, soup, current_app.config['STASH_FOLDER'])
ripper.download_img_links(comic_files, soup, current_app.config['DOWNLOAD_FOLDER'])
# create a comic archive from all images in image_folder
zipper.create_comic_archive(ripper.get_title(soup), image_folder)
# copy comic to stash
print('Copying comic to personal stash')
filename = ripper.get_title(soup) + '.cbr'
src = str(os.path.join(image_folder, filename))
print(src)
dest = str(os.path.join(current_app.config['STASH_FOLDER'], filename))
print(dest)
copyfile(src, dest)
@main.route('/', methods=accepted_methods)
def index():
@@ -37,6 +48,6 @@ def index():
if form.validate_on_submit():
soup = ripper.get_soup_obj(form.search.data, headers)
download_comic_files(soup)
return render_template('success.html')
return render_template('success.html', title=ripper.get_title(soup))
return render_template('index.html', form=form)

View File

@@ -1,6 +1,11 @@
<h1>Save All Comics!</h1>
<form action="" method="POST" enctype=multipart/form-data>
{{ form.hidden_tag() }}
<p>Please input a <a href="http://www.readallcomics.com" rel="Nofollow">Readallcomics.com</a> link</p>
{{ form.search(placeholder='Comic URL, eg: https://readallcomics.com/marauders-001-2019/') }}
{{ form.submit() }}
</form>
</form>
<h2>About Saveallcomics</h2>
<p>We hope you have enjoyed using Saveallcomics! We are a totally <strong>FREE</strong> project without profit.</p>
<p>&copy; 2019 <a href="">Saveallcomics</a>. Some rights reserved.</p>

View File

@@ -1,2 +1,5 @@
<h1>Huzzah! It Worked!</h1>
<h2>Download {{ title }}</h2>
{% set download = title + '/' + title + '.cbr' %}
<button><a href="{{ url_for('static', filename='download/' + download) }}">{{ title }}</a></button>
<a href="{{ url_for('main.index') }}">&laquo; Back to Home</a>