all repos — tg2md @ 48d5e233fda099780ab6705505f4154b0cefa11b

converter from telegram json to jekyll md

make a rename

notice repo name also changed
la-ninpre leobrekalini@gmail.com
Thu, 26 Nov 2020 23:56:43 +0300
commit

48d5e233fda099780ab6705505f4154b0cefa11b

parent

e4f357e68c6e2a40ecdd914d84e66dceb0e86cfd

2 files changed, 10 insertions(+), 2 deletions(-)

jump to
M README.mdREADME.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
M parse.pytg2md.py

@@ -54,6 +54,10 @@ output += '\n' * string.split('\n').count('') * string.endswith('\n')

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 @@ elif obj_type == 'text_link':

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':