Initial tests & video/image mockup
This commit is contained in:
parent
6b7ac32dfa
commit
e0744d3a68
3 changed files with 37 additions and 10 deletions
|
|
@ -42,6 +42,8 @@ REDDIT_API_URL = "https://oauth.reddit.com"
|
|||
RATE_LIMIT = 60
|
||||
RATE_LIMIT_DURATION = timedelta(seconds=60)
|
||||
|
||||
REDDIT_IMAGE_EXTENSIONS = (".jpg", ".png", ".gif")
|
||||
|
||||
|
||||
def get_reddit_authorization_url(user):
|
||||
state = str(uuid4())
|
||||
|
|
@ -120,7 +122,9 @@ class RedditBuilder(Builder):
|
|||
remote_identifier = post["data"]["id"]
|
||||
title = truncate_text(Post, "title", post["data"]["title"])
|
||||
author = truncate_text(Post, "author", post["data"]["author"])
|
||||
url_fragment = f"{post['data']['permalink']}"
|
||||
post_url_fragment = post["data"]["permalink"]
|
||||
direct_url = post["data"]["url"]
|
||||
is_text_post = post["data"]["is_self"]
|
||||
|
||||
if remote_identifier in results:
|
||||
continue
|
||||
|
|
@ -139,6 +143,13 @@ class RedditBuilder(Builder):
|
|||
else ""
|
||||
)
|
||||
|
||||
if not is_text_post and direct_url.endswith(REDDIT_IMAGE_EXTENSIONS):
|
||||
body = f"<div><img alt='{title}' src='{direct_url}' loading='lazy' /></div>"
|
||||
elif not is_text_post and post["data"]["is_video"]:
|
||||
video_info = post["data"]["secure_media"]["reddit_video"]
|
||||
|
||||
body = f"<div><video controls muted><source src='{video_info['fallback_url']}' type='video/mp4' /></video></div>"
|
||||
|
||||
try:
|
||||
parsed_date = datetime.fromtimestamp(post["data"]["created_utc"])
|
||||
created_date = pytz.utc.localize(parsed_date)
|
||||
|
|
@ -151,7 +162,7 @@ class RedditBuilder(Builder):
|
|||
"title": title,
|
||||
"body": body,
|
||||
"author": author,
|
||||
"url": f"{REDDIT_URL}{url_fragment}",
|
||||
"url": f"{REDDIT_URL}{post_url_fragment}",
|
||||
"publication_date": created_date,
|
||||
"rule": rule,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from datetime import datetime
|
||||
from unittest import skip
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from django.test import TestCase
|
||||
|
|
@ -219,3 +220,23 @@ class RedditBuilderTestCase(TestCase):
|
|||
duplicate_post.title,
|
||||
"Linux Experiences/Rants or Education/Certifications thread - July 06, 2020",
|
||||
)
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_image_post(self):
|
||||
pass
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_external_image_post(self):
|
||||
pass
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_video_post(self):
|
||||
pass
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_external_video_post(self):
|
||||
pass
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_link_only_post(self):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -68,14 +68,9 @@
|
|||
margin: 20px 0 5px 0;
|
||||
}
|
||||
|
||||
& img {
|
||||
padding: 10px 10px 30px 10px;
|
||||
|
||||
max-width: 70%;
|
||||
width: inherit;
|
||||
height: 100%;
|
||||
|
||||
align-self: center;
|
||||
& img, video {
|
||||
padding: 10px 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue