Compare commits
No commits in common. "ad17d5a4a5e6e5d321dd41a3e2964898aa464f06" and "3371eba487fbd6c04404b8110305e413a6ce5c7c" have entirely different histories.
ad17d5a4a5
...
3371eba487
16
redditbot.py
16
redditbot.py
|
@ -365,7 +365,7 @@ async def main():
|
||||||
url = urlunparse(urlparse(url, 'https'))
|
url = urlunparse(urlparse(url, 'https'))
|
||||||
await _download_file(filename, url)
|
await _download_file(filename, url)
|
||||||
ext = await _get_file_ext(filename)
|
ext = await _get_file_ext(filename)
|
||||||
if ext in ('.htm', '.html'):
|
if ext.startswith('.htm'):
|
||||||
with open(filename) as file:
|
with open(filename) as file:
|
||||||
soup = BeautifulSoup(file.read())
|
soup = BeautifulSoup(file.read())
|
||||||
ptitle = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:title' and tag.attrs.get('content')) or soup.find('title')
|
ptitle = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:title' and tag.attrs.get('content')) or soup.find('title')
|
||||||
|
@ -374,21 +374,21 @@ async def main():
|
||||||
pdesc = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:description' and tag.attrs.get('content')) or soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('name') == 'description' and tag.attrs.get('content'))
|
pdesc = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:description' and tag.attrs.get('content')) or soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('name') == 'description' and tag.attrs.get('content'))
|
||||||
if pdesc:
|
if pdesc:
|
||||||
pdesc = pdesc.attrs.get('content', pdesc.text).strip()
|
pdesc = pdesc.attrs.get('content', pdesc.text).strip()
|
||||||
pmedia = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:video' and tag.attrs.get('content')) or soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:image' and tag.attrs.get('content'))
|
pimg = soup.find(lambda tag: tag.name == 'meta' and tag.attrs.get('property') == 'og:image' and tag.attrs.get('content'))
|
||||||
if pmedia:
|
if pimg:
|
||||||
pmedia = pmedia.attrs.get('content', '').strip()
|
pimg = pimg.attrs.get('content', '').strip()
|
||||||
tat = f'{text}\n\nURL: '
|
tat = f'{text}\n\nURL: '
|
||||||
if ptitle:
|
if ptitle:
|
||||||
tat += f'<a href="{url}">{html.escape(ptitle)}</a>'
|
tat += f'<a href="{url}">{html.escape(ptitle)}</a>'
|
||||||
else:
|
else:
|
||||||
tat += url
|
tat += url
|
||||||
files = []
|
files = []
|
||||||
if pmedia:
|
if pimg:
|
||||||
pmedia = urlunparse(urlparse(pmedia, 'https'))
|
pimg = urlunparse(urlparse(pimg, 'https'))
|
||||||
await _download_file(filename, pmedia)
|
await _download_file(filename, pimg)
|
||||||
files.append(filename)
|
files.append(filename)
|
||||||
if pdesc:
|
if pdesc:
|
||||||
caplength = 1023 if pmedia else 4095
|
caplength = 1023 if pimg else 4095
|
||||||
caplength -= len(client.parse_mode.parse(tat)[0])
|
caplength -= len(client.parse_mode.parse(tat)[0])
|
||||||
captext = pdesc[:caplength]
|
captext = pdesc[:caplength]
|
||||||
if len(captext) >= caplength:
|
if len(captext) >= caplength:
|
||||||
|
|
Loading…
Reference in New Issue