Use regex to replace long links with shorter ones
This commit is contained in:
parent
7f27fab5fb
commit
8f5e839ae9
1 changed files with 3 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""JARVIS Reddit sync."""
|
"""JARVIS Reddit sync."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ config = TaskConfig.from_yaml()
|
||||||
config.reddit["user_agent"] = config.reddit.get("user_agent", DEFAULT_USER_AGENT)
|
config.reddit["user_agent"] = config.reddit.get("user_agent", DEFAULT_USER_AGENT)
|
||||||
running = []
|
running = []
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
image_link = re.compile(r"(.*preview\.redd\.it\/)(.*\..*)\?")
|
||||||
|
|
||||||
|
|
||||||
async def post_embeds(sub: Sub, post: Submission, reddit: Reddit) -> Optional[List[Embed]]:
|
async def post_embeds(sub: Sub, post: Submission, reddit: Reddit) -> Optional[List[Embed]]:
|
||||||
|
@ -74,6 +76,7 @@ async def post_embeds(sub: Sub, post: Submission, reddit: Reddit) -> Optional[Li
|
||||||
if post.spoiler:
|
if post.spoiler:
|
||||||
content += "||"
|
content += "||"
|
||||||
content += f"\n\n[View this post]({url})"
|
content += f"\n\n[View this post]({url})"
|
||||||
|
content = image_link.sub(content, "https://i.redd.it/\2")
|
||||||
|
|
||||||
if not images and not content:
|
if not images and not content:
|
||||||
logger.debug(f"Post {post.id} had neither content nor images?")
|
logger.debug(f"Post {post.id} had neither content nor images?")
|
||||||
|
|
Loading…
Add table
Reference in a new issue