It connects to Telegram's API. It generates JSON files containing channel's data, including channel's information and posts.

Overview

Telegram API


GitHub stars GitHub watchers Twitter estebanpdl License Open Source Made-with-python


Overview

It connects to Telegram's API. It generates JSON files containing channel's data, including channel's information and posts. You can search for a specific channel, or a set of channels provided in a text file (one channel per line.)

Files are saved by default in a folder called output/data. These folders are created by the script.

โ”œโ”€โ”€๐Ÿ—‚ Telegram-api
|   โ””โ”€โ”€main.py
|   โ””โ”€โ”€๐Ÿ—‚ config
|   	โ””โ”€โ”€config.ini
|   โ””โ”€โ”€๐Ÿ—‚ output
|   	โ””โ”€โ”€collected_chats.csv
|   	โ””โ”€โ”€๐Ÿ—‚ data
|   		โ””โ”€โ”€file_messages.json
|   		โ””โ”€โ”€channel.json
|   		โ””โ”€โ”€etc.

Software required

Python required libraries

Installing

  • Via git clone
git clone https://github.com/estebanpdl/telegram-api.git

This will create a directory called tg-api which contains the Python scripts. Cloning allows you to easily upgrade and switch between available releases.

  • From the github download button

Download the ZIP file from github and use your favorite zip utility to unpack the file tg-api.zip on your preferred location.

After cloning or downloding the repository, install the libraries from requirements.txt.

pip install -r requirements.txt

or

pip3 install -r requirements.txt

Once you obtain an API ID and API hash on my.telegram.org, populate the config/config.ini file with the described values.

[Telegram API credentials]
api_id = api_id
api_hash = api_hash
phone = phone

Example usage

main.py

This Python script will connect to Telegram's API and handle your API request.

Options

  • --telegram-channel Specifies Telegram Channel to download data from.
  • --batch-file File containing Telegram Channels to download data from, one channel per line.
  • --limit-download-to-channel-metadata Will collect channels metadata only, not channel's messages. (default = False)
  • --min-id Specifies the offset id. This will update Telegram data with new posts.

Examples

Basic request

