mirror of
https://github.com/gryf/slack-backup.git
synced 2025-12-17 11:30:25 +01:00
Fixes for links handling
This commit is contained in:
@@ -30,9 +30,11 @@ class Reporter(object):
|
|||||||
'file': '📂',
|
'file': '📂',
|
||||||
'topic': '🟅',
|
'topic': '🟅',
|
||||||
'separator': '│'}}
|
'separator': '│'}}
|
||||||
url_pat = re.compile(r'(?P<replace><http[^>]+>)')
|
literal_url_pat = re.compile(r'(?P<replace>(?P<url>https?[^\s\|]+))')
|
||||||
|
url_pat = re.compile(r'(?P<replace><(?P<url>http[^\|>]+)'
|
||||||
|
r'(\|(?P<title>[^>]+))?>)')
|
||||||
slackid_pat = re.compile(r'(?P<replace><@'
|
slackid_pat = re.compile(r'(?P<replace><@'
|
||||||
'(?P<slackid>U[A-Z,0-9]+)(\|[^>]+)?[^>]*>)')
|
r'(?P<slackid>U[A-Z,0-9]+)(\|[^>]+)?[^>]*>)')
|
||||||
|
|
||||||
def __init__(self, args, query):
|
def __init__(self, args, query):
|
||||||
self.out = args.output
|
self.out = args.output
|
||||||
@@ -220,7 +222,11 @@ class TextReporter(Reporter):
|
|||||||
|
|
||||||
def _msg_file(self, msg):
|
def _msg_file(self, msg):
|
||||||
"""return data for file"""
|
"""return data for file"""
|
||||||
|
if msg.file.filepath:
|
||||||
fpath = os.path.abspath(msg.file.filepath)
|
fpath = os.path.abspath(msg.file.filepath)
|
||||||
|
else:
|
||||||
|
fpath = 'does_not_exists'
|
||||||
|
|
||||||
return {'msg': self.url_pat.sub('(file://' + fpath + ') ' +
|
return {'msg': self.url_pat.sub('(file://' + fpath + ') ' +
|
||||||
msg.file.title, msg.text),
|
msg.file.title, msg.text),
|
||||||
'nick': self._get_symbol('file')}
|
'nick': self._get_symbol('file')}
|
||||||
@@ -370,7 +376,11 @@ class StaticHtmlReporter(Reporter):
|
|||||||
|
|
||||||
def _msg_file(self, msg):
|
def _msg_file(self, msg):
|
||||||
"""return data for file"""
|
"""return data for file"""
|
||||||
|
if msg.file.filepath:
|
||||||
fpath = os.path.abspath(msg.file.filepath)
|
fpath = os.path.abspath(msg.file.filepath)
|
||||||
|
else:
|
||||||
|
fpath = 'does_not_exists'
|
||||||
|
|
||||||
_, ext = os.path.splitext(fpath)
|
_, ext = os.path.splitext(fpath)
|
||||||
if ext.lower() in ('.png', '.jpg', '.jpeg', '.gif'):
|
if ext.lower() in ('.png', '.jpg', '.jpeg', '.gif'):
|
||||||
url = ('<img src="file://' + fpath +
|
url = ('<img src="file://' + fpath +
|
||||||
@@ -389,31 +399,33 @@ class StaticHtmlReporter(Reporter):
|
|||||||
'msg': msg.text,
|
'msg': msg.text,
|
||||||
'nick': msg.user.name}
|
'nick': msg.user.name}
|
||||||
|
|
||||||
|
link = '<a href="{url}">{title}</a>'
|
||||||
attachement_msg = []
|
attachement_msg = []
|
||||||
|
|
||||||
if msg.attachments:
|
if msg.attachments:
|
||||||
for att in msg.attachments:
|
for att in msg.attachments:
|
||||||
|
if 'http' in att.fallback:
|
||||||
|
match = self.url_pat.search(att.fallback)
|
||||||
|
if not match:
|
||||||
|
match = self.literal_url_pat.search(att.fallback)
|
||||||
|
match = match.groupdict()
|
||||||
|
|
||||||
|
if 'title' not in match:
|
||||||
|
match['title'] = match['url']
|
||||||
if att.title:
|
if att.title:
|
||||||
att_text = att.title
|
match['title'] = att.title
|
||||||
|
|
||||||
|
att_text = att.fallback.replace(match['replace'],
|
||||||
|
link.format(**match))
|
||||||
|
else:
|
||||||
|
match = self.url_pat.search(msg.text)
|
||||||
|
if match:
|
||||||
|
match = match.groupdict()
|
||||||
|
match['title'] = att.fallback
|
||||||
|
att_text = msg.text.replace(match['replace'],
|
||||||
|
link.format(**match))
|
||||||
else:
|
else:
|
||||||
att_text = att.fallback
|
att_text = att.fallback
|
||||||
|
|
||||||
if att.text:
|
|
||||||
att_text += '<br>' + att.text
|
|
||||||
|
|
||||||
if 'http' in att.fallback:
|
|
||||||
if not att.fallback.startswith('http'):
|
|
||||||
link = ('<a href="' + att.fallback.split(': ')[1] +
|
|
||||||
'">' + att_text + '</a>')
|
|
||||||
else:
|
|
||||||
link = ('<a href="' + att.fallback + '">' +
|
|
||||||
att_text + '</a>')
|
|
||||||
|
|
||||||
if att_text == att.title:
|
|
||||||
att_text = link
|
|
||||||
else:
|
|
||||||
att_text += '<br>' + link
|
|
||||||
|
|
||||||
attachement_msg.append(att_text)
|
attachement_msg.append(att_text)
|
||||||
|
|
||||||
data['msg'] += '<br>'.join(attachement_msg)
|
data['msg'] += '<br>'.join(attachement_msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user