tegracli
A Telegram/telethon research convenience wrapper for the terminal.
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 2 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.2%) to scientific vocabulary
Keywords
Repository
A Telegram/telethon research convenience wrapper for the terminal.
Basic Info
- Host: GitHub
- Owner: Leibniz-HBI
- License: mit
- Language: Python
- Default Branch: trunk
- Homepage: https://pypi.org/project/tegracli/
- Size: 205 KB
Statistics
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 14
- Releases: 10
Topics
Metadata Files
README.md
tegracli

A convenience wrapper around Telethon and the Telegram Client API for research purposes.
Installation Instructions
tegracli uses Poetry and python >= 3.9 and < 4.0 for building and installing.
To install using pipx, run the following command pipx install tegracli.
How to get API keys
If you don't have API keys for Telegram, head over to my.telegram.org.
Click on API development tools, fill the form to create yourself an app and pluck the keys into tegracli.conf.yml. The session name can be arbitrary.
yaml
api_id: 1234567
api_hash : some12321hashthatmustbehere123
session_name: somesessionyo
This template file is provided with the repository.
Usage
tegracli is a terminal application to access the Telegram API for research purposes.
In order to retrieve messages the configuration-file from the section before must be present in the directory you start tegracli.
```text Usage: tegracli [OPTIONS] COMMAND [ARGS]...
Tegracli!! Retrieve messages from Telegram with a CLI!
Options: -d, --debug Enable legacy debugging, is overwritten by the other options. Defaults to False. -v, --verbose Logging verbosity. -l, --log-file FILENAME File to log to. Defaults to STDOUT. -s, --serialize Serialize output to JSON. --help Show this message and exit.
Commands: configure Configure tegracli. get Get messages for the specified channels by either ID or... group Manage account groups. hydrate Hydrate a file with messages-ids. search Searches Telegram content that is available to your account. ```
Logging
tegracli allows for configuring what and how it is logged. Per default logging is disabled and can be enabled by passing --verbose or -v, logging level can be increased by more -vvvvs. By default logging target is STDOUT but this can be redirected to a file with --log-file yourfile.log. Setting --serialize allows to be to write the entire logging information in JSON-encoded form. --debug is the legacy option used by tegracli <= 0.2.5, this will set serialized logging into tegracli.log.jsonl at the DEBUG level; it is overwritten by setting the --verbose option.
Commands
The following commands are available:
configure
Opens an interactive prompt for configuring API-access. Aks you to input your API id, API hash and session name and requests a 2FA code from Telegram.
```text Usage: tegracli configure [OPTIONS]
Configure tegracli.
Options: --help Show this message and exit. ```
get
To get messages from a number of channels, use this command.
```text Usage: tegracli get [OPTIONS] [CHANNELS]...
Get messages for the specified channels by either ID or username.
Options: -l, --limit INTEGER Number of messages to retrieve. -O, --offsetdate [%Y-%m-%d] Offset retrieval to specific date in YYYY-MM- DD format. -o, --offsetid INTEGER Offset retrieval to a specific post number. -m, --minid INTEGER Minimal post number. -M, --maxid INTEGER Maximal post number -a, --addoffset INTEGER Add an offset to the post numbers to be retrieved. -f, --fromuser TEXT Only messages from this user. --reverse / --forward Should post numbers count upward or downward. Defaults to forward. -r, --reply_to TEXT Only messages replied to specific post id. --help Show this message and exit. ```
| parameter | description |
|---------------------|------------------------------------------------------------------------------------------------------------------------------|
| channels | a list of of either telegram usernames, channel or group URLs or user IDs. |
| limit | number of messages to retrieve, positive integer. If set to -1 , retrieves all messages in the channel. defaults to -1. |
| offset_date | specify start point of retrieval by date, retrieval direction is controlled by reverse/forward. Format must be YYYY-MM-DD. |
| offset_id | specify start point of retrieval by post number, retrieval direction is controlled by reverse/forward. |
| min_id | sets the minimum post number |
| max_id | sets the maximum post number |
| add_offset | add a offset to the post numbers to be retrieved |
| from_user | limit messages to posts from a specific user |
| reply_to | limit messages to replies to a specific user |
| reverse/forward | flag to indicate whether messages should be retrieved in chronological or reverse chronological order. |
Basic Examples
To retrieve the last fifty messages from a Telegram channel:
bash
tegracli get --limit 50 corona_infokanal_bmg
To retrieve the entire history starting with post #1 of a channel, set limit to -1.
bash
tegracli get --reverse --limit -1 corona_infokanal_bmg
To retrieve messages sent after January, 1st 2022:
bash
tegracli get --offset_date 2022-01-01 corona_infokanal_bmg
To retrieve message sent before January, 1st 2022:
bash
tegracli get --reverse --offset_date 2022-01-01 corona_infokanal_bmg
search
To search messages of your chats and groups and channels you are subscribed to, use this command.
```text Usage: tegracli search [OPTIONS] [QUERIES]...
This function searches Telegram content that is available to your account for the specified search term(s).
Options: --help Show this message and exit. ```
hydrate
To rehydrate messages from the API this command accepts a file with message IDs in the format of $channel_name/$post_number.
Both input and output file are optional, if not given, stdin and stdout are used.
Output data is JSONL, one message per line.
```text Usage: tegracli hydrate [OPTIONS] [INPUTFILE] [OUTPUTFILE]
Hydrate a file with messages-ids.
Options: --help Show this message and exit. ```
For example, to rehydrate message IDs:
```bash echo test_channel/1234 | tegracli hydrate
{"":"Message","id": 1234, ... , "restrictionreason":[],"ttl_period":null} ```
groups
In order to support updatable and long-running collections tegracli sports an account group feature which retrieves the history of a given set of accounts and is able to retrieve updates on each of these accounts.
Groups are initialized by calling teracli group init, where accounts to track are stated by either stating them as arguments or by reading in a file.
Account Group File Format
Account files are expected to follow these requirements:
- UTF8 text document,
- per line one account, given as either username, channel-URL or ID,
- there shall be no header and no additional columns
```text Usage: tegracli group init [OPTIONS] NAME [ACCOUNTS]...
initialize a new account group
Options: -f, --readfile PATH read an account list from a file, one handle/id/url per line. -s, --startdate [%Y-%m-%d] Start date for the collection. Must be in YYYY- MM-DD format. -l, --limit INTEGER number of posts fo retrieve in one run --help Show this message and exit. ```
A group is essentially a directory in your tegracli project folder which holdes
a group configuration file, a profiles.jsonl file which will collect all user objects returned
by Telegram (these will be recycled to save API requests), as well as the jsonl-files containing the messages.
The messages-files are structured in a way that one file holds the messages of one account and is named by the
account's ID.
An exemplary project could look this:
text
tegracli-project/
|- tegracli.conf.yml
|- mysession.session
|- my_group/
|- tegracli_group.conf.yml
|- profiles.jsonl
|- 10000001.jsonl
|- 10000002.jsonl
To run the project command your terminal to tegracli group run my_group to collect the latest post of the accounts you want to track. If you have multiple groups configured you can run all by running tegracli group run all. This interprets all subdirectories as valid groups. However, tegracli will fail if a subdirectory is not a valid group.
```text Usage: tegracli group run [OPTIONS] [GROUPS]...
Load a group configuration and run the groups operations.
GROUPS are subdirectories with a valid group configuration. If the special keyword all is given, all subdirectories are considered. ```
Result File Format
Messages are stored in jsonl-files per channel or query. For channels filename is the channel's or user's id, for searches the query.
BEWARE: how directories and files are structured is subject to active development and prone to changes in the near future.
Developer Installation
- Install poetry,
- Clone repository and unzip, if necessary,
- In the directory run
poetry install, - Run
poetry shellto start the development virtualenv, - Run
pytestto run tests, runpytest --run_apito include tests against the Telegram API (these do require a valid configuration), coverage report can be found undertests/coverage.
Owner
- Name: Leibniz-Institut für Medienforschung | Hans-Bredow-Institut
- Login: Leibniz-HBI
- Kind: organization
- Location: Hamburg
- Website: https://leibniz-hbi.de
- Repositories: 22
- Profile: https://github.com/Leibniz-HBI
Citation (CITATION.bib)
@misc{kesslingLeibnizHBITegracliV02023,
title = {{Leibniz-HBI/Tegracli: V0.3.0}},
author = {Kessling, Philipp and M{\"u}nch, Felix Victor},
year = {2023},
month = jun,
doi = {10.5281/zenodo.8043362},
howpublished = {Zenodo},
}
GitHub Events
Total
- Create event: 6
- Release event: 1
- Issues event: 9
- Watch event: 1
- Delete event: 5
- Issue comment event: 2
- Push event: 28
- Pull request review comment event: 2
- Pull request review event: 5
- Pull request event: 11
Last Year
- Create event: 6
- Release event: 1
- Issues event: 9
- Watch event: 1
- Delete event: 5
- Issue comment event: 2
- Push event: 28
- Pull request review comment event: 2
- Pull request review event: 5
- Pull request event: 11
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 36
- Total Committers: 4
- Avg Commits per committer: 9.0
- Development Distribution Score (DDS): 0.306
Top Committers
| Name | Commits | |
|---|---|---|
| Philipp Kessling | p****g@l****e | 25 |
| Philipp Kessling | 3****n@u****m | 9 |
| dependabot[bot] | 4****]@u****m | 1 |
| Felix Victor Münch | F****r@u****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 44
- Total pull requests: 36
- Average time to close issues: about 1 month
- Average time to close pull requests: 5 days
- Total issue authors: 5
- Total pull request authors: 3
- Average comments per issue: 0.48
- Average comments per pull request: 0.19
- Merged pull requests: 29
- Bot issues: 0
- Bot pull requests: 4
Past Year
- Issues: 5
- Pull requests: 13
- Average time to close issues: 2 days
- Average time to close pull requests: 19 minutes
- Issue authors: 2
- Pull request authors: 2
- Average comments per issue: 0.2
- Average comments per pull request: 0.0
- Merged pull requests: 9
- Bot issues: 0
- Bot pull requests: 2
Top Authors
Issue Authors
- pekasen (28)
- FlxVctr (12)
- JonasRieger (1)
- JanEggers-hr (1)
- vicru (1)
Pull Request Authors
- pekasen (29)
- dependabot[bot] (5)
- FlxVctr (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 10 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 13
- Total maintainers: 2
pypi.org: tegracli
A research-focused Telegram CLI application
- Documentation: https://tegracli.readthedocs.io/
- License: MIT
-
Latest release: 0.3.0
published about 1 year ago
Rankings
Dependencies
- black ^22.6.0 develop
- coverage ^6.4.2 develop
- ipykernel ^6.9.1 develop
- isort ^5.10.1 develop
- pytest ^7.1.2 develop
- pytest-asyncio ^0.18.3 develop
- pytest-cov ^3.0.0 develop
- pytest-socket ^0.5.1 develop
- PyYAML ^6.0
- Telethon ^1.24.0
- click ^8.1.3
- loguru ^0.6.0
- pandas ^1.4.3
- python ^3.9
- ujson ^5.4.0
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/upload-artifact v3 composite
- astroid 3.1.0
- black 24.3.0
- cfgv 3.4.0
- click 8.1.7
- colorama 0.4.6
- coverage 7.4.4
- dill 0.3.8
- distlib 0.3.8
- exceptiongroup 1.2.0
- filelock 3.13.3
- identify 2.5.35
- iniconfig 2.0.0
- isort 5.13.2
- loguru 0.7.2
- mccabe 0.7.0
- mypy-extensions 1.0.0
- nodeenv 1.8.0
- numpy 1.24.4
- numpy 1.26.4
- packaging 24.0
- pandas 2.0.3
- pathspec 0.12.1
- platformdirs 4.2.0
- pluggy 1.4.0
- pre-commit 3.5.0
- pyaes 1.6.1
- pyasn1 0.6.0
- pydocstyle 6.3.0
- pylint 3.1.0
- pytest 8.1.1
- pytest-asyncio 0.23.6
- pytest-cov 5.0.0
- pytest-socket 0.7.0
- python-dateutil 2.9.0.post0
- pytz 2024.1
- pyyaml 6.0.1
- rsa 4.9
- setuptools 70.0.0
- six 1.16.0
- snowballstemmer 2.2.0
- telethon 1.34.0
- tomli 2.0.1
- tomlkit 0.12.4
- typing-extensions 4.10.0
- tzdata 2024.1
- ujson 5.9.0
- virtualenv 20.25.1
- win32-setctime 1.1.0