Last active
October 2, 2021 14:21
-
-
Save anandtrex/98caedce1756d973f87a9fdd5ec0c287 to your computer and use it in GitHub Desktop.
Script to convert Telegram json to a html file in the Netscape Bookmarks format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import json | |
import dateutil.parser as parser | |
with open('links.html', 'wt') as fw: | |
fw.write("""<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Telegram Export</title> | |
</head> | |
<body> | |
<h1>Unread</h1> | |
<ul> | |
""") | |
with open('links.out.json', 'rt') as f: | |
ss = f.readlines() | |
js = json.loads(ss[0]) | |
for j in js: | |
link = j.get('text') | |
title = j.get('media', {}).get('title', 'No Title') | |
if link: | |
m = re.search('http[s]://.*', link) | |
if m: | |
actual_link = m[0] | |
dt = j.get('to', {}).get('when', '') | |
dtime = parser.parse(dt) | |
fw.write(f'<li><a href="{actual_link}" time_added="{int(dtime.timestamp())}">{title}</a></li>\n') | |
fw.write(""" | |
</ul> | |
</body> | |
</html>""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment