Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask web server #1411

Open
wants to merge 59 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fe014d8
Website initial release
jere344 Jun 18, 2022
3739133
Merge branch 'flask' of https://github.com/jere344/lightnovel-crawler…
jere344 Jun 18, 2022
f398397
Removed test + useless import
jere344 Jun 18, 2022
5009c7b
removed test
jere344 Jun 18, 2022
7c28fad
Fixed wrong link for latest
jere344 Jun 18, 2022
137374b
Fixed source selection
jere344 Jun 18, 2022
7111759
Fixed url to novel_info
jere344 Jun 18, 2022
b21c12d
Format + removed ads and notification css/js
jere344 Jun 18, 2022
0c01a4f
Fix regex broken by formatter
jere344 Jun 18, 2022
f87ac0a
Allow displaying the whole title (was limited to ~40 before)
jere344 Jun 18, 2022
d7e8376
Integrated downloader inside reader and various downloader bugfixes
jere344 Jun 19, 2022
5124d75
Added support for images in chapters
jere344 Jun 19, 2022
94045d0
Removed test
jere344 Jun 19, 2022
90dd2f1
Added 'add novel' navigation item to header
jere344 Jun 19, 2022
fce1b0b
Improved search algorithm, added docstrings
jere344 Jun 19, 2022
eebf1c8
Flask requierement for web bot
jere344 Jun 21, 2022
eeab0a8
Added waitress to serve app instead of flask
jere344 Jun 21, 2022
1a94832
Fixed wrong url
jere344 Jun 21, 2022
1c46376
Create lightnovel dir if don't exist
jere344 Jun 21, 2022
b49ff95
Added mobile support + changed font
jere344 Jun 21, 2022
747d909
Headers and footers href now point toward lightnovel-crawler github
jere344 Jun 24, 2022
7b223bb
Save dark/light theme
jere344 Jun 25, 2022
1a31cff
fix icon switch on theme change
jere344 Jun 25, 2022
f3ea1e1
Save font and fontsize + added opendyslexic font
jere344 Jun 25, 2022
c0a7fd1
doctype html
jere344 Jun 25, 2022
34a35a7
Merge branch 'dipu-bd:master' into flask
jere344 Jun 25, 2022
251e177
Added Flask-Minify dependency
jere344 Jun 25, 2022
b19a9c6
Added support for summary and language optionnal metadata
jere344 Jun 26, 2022
355e6fb
Update _template.py
jere344 Jun 26, 2022
4172971
Quick refactor
jere344 Jun 27, 2022
7dd365e
Merge branch 'flask' of https://github.com/jere344/lightnovel-crawler…
jere344 Jun 27, 2022
2d88f75
Quick refactor
jere344 Jun 27, 2022
aaf2c77
type hint
jere344 Jun 27, 2022
908677a
Minor fixes
jere344 Jun 27, 2022
98dc9ee
CSS for the add novel icon
jere344 Jun 27, 2022
f185393
Separated header and footer
jere344 Jun 28, 2022
009089a
Downloader v2 + merged downloader with website
jere344 Jun 30, 2022
fa1b2a7
Added direct download with url
jere344 Jun 30, 2022
08a1d17
Clarity
jere344 Jun 30, 2022
c0b2174
Language and summary support
jere344 Jun 30, 2022
235a1db
job_id are now random
jere344 Jun 30, 2022
c079550
Moved novels class in their own files
jere344 Jun 30, 2022
d525645
strong typing
jere344 Jul 1, 2022
23c6931
Moved Job classes and novel metadata reader in their own files
jere344 Jul 1, 2022
e582224
Added support for novel stats : clicks/favorites/rating
jere344 Jul 1, 2022
0bbca8a
Removed favorites (it was a mistake)
jere344 Jul 1, 2022
6a2d56d
Now show rank based on number of clicks and rating
jere344 Jul 2, 2022
5c9a7bf
Default language for novels are set using the crawler folder name
jere344 Jul 2, 2022
e99b541
Now display flags for languages in main page above the covers
jere344 Jul 2, 2022
2149de6
Fixed default language for english sources
jere344 Jul 2, 2022
292217c
Security fix
jere344 Jul 2, 2022
39738e1
Meta tags
jere344 Jul 3, 2022
ef6daf1
Meta tags
jere344 Jul 3, 2022
890ba91
config file
jere344 Jul 4, 2022
ad91155
fixed summary display
jere344 Jul 4, 2022
fa523dd
Novel info now show rank, language, rating ...
jere344 Jul 4, 2022
8d06da4
Merge branch 'dipu-bd:master' into flask
jere344 Jul 6, 2022
abdee3c
Replaced pipes to support older versions of python
jere344 Jul 6, 2022
351b828
Merge branch 'flask' of https://github.com/jere344/lightnovel-crawler…
jere344 Jul 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ client_secrets.json
/lightnovel-crawler-*
__pycache__/
.idea/
lncrawl/bots/web/config.json
2 changes: 2 additions & 0 deletions lncrawl/binders/calibre.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def epub_to_calibre(app, epub_file, out_fmt):
'--no-chapters-in-toc',
'--title', file_name_without_ext,
'--authors', app.crawler.novel_author,
'--summary', app.crawler.summary,
'--language', app.crawler.language,
'--series', app.crawler.novel_title,
'--publisher', app.crawler.home_url,
'--book-producer', 'Lightnovel Crawler',
Expand Down
10 changes: 9 additions & 1 deletion lncrawl/binders/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def make_intro_page(app, cover_image):
]))
# end if

