aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--tg2md.py (renamed from parse.py)9
2 files changed, 10 insertions, 2 deletions
diff --git a/README.md b/README.md
index 2eb604e..959d9b3 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# telegram2md
+# tg2md
This script parses output from Telegram channel and converts each post to
jekyll-applicable post in markdown.
@@ -37,6 +37,7 @@ and `files`, you should change `photo_dir` and `media_dir` variables.
## todo's
+- use argparse module instead of crap
- replies
- single/muliple tags
- forwarded posts
diff --git a/parse.py b/tg2md.py
index a19cf0b..ca4ef35 100644
--- a/parse.py
+++ b/tg2md.py
@@ -54,6 +54,10 @@ def text_format(string, fmt):
return output
def text_link_format(text, link):
+ # convert telegram links to anchors
+ # this implies that telegram links are pointing to the same channel
+ if link.startswith('https://t.me/c/'):
+ link = '#' + link.split('/')[-1]
link_fmt = '[{text}]({href})'
link_fmt = link_fmt.format(text=text.strip(), href=link)
link_fmt += '\n' * text.count('\n') * text.endswith('\n')
@@ -73,7 +77,10 @@ def parse_text_object(obj):
return text_link_format(obj_text, obj['href'])
elif obj_type == 'link' or obj_type == 'email':
- post_link = '<{href}>'.format(href=obj_text.strip())
+ link = obj_text.strip()
+ link = 'https://' * (obj_type == 'link') * \
+ (1 - link.startswith('https://')) + link
+ post_link = '<{href}>'.format(href=link)
return post_link
elif obj_type == 'phone':