mirror of
https://github.com/kemayo/leech
synced 2026-01-18 21:42:39 +01:00
Use attrs
This commit is contained in:
parent
e6343cb1c9
commit
f066fc663d
2 changed files with 24 additions and 21 deletions
|
|
@ -1,3 +1,4 @@
|
|||
attrs==16.3.0
|
||||
beautifulsoup4==4.4.1
|
||||
html5lib==0.999
|
||||
Pillow==3.0.0
|
||||
|
|
|
|||
|
|
@ -3,31 +3,31 @@ import glob
|
|||
import os
|
||||
import argparse
|
||||
import uuid
|
||||
import attr
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
_sites = []
|
||||
|
||||
|
||||
def _default_uuid_string(*args):
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
@attr.s
|
||||
class Chapter:
|
||||
def __init__(self, title, contents, date=False, chapterid=None):
|
||||
if not chapterid:
|
||||
chapterid = str(uuid.uuid4())
|
||||
self.id = chapterid
|
||||
self.title = title
|
||||
self.contents = contents
|
||||
self.date = date
|
||||
title = attr.ib()
|
||||
contents = attr.ib()
|
||||
date = attr.ib(default=False)
|
||||
id = attr.ib(default=attr.Factory(_default_uuid_string), convert=str)
|
||||
|
||||
|
||||
@attr.s
|
||||
class Section:
|
||||
def __init__(self, title, author, sectionid=None):
|
||||
if not sectionid:
|
||||
sectionid = str(uuid.uuid4())
|
||||
self.id = sectionid
|
||||
self.title = title
|
||||
self.author = author
|
||||
# Will contain a mix of Sections and Chapters
|
||||
self.contents = []
|
||||
self.footnotes = []
|
||||
title = attr.ib()
|
||||
author = attr.ib()
|
||||
id = attr.ib(default=attr.Factory(_default_uuid_string), convert=str)
|
||||
contents = attr.ib(default=attr.Factory(list))
|
||||
footnotes = attr.ib(default=attr.Factory(list))
|
||||
|
||||
def __iter__(self):
|
||||
return self.contents.__iter__()
|
||||
|
|
@ -55,15 +55,17 @@ class Section:
|
|||
yield chapter.date
|
||||
|
||||
|
||||
@attr.s
|
||||
class Site:
|
||||
"""A Site handles checking whether a URL might represent a site, and then
|
||||
extracting the content of a story from said site.
|
||||
"""
|
||||
def __init__(self, session, args=None):
|
||||
super().__init__()
|
||||
self.session = session
|
||||
self.footnotes = []
|
||||
self.options = self._parse_args(args)
|
||||
session = attr.ib()
|
||||
args = attr.ib()
|
||||
footnotes = attr.ib(default=attr.Factory(list), init=False)
|
||||
|
||||
def __attrs_post_init__(self):
|
||||
self.options = self._parse_args(self.args)
|
||||
|
||||
@staticmethod
|
||||
def matches(url):
|
||||
|
|
|
|||
Loading…
Reference in a new issue