aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorla-ninpre <leobrekalini@gmail.com>2020-11-26 23:56:43 +0300
committerla-ninpre <leobrekalini@gmail.com>2020-11-26 23:58:27 +0300
commit48d5e233fda099780ab6705505f4154b0cefa11b (patch)
treee0475e16416e54f12564e230a16de08ac2506553
parente4f357e68c6e2a40ecdd914d84e66dceb0e86cfd (diff)
downloadtg2md-48d5e233fda099780ab6705505f4154b0cefa11b.tar.gz
tg2md-48d5e233fda099780ab6705505f4154b0cefa11b.zip
make a rename
notice repo name also changed
-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':