python main.py --telegram-channel channelname`

Expected output

  • Excel file of collected channels
  • JSON file containing channel's profile metadata
  • JSON file containing posts from the requested channel

Request using a text file containing a set of channels

python main.py --batch-file './path/to/channels_text_file.txt'

Expected output

  • Excel file of collected channels
  • JSON files containing channels' profile metadata
  • JSON files containing posts from each requested channel

These examples will retrieve all posts available through the API from the requested channel. If you want to collect channel's information only, without posts, you can run:

Limit download to channel's metadata only

python main.py --telegram-channel channelname --limit-download-to-channel-metadata

or, using a set of telegram channels via a text file:

python main.py --batch-file './path/to/channels_text_file.txt' --limit-download-to-channel-metadata

Updating channel's data

If you want to collect new messages from one channel, you need to identify the message ID from the last post. Once you identify the id, run:

python main.py --telegram-channel channelname --min-id 12345

Expected output

  • Excel file of collected channels - based on new messages
  • JSON file containing channel's profile metadata
  • JSON file containing new messages posted after the requested ID (min ID)

build-datasets.py

python build-datasets.py

This Python script reads the collected files and creates a new dataset containing messages from the requested channels. By default, the created dataset in CSV format will be located in the output folder.

โ”œโ”€โ”€๐Ÿ—‚ Telegram-api
|   โ””โ”€โ”€main.py
|   โ””โ”€โ”€๐Ÿ—‚ output
|   	โ””โ”€โ”€msgs_dataset.csv

channels-to-network.py

python channels-to-network.py

This Python script builds a network graph. By default, the file will be located in the output folder. The script also shows a preliminary graph using the modules matplotlib, networkx, and python-louvain, which implements community detection. You can use import the graph file in different softwares, including Gephi.

โ”œโ”€โ”€๐Ÿ—‚ Telegram-api
|   โ””โ”€โ”€main.py
|   โ””โ”€โ”€๐Ÿ—‚ output
|   	โ””โ”€โ”€Graph.gexf

Owner
Esteban Ponce de Leon
Esteban Ponce de Leon
A Discord bot to scrape textfiles from messages and put them to Hastebin

A Discord bot to scrape textfiles from messages and put them to Hastebin. Intended to use on support servers to help users read textfiles on mobile.

1 Jan 23, 2022
A bot for the [email protected] Discord server.

KittyBot - a sentient Discord bot! Key Notes An open-source, community-powered bot for the [email 

Ollie 11 Dec 06, 2022
LEC_Ditto is a bot that tracks the follows and unfollows of Twitter accounts

โœจ LEC_Ditto โœจ I'm Ditto, and I'm a bot ๐Ÿค– . Getting Started | Installation | Usage Getting Started LEC_Ditto is a bot that tracks the follows and unfo

2 Mar 30, 2022
This repo contains a small project i've done using PILLOW module in python

This repo contains a small project i've done using PILLOW module in python. I wrote an automated script which generates more than 5k+ unique nfts with 0 hassle in less time.

SasiVatsal 11 Nov 05, 2022
Discord Online Account Forever

๐Ÿ’  Discord-Online-Account-Forever Discord Online Account Forever ๐Ÿ“ธ Tutorial Token Discord NEVER SHARE YOUR TOKEN Installation Replit ๐Ÿงฟ Replit : Here

nimaisox 2 Nov 28, 2021
Send pm to Admin - Telegram

Send pm to Admin - Telegram

Ahoora 3 Nov 17, 2022
Mazda Connected Service API wrapper based on pymazda and Flask.

Mazda Connected Service Relay Mazda Connected Service API wrapper based on pymazda and Flask. Usage Make POST calls to https://mymazda.herokuapp.com/{

Alan Chen 10 Jan 05, 2023
A Python wrapper around the OpenWeatherMap web API

PyOWM A Python wrapper around OpenWeatherMap web APIs What is it? PyOWM is a client Python wrapper library for OpenWeatherMap (OWM) web APIs. It allow

Claudio Sparpaglione 740 Dec 18, 2022
Discord bot for playing Werewolf game on League of Legends.

LoLWolf LoLไบบ็‹ผใ‚’ใƒ—ใƒฌใ‚คใ™ใ‚‹ใจใใฎDiscord็”จbotใงใ™ใ€‚ (Discord bot for playing Werewolf game on League of Legends.) ไปฅไธ‹ใฎใƒœใ‚ฟใƒณใ‚’ๆŠผใ—ใฆbotใ‚’ใ‚ใชใŸใฎDiscordใซๆ‹›ๅพ…ใ™ใ‚‹ใ“ใจใง่ชฐใงใ‚‚็ฐกๅ˜ใซไฝฟ็”จใ™ใ‚‹ใ“ใจใŒใงใใพใ™ใ€‚

Hatsuka 4 Oct 18, 2021
A modular bot running on python3 with anime theme and have a lot features

STINKY ROBOT Emiko Robot is a modular bot running on python3 with anime theme and have a lot features. Easiest Way To Deploy On Heroku This Bot is Cre

Riyan.rz 3 Jan 21, 2022
Search twitter by address.

Twitter Geolocate Twitter Geolocation is a console app that generates twitter search querries for a certain geolocation and opens them in your standar

David J. Kowalk 28 Dec 06, 2022
Command-line program to download videos from YouTube.com and other video sites

youtube-dl - download videos from youtube.com or other video platforms INSTALLATION DESCRIPTION OPTIONS CONFIGURATION OUTPUT TEMPLATE FORMAT SELECTION

youtube-dl 116.4k Jan 07, 2023
Create CDK projects with projen

The Projenator: I'll be back! Description This is a CDKv2 project that takes the grind out of setting up new cdk projects/implementations by using aut

Andrew 2 Dec 11, 2021
Azure Neural Speech Service TTS

Written in Python using the Azure Speech SDK. App.py provides an easy way to create an Text-To-Speech request to Azure Speech and download the wav file.

Rodney 1 Oct 11, 2021
A Really Simple and Advanced Google Colab NoteBook to Setup and start using Rclone on Google Colab easily.

Rclone on Google Colab (Advanced!) ๐Ÿ”ฅ 1.Setup and Start using Rclone on Google Colab and Create/Edit/View and delete your Rclone config file and keep

Dr.Caduceus 14 May 24, 2022
Basic-Discord-Response-Bot, in Python

Response bot for Discord. EG: User: Hello! Bot: Hello there! About Very customizable, no credits needed. Edit the bot.py to what you want, basic Pytho

rhys 1 Nov 20, 2021
Simple spam bot made in python

Simple Spam Bot A Simple and easy way to be the most hated person between your friends, All you have to do is spam the group chat using this bot until

Kareem Osama 6 Sep 05, 2022
Authenticate your League of legends account on riot client in a few lines of code.

lol-authenticator v1.0.0 Content index Project Setup Dependencies Project Setup Dependencies Python v3.9.6 If you don't have Python installed on your

Cรกssio Fontoura 5 Aug 28, 2022
A really easy way to display your spotify listening status on spotify.

Spotify playing README A really easy way to display your spotify listening status on READMEs and Websites too! Demo Here's the embed from the site. Cu

Sunrit Jana 21 Nov 06, 2022
A basic Ubisoft API wrapper created in python.

UbisoftAPI A basic Ubisoft API wrapper created in python. I will be updating this with more endpoints as time goes on. Please note that this is my fir

Ethan 2 Oct 31, 2021