commit 7a15460cea585cb1d47e551ef234cf5b80c1483b Author: Michel Roux Date: Sat Apr 10 23:53:47 2021 +0200 First draft diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..8e89cc3 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,43 @@ +kind: pipeline +name: default +type: docker + +steps: + - name: flake8 + image: python:slim + commands: + - pip install flake8 + - flake8 + - name: epub + image: python:slim + commands: + - pip install -r requirements.txt + - python livres_fr.py + - python livres_en.py + - name: pdf + image: svensp/ebook-convert + commands: + - ebook-convert "output/L'auberge Vagabonde - Volume 1.epub" "output/L'auberge Vagabonde - Volume 1.pdf" + - ebook-convert "output/L'auberge Vagabonde - Volume 2.epub" "output/L'auberge Vagabonde - Volume 2.pdf" + - ebook-convert "output/The Wandering Inn - Volume 3.epub" "output/The Wandering Inn - Volume 3.pdf" + - ebook-convert "output/The Wandering Inn - Volume 4.epub" "output/The Wandering Inn - Volume 4.pdf" + - ebook-convert "output/The Wandering Inn - Volume 5.epub" "output/The Wandering Inn - Volume 5.pdf" + - ebook-convert "output/The Wandering Inn - Volume 6.epub" "output/The Wandering Inn - Volume 6.pdf" + - ebook-convert "output/The Wandering Inn - Volume 7.epub" "output/The Wandering Inn - Volume 7.pdf" + - name: upload + image: curlimages/curl + commands: + - curl -Ss -u "$USER":"$PASS" -T "output/L'auberge Vagabonde - Volume 1.epub" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/L'auberge Vagabonde - Volume 1.epub" + - curl -Ss -u "$USER":"$PASS" -T "output/L'auberge Vagabonde - Volume 1.pdf" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/L'auberge Vagabonde - Volume 1.pdf" + - curl -Ss -u "$USER":"$PASS" -T "output/L'auberge Vagabonde - Volume 2.epub" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/L'auberge Vagabonde - Volume 2.epub" + - curl -Ss -u "$USER":"$PASS" -T "output/L'auberge Vagabonde - Volume 2.pdf" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/L'auberge Vagabonde - Volume 2.pdf" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 3.epub" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 3.epub" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 3.pdf" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 3.pdf" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 4.epub" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 4.epub" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 4.pdf" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 4.pdf" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 5.epub" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 5.epub" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 5.pdf" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 5.pdf" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 6.epub" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 6.epub" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 6.pdf" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 6.pdf" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 7.epub" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 7.epub" + - curl -Ss -u "$USER":"$PASS" -T "output/The Wandering Inn - Volume 7.pdf" "https://cloud.crystalyx.net/remote.php/dav/files/$USER/Public/TWI/The Wandering Inn - Volume 7.pdf" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79774db --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +.venv +output diff --git a/cover.png b/cover.png new file mode 100644 index 0000000..7f91ed9 Binary files /dev/null and b/cover.png differ diff --git a/livres_en.py b/livres_en.py new file mode 100644 index 0000000..dd6c320 --- /dev/null +++ b/livres_en.py @@ -0,0 +1,52 @@ +import os + +import requests +from bs4 import BeautifulSoup +from pypub import Epub, create_chapter_from_string + +if not os.path.exists('output'): + os.makedirs('output') + +html = requests.get('https://wanderinginn.com/table-of-contents/') +soup = BeautifulSoup(html.text, 'html.parser') + +tags = soup.select('div.entry-content > p') +proceed = True +volume = 0 +volumes = [None, None, None] + +for volume_tag in tags: + if not proceed: + proceed = True + continue + + if 'Volume' in volume_tag.get_text() and int(volume_tag.get_text().replace('Volume ', '')) < 3: + proceed = False + continue + + if 'Volume' in volume_tag.get_text(): + volume = int(volume_tag.get_text().replace('Volume ', '')) + volumes.append(Epub("The Wandering Inn - Volume %d" % volume, cover='cover.png')) + continue + + for link_tag in volume_tag: + if link_tag.name == 'a': + chapter = requests.get(link_tag['href']) + chapter_soup = soup = BeautifulSoup(chapter.text, 'html.parser') + + title = chapter_soup.select_one('h1.entry-title').get_text() + text = chapter_soup.select_one('div.entry-content') + + for pagination in text.find_all('a'): + pagination.decompose() + + print(title) + + chapter = create_chapter_from_string(str(text), title) + volumes[volume].add_chapter(chapter) + +for ebook in volumes: + if ebook is None: + continue + + ebook.create_epub('output') diff --git a/livres_fr.py b/livres_fr.py new file mode 100644 index 0000000..9a58e99 --- /dev/null +++ b/livres_fr.py @@ -0,0 +1,51 @@ +import os + +import requests +from bs4 import BeautifulSoup +from pypub import Epub, create_chapter_from_string + +if not os.path.exists('output'): + os.makedirs('output') + +post = 0 +volumes = [ + None, + Epub("L'auberge Vagabonde - Volume 1", cover='cover.png'), + Epub("L'auberge Vagabonde - Volume 2", cover='cover.png') +] + +for page in range(12): + html = requests.get( + 'https://www.jeunesecrivains.com/t53075p%s-the-wandering-inn-fan-traduction-fantastique-aventure' % (page * 15)) + soup = BeautifulSoup(html.text, 'html.parser') + tags = soup.select('div.postbody') + + for tag in tags: + post = post + 1 + volume = 1 if post <= 69 else 2 + + if post == 1: + continue + + title_test = tag.div.select_one('div[align=center]') + + if not title_test: + continue + + title = title_test.contents[0] + title_test.decompose() + + text = tag.div.div + + if text.get_text() == '': + text = tag.div + + del text['style'] + + print(title) + + chapter = create_chapter_from_string(str(text), title) + volumes[volume].add_chapter(chapter) + +volumes[1].create_epub('output') +volumes[2].create_epub('output') diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..400facf --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +requests==2.25.1 +beautifulsoup4==4.9.3 +git+git://github.com/Xefir/pypub@fix/py3#egg=pypub