auto-archiver/utils/misc.py

21 wiersze
443 B
Python
Czysty Zwykły widok Historia

2022-05-09 16:19:38 +00:00
import os, requests
from loguru import logger
2022-02-23 15:32:38 +00:00
def mkdir_if_not_exists(folder):
if not os.path.exists(folder):
2022-05-09 16:19:38 +00:00
os.mkdir(folder)
def expand_url(url):
# expand short URL links
if 'https://t.co/' in url:
try:
r = requests.get(url)
2022-06-03 16:03:49 +00:00
logger.debug(f'Expanded url {url} to {r.url}')
return r.url
2022-05-09 16:19:38 +00:00
except:
logger.error(f'Failed to expand url {url}')
return url