Update to properly utilize docker

Trying this, time to see if it works.
This commit is contained in:
MrTyton 2022-03-25 17:21:17 -04:00
parent a16654503d
commit 9833f81007
22 changed files with 2696 additions and 181 deletions

8
.gitignore vendored
View File

@ -98,11 +98,3 @@ ENV/
# mypy
.mypy_cache/
# Personal Files
config.ini
defaults.ini
fanfiction_file
notifications.py
personal.ini
run.sh

77
Dockerfile Normal file
View File

@ -0,0 +1,77 @@
FROM python:3.9-alpine
# set version label
ARG BUILD_DATE
ARG VERSION
ARG CALIBRE_RELEASE
ARG FFF_RELEASE
LABEL build_version="FFDL-Auto version:- ${VERSION} Calibre: ${CALIBRE_RELEASE} FFF: ${FFF_RELEASE} Build-date:- ${BUILD_DATE}"
RUN set -x && \
addgroup --gid "$PGID" abc && \
adduser \
--gecos "" \
--disabled-password \
--no-create-home \
--uid "$PUID" \
--ingroup abc \
--shell /bin/bash \
abc
RUN mkdir -p /opt/calibre && \
apk update && \
apk add --no-cache --upgrade \
bash \
ca-certificates \
gcc \
mesa-gl \
qt5-qtbase-x11 \
wget \
xdg-utils \
xz \
curl \
dbus \
jq \
python3
RUN echo "**** install calibre ****" && \
mkdir -p \
/opt/calibre && \
if [ -z ${CALIBRE_RELEASE+x} ]; then \
CALIBRE_RELEASE=$(curl -sX GET "https://api.github.com/repos/kovidgoyal/calibre/releases/latest" \
| jq -r .tag_name); \
fi && \
CALIBRE_VERSION="$(echo ${CALIBRE_RELEASE} | cut -c2-)" && \
CALIBRE_URL="https://download.calibre-ebook.com/${CALIBRE_VERSION}/calibre-${CALIBRE_VERSION}-x86_64.txz" && \
curl -o \
/tmp/calibre-tarball.txz -L \
"$CALIBRE_URL" && \
tar xvf /tmp/calibre-tarball.txz -C \
/opt/calibre && \
/opt/calibre/calibre_postinstall && \
dbus-uuidgen > /etc/machine-id
RUN echo "**** cleanup ****" && \
apt-get clean && \
rm -rf \
/tmp/* \
/var/lib/apt/lists/* \
/var/tmp/*
RUN echo *** Install Packages *** && \
apk add --no-cache --upgrade py-pillow && \
if [ -z ${FFF_RELEASE+x} ]; then \
python3 -m pip --no-cache-dir install FanFicFare \
else \
python3 -m pip --no-cache-dir install --extra-index-url https://testpypi.python.org/pypi FanFicFare==${FFF_RELEASE} \
fi && \
python3 -m pip --no-cache-dir install pushbullet.py && \
ln -s /opt/calibre/calibredb /bin/calibredb
COPY root/ /
VOLUME /config
WORKDIR /config
ENTRYPOINT ["/init"]

View File

@ -1,17 +0,0 @@
# AutomatedFanfic
Python script to automate the use of FanFicFare CLI (https://github.com/JimmXinu/FanFicFare) with calibre.
Primary script is fanficdownload.py. Use -h or --help to see the options.
All of the options can be loaded into the config file, of which the template is provided in `config_template.ini`, and utilized with `python3 fanficdownload.py -c path_to_config.ini`.
There is additional support for notifications, including pushbullet integration, through runner_notify. Use -h to see options.
Works with Fanficfare 2.3.6+. Rewrite underway to take advantage of new features in Fanficfare 2.4.0
Requires Python 3.6.9. Unsure if it will work on higher versions of Python.
For basic cron usage, this is not needed, `fanficfare -dowload-imap -u` should work if you're not integrating into calibre. This script is best used if you want to update the calibre library, for the usage of calibre-server for instance.
If anything does not work, please open a ticket.

View File

@ -1,85 +0,0 @@
# -- coding: utf-8 --
from win32api import *
from win32gui import *
import win32con
import sys, os
import struct
import time
import threading
import cmd
from os.path import join, dirname, abspath
# Class
class WindowsBalloonTip:
def __init__(self, title, msg):
message_map = { win32con.WM_DESTROY: self.OnDestroy,}
# Register the window class.
wc = WNDCLASS()
hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = 'PythonTaskbar'
wc.lpfnWndProc = message_map # could also specify a wndproc.
while True:
try:
classAtom = RegisterClass(wc)
break
except:
continue
# Create the window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = CreateWindow(classAtom, "Taskbar", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None)
UpdateWindow(self.hwnd)
# Icons managment
iconPathName = join(dirname(abspath(__file__)), 'ff.png')
#print iconPathName
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
try:
hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
except:
hicon = LoadIcon(0, win32con.IDI_APPLICATION)
flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, 'Tooltip')
# Notify
Shell_NotifyIcon(NIM_ADD, nid)
Shell_NotifyIcon(NIM_MODIFY, (self.hwnd, 0, NIF_INFO, win32con.WM_USER+20, hicon, 'Balloon Tooltip', msg, 200, title))
# self.show_balloon(title, msg)
time.sleep(5)
# Destroy
DestroyWindow(self.hwnd)
classAtom = UnregisterClass(classAtom, hinst)
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, nid)
#PostQuitMessage(0) # Terminate the app.
# Function
class myThread(threading.Thread):
def __init__(self, title, msg):
threading.Thread.__init__(self)
self.title = title
self.msg = msg
def run(self):
w = WindowsBalloonTip(self.title, self.msg)
def balloon_tip(title, msg):
thread1 = myThread(title, msg)
thread1.start()
return
#w=WindowsBalloonTip(title, msg)
class Notification():
def __init__(self):
pass
def send_notification(self, title, text):
balloon_tip(title, msg)

View File

@ -1,27 +0,0 @@
# Email Login Information, so that the script can download from email subscription notifications.
[login]
# Username for email
user=
# Password for email
password=
# IMAP address for email
server=
# The mailbox to look in the emails for, such as INBOX
mailbox=
[locations]
# Web Address for the calibre library to update
library=
# Path to file to read links from, or to output links that didn't work.
input=
# If you want to user runner_notify.py to send alerts to your phone, fill out the fields here.
[runner]
notification=
pushbullet=
pbdevice=
tag=
# How to display output. True will display as the program runs, false will wait until the end.
[output]
live=

BIN
ff.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,21 +0,0 @@
from gi import require_version as gir
gir('Notify', '0.7')
from gi.repository import GObject
from gi.repository import Notify
import sys
from os.path import join, dirname, abspath
class Notification(GObject.Object):
def __init__(self):
super(Notification, self).__init__()
# lets initialise with the application name
Notify.init("Fanfiction")
self.icon = join(dirname(abspath(__file__)), 'ff.png')
def send_notification(self, title, text):
n = Notify.Notification.new(title, text, self.icon)
n.show()

View File

@ -0,0 +1 @@
5.39.1

1
release-versions/fff.txt Normal file
View File

@ -0,0 +1 @@
4.11.1

View File

@ -0,0 +1 @@
Release: v2022.02.25

View File

@ -149,11 +149,12 @@ def downloader(args):
# story is not in calibre
cur = url
moving = 'cd "{}" && '.format(loc)
copyfile("personal.ini", "{}/personal.ini".format(loc))
output += log('\tRunning: {}python -m fanficfare.cli -u "{}" --update-cover --non-interactive'.format(
copyfile("/config/personal.ini", "{}/personal.ini".format(loc))
copyfile("/config/defaults.ini", "{}/defaults.ini".format(moving))
output += log('\tRunning: {}python3.9 -m fanficfare.cli -u "{}" --update-cover --non-interactive'.format(
moving, cur), 'BLUE', live)
res = check_output('{}python -m fanficfare.cli -u "{}" --update-cover'.format(
moving, cur), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
res = check_output('{}python3.9 -m fanficfare.cli -u "{}" --update-cover --non-interactive --config={}/personal.ini'.format(
moving, cur, loc), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
check_regexes(res)
if chapter_difference.search(res) or more_chapters.search(res):
output += log("\tForcing download update due to:",
@ -162,8 +163,8 @@ def downloader(args):
if line:
output += log("\t\t{}".format(line), 'WARNING', live)
res = check_output(
'{}python -m fanficfare.cli -u "{}" --force --update-cover --non-interactive'.format(
moving, cur), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
'{}python3.9 -m fanficfare.cli -u "{}" --force --update-cover --non-interactive --config={}/personal.ini'.format(
moving, cur, loc), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
check_regexes(res)
cur = get_files(loc, '.epub', True)[0]
@ -275,9 +276,12 @@ def main(user, password, server, label, inout_file, path, live):
if len(urls) == 1:
downloader([list(urls)[0], inout_file, path, True])
else:
p = Pool()
p.map(downloader, [[url, inout_file, path, live] for url in urls])
for url in urls:
downloader([url, inout_file, path, True])
with open(inout_file, "r") as fp:
urls = set([x.replace("\n", "") for x in fp.readlines()])
with open(inout_file, "w") as fp:
fp.writelines(["{}\n".format(x) for x in urls])
return

View File

@ -0,0 +1,8 @@
class Notification():
def __init__(self):
self.name="Fanfiction"
def send_notification(self, title, text):
return

16
root/app/run.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
function fix_linux_internal_host() {
DOCKER_INTERNAL_HOST="host.docker.internal"
if ! grep $DOCKER_INTERNAL_HOST /etc/hosts > /dev/null ; then
DOCKER_INTERNAL_IP=`/sbin/ip route | awk '/default/ { print $3 }' | awk '!seen[$0]++'`
echo -e "$DOCKER_INTERNAL_IP\t$DOCKER_INTERNAL_HOST" | tee -a /etc/hosts > /dev/null
fi
}
fix_linux_internal_host
python3 runner_notify.py -c config.ini
sleep 60

View File

@ -7,13 +7,11 @@ import ntpath
from os import utime
from os.path import join
from notifications import Notification
from pushbullet import Pushbullet
from optparse import OptionParser
from configparser import ConfigParser
def enable_notifications(options):
if options.pushbullet:
fail = False
@ -34,10 +32,6 @@ def enable_notifications(options):
temp_note.send_notification = pb.push_note
yield temp_note
if options.notify:
notary = Notification()
yield notary
def touch(fname, times=None):
with open(fname, 'a'):
@ -47,7 +41,7 @@ def touch(fname, times=None):
def main(options):
try:
res = check_output(
"python3 fanficdownload.py -c config.ini",
"python3.9 fanficdownload.py -c config.ini",
shell=True,
stderr=STDOUT)
except Exception as e:
@ -134,13 +128,6 @@ if __name__ == "__main__":
def updater(option, newval): return newval if newval != "" else option
try:
options.notify = updater(
options.notify, config.getboolean(
'runner', 'notification'))
except BaseException:
pass
try:
options.pushbullet = updater(
options.pushbullet, config.get(

View File

@ -0,0 +1,16 @@
[login]
user=
password=
server=
mailbox=
[locations]
library=
input=/config/fanfiction_file
[runner]
pushbullet=False
pbdevice=
[output]
live=False

File diff suppressed because it is too large Load Diff

View File

View File

@ -0,0 +1,140 @@
## This is an example of what your personal configuration might look
## like. Uncomment options by removing the '#' in front of them.
[defaults]
## [defaults] section applies to all formats and sites but may be
## overridden at several levels. Example:
## [defaults]
## titlepage_entries: category,genre, status
## [www.whofic.com]
## # overrides defaults.
## titlepage_entries: category,genre, status,dateUpdated,rating
## [epub]
## # overrides defaults & site section
## titlepage_entries: category,genre, status,datePublished,dateUpdated,dateCreated
## [www.whofic.com:epub]
## # overrides defaults, site section & format section
## titlepage_entries: category,genre, status,datePublished
## [overrides]
## # overrides all other sections
## titlepage_entries: category
## Some sites also require the user to confirm they are adult for
## adult content. Uncomment by removing '#' in front of is_adult.
is_adult:true
## Don't like the numbers at the start of chapter titles on some
## sites? You can use strip_chapter_numbers to strip them off. Just
## want to make them all look the same? Strip them off, then add them
## back on with add_chapter_numbers. Don't like the way it strips
## numbers or adds them back? See chapter_title_strip_pattern and
## chapter_title_add_pattern.
#strip_chapter_numbers:true
#add_chapter_numbers:true
## Add this to genre if there's more than one category.
#add_genre_when_multi_category: Crossover
[epub]
## include images from img tags in the body and summary of stories.
## Images will be converted to jpg for size if possible. Images work
## in epub format only. To get mobi or other format with images,
## download as epub and use Calibre to convert.
include_images:true
## If not set, the summary will have all html stripped for safety.
## Both this and include_images must be true to get images in the
## summary.
#keep_summary_html:true
## If set, the first image found will be made the cover image. If
## keep_summary_html is true, any images in summary will be before any
## in chapters.
make_firstimage_cover:true
## Resize images down to width, height, preserving aspect ratio.
## Nook size, with margin.
#image_max_size: 580, 725
## Change image to grayscale, if graphics library allows, to save
## space.
#grayscale_images: false
## Most common, I expect will be using this to save username/passwords
## for different sites. Here are a few examples. See defaults.ini
## for the full list.
[www.twilighted.net]
#username:YourPenname
#password:YourPassword
## default is false
#collect_series: true
[ficwad.com]
#username:YourUsername
#password:YourPassword
[www.adastrafanfic.com]
## Some sites do not require a login, but do require the user to
## confirm they are adult for adult content.
#is_adult:true
[www.fictionalley.org]
#is_adult:true
[www.harrypotterfanfiction.com]
#is_adult:true
[www.fimfiction.net]
#is_adult:true
#fail_on_password: false
[www.tthfanfic.org]
#is_adult:true
## tth is a little unusual--it doesn't require user/pass, but the site
## keeps track of which chapters you've read and won't send another
## update until it thinks you're up to date. This way, on download,
## it thinks you're up to date.
#username:YourName
#password:yourpassword
[www.fanfiction.net]
check_next_chapter:true
skip_author_cover:false
user_agent:Mozilla/5.0
continue_on_chapter_error:false
# for use with the workaround
#use_nsapa_proxy:true
#use_cloudscraper:false
use_flaresolverr_proxy:true
# option settings, these are the defaults:
flaresolverr_proxy_address:localhost
flaresolverr_proxy_port:8191
flaresolverr_proxy_protocol:http
## This option if uncommented, will put a box around the spoiler
## blocks with the original spoiler button text as a label using
## fieldset and legend HTML tags. For a simple box, see the
## add_to_output_css example for [base_xenforoforum:epub].
#legend_spoilers:true
## This section will override anything in the system defaults or other
## sections here.
[overrides]
## default varies by site. Set true here to force all sites to
## collect series.
#collect_series: true
# Change oneshot to ['Completed'] to ['Completed','Oneshot'] only when
# numChapters is exactly 1.
# with ',' instead of '\,' it would be ['Completed'] to
# ['Completed,Oneshot']--one string instead of two.
add_to_replace_metadata:
oneshot=>Completed=>Completed\,Oneshot&&numChapters=>^1$

View File

@ -0,0 +1,25 @@
#!/usr/bin/with-contenv sh
if ! [ -f "/config/config.ini" ]
then
echo "[default-confs] restoring default 'config.ini'."
cp /config.default/config.ini /config/
fi
if ! [ -f "/config/defaults.ini" ]
then
echo "[default-confs] restoring default 'defaults.ini'."
cp /config.default/defaults.ini /config/
fi
if ! [ -f "/config/personal.ini" ]
then
echo "[default-confs] restoring default 'personal.ini'."
cp /config.default/personal.ini /config/
fi
if ! [ -f "/config/fanfiction_file" ]
then
echo "[default-confs] restoring default 'fanfiction_file'."
cp /config.default/fanfiction_file /config/
fi

View File

@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bash
groupmod -o -g "$PGID" abc
usermod -o -u "$PUID" abc
chown -R abc:abc /app
chown -R abc:abc /config
chmod +x /app/run.sh

View File

@ -0,0 +1,11 @@
#!/usr/bin/with-contenv sh
echo "
UID/GID
---------------------------------------
User uid: $(id -u abc)
User gid: $(id -g abc)
---------------------------------------
Image Made By: MrTyton
"

View File

@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bash
sleep 30s
exec s6-setuidgid abc /app/run.sh