mirror of
https://github.com/brockar/ig2tg.git
synced 2026-01-12 07:20:58 -03:00
fix imports and modify README and .env.example
This commit is contained in:
110
README.md
110
README.md
@@ -1,30 +1,50 @@
|
||||
# IG2TG: Instagram Stories to Telegram
|
||||
# IG2TG: Instagram Stories to Telegram Automation
|
||||
|
||||
**IG2TG** is a Python tool that automatically downloads Instagram stories from a specified user and sends updates to your Telegram chat. It leverages [Instaloader](https://instaloader.github.io/) for Instagram scraping and [python-telegram-bot](https://python-telegram-bot.org/) for Telegram integration.
|
||||
**IG2TG** is a Python package and CLI tool that automatically downloads Instagram stories from specified users and sends them to your Telegram chat.
|
||||
It leverages [Instaloader](https://instaloader.github.io/) for Instagram scraping and [python-telegram-bot](https://python-telegram-bot.org/) for Telegram integration.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- Download Instagram stories from any public or followed private account.
|
||||
- Automatically cleans up unnecessary files after download.
|
||||
- Designed for easy integration with Telegram bots to send story updates to your chat.
|
||||
- Sends new stories to your Telegram chat via a bot.
|
||||
- Easy configuration with environment variables.
|
||||
|
||||
---
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.7+
|
||||
- Instagram account credentials or session cookies
|
||||
- Telegram Bot Token
|
||||
- Instagram accounts to download stories.
|
||||
|
||||
Install dependencies with:
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
Install dependencies (for development or direct use):
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Or, if you want to install as a package (after building):
|
||||
|
||||
```bash
|
||||
pip install .
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Setup
|
||||
|
||||
1. **Clone the repository:**
|
||||
|
||||
```bash
|
||||
git clone <your-repo-url>
|
||||
git clone https://github.com/brockar/ig2tg.git
|
||||
cd ig2tg
|
||||
```
|
||||
|
||||
@@ -37,30 +57,81 @@ pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Edit `.env` and set:
|
||||
- `IG_USERNAME` and `IG_PASSWORD` (or `IGSESSIONID` and `IGCSRFTOKEN` for session login)
|
||||
- `TELEGRAM_TOKEN` (your Telegram bot token)
|
||||
- `IG_USERNAME` and `IG_PASSWORD` (or `IGSESSIONID` and `IGCSRFTOKEN` for session login) (works with 2FAs)
|
||||
- `TELEGRAM_TOKEN` (your Telegram bot token) and `TG_USER` to just send images to your telegram user.
|
||||
|
||||
The script uses environment variables for authentication. Here’s how to get each one:
|
||||
- **IG_USERNAME**: Your Instagram username (email or handle).
|
||||
- **IG_PASSWORD**: Your Instagram password.
|
||||
- **IGSESSIONID** and **IGCSRFTOKEN**:
|
||||
If you prefer not to use your password, you can log in to Instagram in your browser, open the Developer Tools, and copy these cookies from your session:
|
||||
**How to get Instagram session cookies:**
|
||||
1. Go to [instagram.com](https://instagram.com) and log in.
|
||||
2. Open Developer Tools (F12 or right-click → Inspect).
|
||||
3. Go to the "Application" tab, then "Cookies".
|
||||
4. Copy the values for `sessionid` (set as `IGSESSIONID`) and `csrftoken` (set as `IGCSRFTOKEN`).
|
||||
|
||||
3. **Run the script:**
|
||||
3. **Add Instagram usernames to monitor:**
|
||||
|
||||
```bash
|
||||
python scripts/stories.py
|
||||
Create a file named `user_list.txt` in the project root and add one Instagram username per line (no `@`):
|
||||
|
||||
```
|
||||
testuser1
|
||||
testuser2
|
||||
```
|
||||
|
||||
You will be prompted to enter the Instagram username whose stories you want to download.
|
||||
Also can add comments with `#`
|
||||
|
||||
## Sending Stories to Telegram
|
||||
---
|
||||
|
||||
To send downloaded stories to your Telegram chat, extend the script using the `python-telegram-bot` library. You can use the `TELEGRAM_TOKEN` from your `.env` file to authenticate your bot and send media files to your chat.
|
||||
## Usage
|
||||
|
||||
### As a CLI tool (recommended)
|
||||
|
||||
After installing as a package, run:
|
||||
|
||||
```bash
|
||||
ig2tg
|
||||
```
|
||||
|
||||
### As a Python script
|
||||
|
||||
You can also run the main script directly:
|
||||
|
||||
```bash
|
||||
python -m ig2tg.main
|
||||
```
|
||||
|
||||
The tool will:
|
||||
- Log in to Instagram using your credentials or session.
|
||||
- Download stories for each user in `user_list.txt`.
|
||||
- Clean up unnecessary files.
|
||||
- Send new stories to your Telegram chat.
|
||||
- Repeat the process every 24 hours.
|
||||
|
||||
---
|
||||
|
||||
## Telegram Integration
|
||||
|
||||
- The Telegram bot will send all new stories to the chat where you first interact with it.
|
||||
- Only the user specified in your `.env` as `TG_USER` can trigger the bot.
|
||||
|
||||
---
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
ig2tg/
|
||||
__init__.py
|
||||
main.py
|
||||
stories.py
|
||||
tg.py
|
||||
utils.py
|
||||
stories/
|
||||
<downloaded stories organized by user>
|
||||
user_list.txt
|
||||
.env
|
||||
README.md
|
||||
pyproject.toml
|
||||
LICENSE
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
@@ -68,4 +139,5 @@ This project is licensed under the [GNU GPLv3](LICENSE).
|
||||
|
||||
---
|
||||
|
||||
**Note:** Use this tool responsibly and respect Instagram's terms of service.
|
||||
**Note:**
|
||||
Use this tool responsibly and respect Instagram's and Telegram's terms of service.
|
||||
|
||||
@@ -2,4 +2,5 @@ IG_USERNAME=""
|
||||
IG_PASSWORD=""
|
||||
IGSESSIONID=""
|
||||
IGCSRFTOKEN=""
|
||||
TELEGRAM_TOKEN=""
|
||||
TELEGRAM_TOKEN=""
|
||||
TG_USER=""
|
||||
@@ -7,8 +7,8 @@ logger = logging.getLogger(__name__)
|
||||
from dotenv import load_dotenv
|
||||
import instaloader
|
||||
|
||||
from utils import ig_login, load_user_list, wait_before_next_check
|
||||
from stories import download_stories_for_user
|
||||
from ig2tg.utils import ig_login, load_user_list, wait_before_next_check
|
||||
from ig2tg.stories import download_stories_for_user
|
||||
|
||||
def main():
|
||||
"""Main entry point for the IG2TG story downloader."""
|
||||
|
||||
@@ -4,7 +4,7 @@ from retrying import retry
|
||||
import requests
|
||||
import os
|
||||
import logging
|
||||
from utils import delete_files_with_specific_extensions
|
||||
from ig2tg.utils import delete_files_with_specific_extensions
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user