This project is a Telegram bot that downloads Instagram stories and stores them in a SQLite database. It allows users to download stories from Instagram profiles, view downloaded stories, and export the data as a CSV file.
Used during the Paris 2024 Olympic Games to connect fans with athletes Instagram profiles and build a database of their memorable moments, this sample version of the project uses a smaller dataset to demonstrate key features with reduced complexity. Feel free to adapt this bot to suit your specific use case and research needs.
- Download Instagram stories from public profiles
- View downloaded stories
- Retrieve stories by Instagram user or Telegram user
- Saved stories are stored in a SQLite table
- Export stories data to a CSV file
Example of the data that was stored in the stories.db
table in SQLite, converted to .csv to be sent via Telegram.
- Python 3.x 🐍🐍
- Telegram Account
python-telegram-bot
libraryinstaloader
librarysqlite3
library (included with Python)pandas
library (optional for data manipulation using .csv file)
git clone https://github.com/yourusername/instagram-stories-downloader-bot.git
cd instagram-stories-downloader-bot
Make sure you have pip
installed, then run:
pip install python-telegram-bot instaloader pandas
-
Create a Telegram Bot:
- Use BotFather on Telegram to create a new bot and get the API key.
- Replace the
api_key
inbot.py
with your bot’s API key.
-
Create a Session File for Instaloader:
- Use
instaloader
to log in and create a session file or log in Instagram using Firefox and run theimportfirefoxsession.py
. - Run
instaloader --login your_username
and follow the prompts. - Save the session file with the name
session-topcortessecos
or modify the code to match your session file name.
- Use
Start the bot with:
python telegrambot.py
The bot will now be running and listening for commands on Telegram.
/downloadstories
- Download all available stories from an Instagram user. Type the username without@
./getmystories
- Retrieve your downloaded stories./getstories
- Get stories for a specific Instagram user. Type the username to fetch stories./viewtable
- View the entire stories table as a CSV file.
The /viewtable
command generates a CSV file with the following columns:
ID
Telegram User ID
Instagram User
File Path
Time Posted
Country
The file is sent as a document through Telegram.
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions, feel free to reach out vinigoes@outlook.com or vinox_quente on Discord.