Giter Site home page Giter Site logo

tg2md's Introduction

Python script to convert Telegram chat export to Obsidian vault

This script parses output from Telegram channel or group and converts each post to a Markdown file.

Telegram Desktop creates JSON file, as well as different directories containing multimedia, photos, etc. This script creates new directory and populates it with formatted posts. As a result, the folder containing original media subfolders and this newly created formatted posts folder could be opened in Obsidian as a vault.

In Obsidian, all links between the channel/group posts are converted to wiki links, all photos and other media display embedded in pages like in Telegram.

Easy usage on Windows

For chat with alias

I.e. for chats where links to messages look like https://t.me/samuprav/342

  1. Put tg2md.py and tg2md-link_alias.bat to the same folder where result.json and other exported stuff resides.
  2. Edit tg2md-link_alias.bat and replace <chat_alias> with actual chat alias (like samuprav in the example above).
  3. Run tg2md-link_alias.bat. posts subfolder containing posts will be created by the script.
  4. Check the result by opening the folder as vault in Obsidian.
  5. If the result is OK for you and links inside the vault work fine, delete tg2md-link_alias.bat, tg2md.py, and result.json.

For private chat or chat without alias

I.e. for chats where links to messages look like https://t.me/c/5345344532/342

  1. Put tg2md.py and tg2md.bat to the same folder where result.json and other exported stuff resides.
  2. Run tg2md.py. posts subfolder containing posts will be created by the script.
  3. Check the result by opening the folder as vault in Obsidian.
  4. If the result is OK for you and links inside the vault work fine, delete tg2md-link_alias.bat, tg2md.py, and result.json.

Basic usage

Firstly you need to export your channel history from Telegram Desktop app. This could be done from three dots menu. Then popup menu appears, where you can choose what data you want to export. The script currently supports only photos, voice messages and audio files.

tg-export

In format menu you should specify 'Machine-readable JSON' file and then locate to directory of your desire.

To convert your posts to markdown files you need to run tg2md.py program which takes path to your result.json file as first argument.

$ python tg2md.py path/to/result.json

By default it will create posts directory in your current directory and populate it with markdown files. If you want to specify other location, use --out-dir flag

$ python tg2md.py result.json --out-dir path/to/post/output

For correct linking of posts, please specify channel alias ('@name' without @) using the --alias parameter. I.e. for https://t.me/samuprav:

$ python tg2md.py result.json --alias samuprav

You can also customize names of directories for storing media files instead of default photos and files by specifying them with --photo-dir and --media-dir parameters respectively. Note that they only change links in the markdown files. This actually does not make sense for Obsidian and will be removed.

Todo

  • replies (prev post transcluded)
  • wiki-links and external links
  • links to original Telegram posts
  • post author tag for groups
  • yyyy-mm subfolders to output posts folder
  • forwarded posts
  • single/muliple tags
  • custom post header

tg2md's People

Contributors

la-ninpre avatar dimonier avatar progxaker avatar

Stargazers

 avatar ACTPO HOMOC avatar  avatar Mikhail Lashkin avatar Sergei Korolev avatar ninedraft avatar Niyaz avatar Karel Wintersky avatar Eoin Gairleog avatar Ilya Isaev avatar a13ph avatar demn avatar

Watchers

Eoin Gairleog avatar

Forkers

pabraksas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.