This commit is contained in:
stubbfel
2017-11-29 00:12:09 +01:00
commit 50b6b45459
9 changed files with 157 additions and 0 deletions

4
news2kindle.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
NAME=$1
xvfb-run ebook-convert recipe/$NAME.recipe mobi/$NAME.mobi --output-profile kindle
calibre-smtp -a mobi/$NAME.mobi -s $NAME stubbfel@b-tu.de stubbfel@kindle.com "$NAME"

1
python/dn2k/src/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.pyc

View File

@@ -0,0 +1,38 @@
__author__ = 'dev'
import subprocess
import os
import glob
EBOOK_CONVERT_CMD = "ebook-convert"
OUTPUT_PROFIL_OPTION = "--output-profile"
DEFAULT_OUTPUT_PROFIL = "kindle"
DEFAULT_FEED_MOBI_FILE_EXTENSION = ".mobi"
DEFAULT_FEED_RECIPE_FILE_EXTENSION = ".recipe"
def convert_feed(recipe_path, dst_path, profile=DEFAULT_OUTPUT_PROFIL):
recipe_path_abs = os.path.abspath(recipe_path)
dst_path_abs = os.path.abspath(dst_path)
if not os.path.exists(recipe_path_abs):
raise os.error.filename
if os.path.exists(dst_path_abs):
os.remove(dst_path_abs)
subprocess.call([EBOOK_CONVERT_CMD ,recipe_path_abs, dst_path_abs, OUTPUT_PROFIL_OPTION, profile])
def convert_all_feed(recipe_folder, dst_folder, profile=DEFAULT_OUTPUT_PROFIL, recipe_extension=DEFAULT_FEED_RECIPE_FILE_EXTENSION, mobi_extension=DEFAULT_FEED_MOBI_FILE_EXTENSION):
recipe_folder_path_abs = os.path.abspath(recipe_folder)
dst_folder_path_abs = os.path.abspath(dst_folder)
if not os.path.exists(recipe_folder_path_abs) or not os.path.exists(dst_folder_path_abs):
raise os.error.filename
for file in glob.glob(os.path.join(recipe_folder_path_abs, "*" + recipe_extension)):
file_base_name = os.path.splitext(os.path.basename(file))[0]
dst_path_abs = os.path.join(dst_folder_path_abs, file_base_name + mobi_extension)
if os.path.exists(dst_path_abs):
os.remove(dst_path_abs)
convert_feed(file, dst_path_abs, profile)

View File

@@ -0,0 +1,15 @@
__author__ = 'dev'
import subprocess
EBOOK_SEND_CMD = "calibre-smtp"
def send_feed(mobi_path, feed_name, sender_mail_address, dst_mail_address):
subprocess.call([EBOOK_SEND_CMD, "-a", mobi_path, "-s", feed_name, sender_mail_address, dst_mail_address, feed_name])
def send_feeds(feedDict, sender_mail_address, dst_mail_address):
for feed_name, mobi_path in feedDict.items():
send_feed(mobi_path, feed_name, sender_mail_address, dst_mail_address)

View File

@@ -0,0 +1 @@
*.pyc

View File

@@ -0,0 +1 @@
/moz.mobi

View File

@@ -0,0 +1,14 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
from __future__ import unicode_literals, division, absolute_import, print_function
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1422191832(BasicNewsRecipe):
title = 'moz'
oldest_article = 7
max_articles_per_feed = 100
auto_cleanup = True
feeds = [
('moz-brandenburg', 'http://www.moz.de/nc/service/weiteres/rss-feeds-auf-mozde/?type=578&tx_rsmretrescorss_pi1%5Bshow%5D=1')
]

View File

@@ -0,0 +1,49 @@
__author__ = 'dev'
import unittest
import os
import subprocess
import ConvertFeed
ABS_CUR = os.path.abspath(os.path.curdir)
TEST_FEED_NAME = "moz"
TEST_FEED_RECIPE_FOLDER = os.path.join(ABS_CUR, "recipe")
TEST_FEED_RECIPE_FILE_EXTENSION = ".recipe"
TEST_FEED_RECIPE = os.path.join(TEST_FEED_RECIPE_FOLDER, TEST_FEED_NAME + TEST_FEED_RECIPE_FILE_EXTENSION)
TEST_FEED_MOBI_FOLDER = os.path.join(ABS_CUR, "mobi")
TEST_FEED_MOBI_FILE_EXTENSION = ".mobi"
TEST_FEED_MOBI = os.path.join(TEST_FEED_MOBI_FOLDER, TEST_FEED_NAME + TEST_FEED_MOBI_FILE_EXTENSION)
TEST_OUTPUT_PROFIL = "kindle"
TEST_OUTPUT_PROFIL_OPTION = "--output-profile"
TEST_ECONVERT_CMD = "ebook-convert"
class TestEbookConvert(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_ebook_convert(self):
if os.path.exists(TEST_FEED_MOBI):
os.remove(TEST_FEED_MOBI)
ConvertFeed.convert_feed(TEST_FEED_RECIPE, TEST_FEED_MOBI)
self.assertTrue(os.path.exists(TEST_FEED_MOBI))
def test_ebook_convert_all_feed(self):
if os.path.exists(TEST_FEED_MOBI):
os.remove(TEST_FEED_MOBI)
ConvertFeed.convert_all_feed(TEST_FEED_RECIPE_FOLDER , TEST_FEED_MOBI_FOLDER)
self.assertTrue(os.path.exists(TEST_FEED_MOBI))
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,34 @@
__author__ = 'dev'
import unittest
import os
import SendFeed
ABS_CUR = os.path.abspath(os.path.curdir)
TEST_FEED_NAME = "moz"
TEST_FEED_MOBI_FOLDER = os.path.join(ABS_CUR, "mobi")
TEST_FEED_MOBI_FILE_EXTENSION = ".mobi"
TEST_FEED_MOBI = os.path.join(TEST_FEED_MOBI_FOLDER, TEST_FEED_NAME + TEST_FEED_MOBI_FILE_EXTENSION)
TEST_SENDER_MAIL = "stubbfel@b-tu.de"
TEST_DST_MAIL = "stubbfel@kindle.com"
TEST_FEED_DICT = {TEST_FEED_NAME: TEST_FEED_MOBI, TEST_FEED_NAME+"2": TEST_FEED_MOBI}
class TestSendFeed(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_send_feed(self):
SendFeed.send_feed(TEST_FEED_MOBI, TEST_FEED_NAME, TEST_SENDER_MAIL, TEST_DST_MAIL)
self.assertTrue(True)
def test_send_feeds(self):
SendFeed.send_feeds(TEST_FEED_DICT, TEST_SENDER_MAIL, TEST_DST_MAIL)
self.assertTrue(True)
if __name__ == '__main__':
unittest.main()