if app.crawler.summary :
intro_html += f'''
<div>
<p>{app.crawler.summary}</p>
</div>
'''
# end if

intro_html += '''
<div>
<b>Source:</b> <a href="%s">%s</a><br>
Expand Down Expand Up @@ -138,7 +146,7 @@ def bind_epub_book(app, chapters, volume=''):

# Create book
book = epub.EpubBook()
book.set_language('en')
book.set_language(app.crawler.language)
book.set_title(book_title)
book.add_author(app.crawler.novel_author)
book.set_identifier(app.output_path + volume)
Expand Down
32 changes: 21 additions & 11 deletions lncrawl/bots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
# -*- coding: utf-8 -*-

supported_bots = [
'console',
'telegram',
'discord',
'test',
"console",
"telegram",
"discord",
"web",
"test",
]


def run_bot(bot):
if bot not in supported_bots:
bot = 'console'
bot = "console"
# end if
if bot == 'console':
if bot == "console":
from ..bots.console import ConsoleBot

ConsoleBot().start()
elif bot == 'telegram':
elif bot == "telegram":
from ..bots.telegram import TelegramBot

TelegramBot().start()
elif bot == 'discord':
elif bot == "discord":
from ..bots.discord import DiscordBot

DiscordBot().start_bot()
elif bot == 'test':
from ..bots.test import TestBot
elif bot == "web":
from . import web

elif bot == "test":
from ..bots.test import TestBot # type: ignore

TestBot().start()
else:
print('Unknown bot: %s' % bot)
print("Unknown bot: %s" % bot)
# end def


# end def
3 changes: 3 additions & 0 deletions lncrawl/bots/console/resume_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def load_session_from_metadata(data) -> App:

app.crawler.novel_title = data['title']
app.crawler.novel_author = data['author']
# ternary operator necessary for novels downloaded before language and summary where implemented
app.crawler.language = data['language'] if 'language' in data else 'en'
app.crawler.summary = data['summary'] if 'summary' in data else ''
app.crawler.novel_cover = data['cover']
app.crawler.volumes = data['volumes']
app.crawler.chapters = data['chapters']
Expand Down
70 changes: 70 additions & 0 deletions lncrawl/bots/web/Novel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from urllib.parse import quote_plus
from typing import Any, List, Optional

@dataclass(init=False)
class _Novel:
title: str = ""
path: Optional[Path] = None
cover: Optional[str] = None
author: str = ""
chapter_count: int = 0
volume_count: int = 0
slug: str = ""
first: str = ""
latest: str = ""
summary: str = ""
language: str = "en"

def __init__(self, path: Path):
self.path = path
self.slug = quote_plus(path.name)

def __hash__(self) -> int:
return super().__hash__()


@dataclass(init=False)
class Novel(_Novel):
"""
Holds information about a novel.
"""
prefered_source: Optional[NovelFromSource] = None
source_count: int = 0
clicks : int = 0
overall_rating: float = 0.0
ratings_count = property(lambda self: len(self.ratings))
rank:int

def __init__(self, path: Path):
self.search_words = []
self.sources = []
self.ratings: dict[str, int] = {}
self.search_words: List[str] = []
self.sources: list[NovelFromSource] = []

super().__init__(path)

def __eq__(self, other: Any) -> bool:
"""
Overrides the default implementation
_Novel are equal if they have the same title
"""
if issubclass(type(other), _Novel):
return self.title == other.title
return False

def __hash__(self) -> int:
"""Overrides the default implementation"""
return hash(self.title)


@dataclass(init=False)
class NovelFromSource(_Novel):
"""
Hold information about a novel from a source.
"""

novel: Novel
8 changes: 8 additions & 0 deletions lncrawl/bots/web/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from . import flaskapp
from . import downloader # type: ignore
from . import reader # type: ignore
from .lib import PORT, HOST
from waitress import serve
serve(flaskapp.app, port=PORT, host=HOST)

# flaskapp.app.run()
6 changes: 6 additions & 0 deletions lncrawl/bots/web/_stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"clicks": 0,
"ratings": {
"-6455068401711230225": 5
}
}
13 changes: 13 additions & 0 deletions lncrawl/bots/web/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import List, Union
from .Novel import Novel

all_downloaded_novels: List[Novel] = []

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .downloader.Job import JobHandler, FinishedJob

jobs: dict[str, Union[FinishedJob, JobHandler]]

jobs = {}
Loading