Fix reddit client
This commit is contained in:
parent
a3deafb610
commit
f3b4319c2d
2 changed files with 2 additions and 12 deletions
|
|
@ -4,7 +4,6 @@ from newsreader.news.collection.constants import (
|
||||||
WHITELISTED_ATTRIBUTES,
|
WHITELISTED_ATTRIBUTES,
|
||||||
WHITELISTED_TAGS,
|
WHITELISTED_TAGS,
|
||||||
)
|
)
|
||||||
from newsreader.news.collection.models import CollectionRule
|
|
||||||
from newsreader.news.core.models import Post
|
from newsreader.news.core.models import Post
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -33,7 +32,7 @@ class Client:
|
||||||
stream = Stream
|
stream = Stream
|
||||||
|
|
||||||
def __init__(self, rules=[]):
|
def __init__(self, rules=[]):
|
||||||
self.rules = rules if rules else CollectionRule.objects.enabled()
|
self.rules = rules
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
for rule in self.rules:
|
for rule in self.rules:
|
||||||
|
|
@ -130,14 +129,6 @@ class PostStream(Stream):
|
||||||
class PostClient(Client):
|
class PostClient(Client):
|
||||||
stream = PostStream
|
stream = PostStream
|
||||||
|
|
||||||
def __init__(self, rules=[]):
|
|
||||||
if rules:
|
|
||||||
self.rules = rules
|
|
||||||
else:
|
|
||||||
self.rules = CollectionRule.objects.enabled().filter(
|
|
||||||
type=self.stream.rule_type
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_rule_error(self, rule, exception):
|
def set_rule_error(self, rule, exception):
|
||||||
length = rule._meta.get_field("error").max_length
|
length = rule._meta.get_field("error").max_length
|
||||||
|
|
||||||
|
|
@ -146,7 +137,7 @@ class PostClient(Client):
|
||||||
|
|
||||||
|
|
||||||
class PostCollector(Collector):
|
class PostCollector(Collector):
|
||||||
def collect(self, rules=None):
|
def collect(self, rules=[]):
|
||||||
with self.client(rules=rules) as client:
|
with self.client(rules=rules) as client:
|
||||||
for payload, stream in client:
|
for payload, stream in client:
|
||||||
with self.builder(payload, stream) as builder:
|
with self.builder(payload, stream) as builder:
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,6 @@ class RedditStream(PostStream):
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
|
|
||||||
# TODO fix client
|
|
||||||
class RedditClient(PostClient):
|
class RedditClient(PostClient):
|
||||||
stream = RedditStream
|
stream = RedditStream
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue