Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
improved reels feature NO CREDENTIALS REQUIRED
Browse files Browse the repository at this point in the history
1. No need to give instagram credentials
2. Instant reel download
  • Loading branch information
Philotheephilix committed Jul 6, 2023
1 parent 832bae1 commit 2d9262b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 75 deletions.
10 changes: 4 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
E-mail_for_checking_email=nono
Password_for_checking_mail=none
Instagram_username=none
Instagram_password=none
TELE_API_KEY=none
Open_Weather_API=none
E-mail_for_checking_email=
Password_for_checking_mail=
Telegram_bot_API=
Open_Weather_API=
28 changes: 13 additions & 15 deletions Initialize.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import os
from cryptography.fernet import Fernet
with open('crypt.key', 'wb') as filekey:
filekey.write(key)

def init_var():
mod={
"E-mail_for_checking_email":"",
"Password_for_checking_mail":"",
"Instagram_username":"",
"Instagram_password":"",
"Telegram_bot_API":"",
"Open_Weather_API":""
}
data=open("kets.env","r")
dada=data.readlines()
data=open(".env","r")
dada = data.readlines()
for val in dada:
print(val)
k,v=val.strip().split(":",1)
if k in mod:
new_value = input(f"Enter a new value for {k}: ")
mod[k] = new_value
if ":" in val:
k, v = val.strip().split(":", 1)
if k in mod:
new_value = input(f"Enter a new value for {k}: ")
mod[k] = new_value
data.close()
data=open("kets.env","w")
data=open(".env","w")
for key, value in mod.items():
data.write(f"{key}:{value}\n")
data.write(f"{key}={value}\n")
data.close()
data=open("kets.env","r")
data=open(".env","r")
dada=data.read()
print(dada)
def encrypt():
Expand All @@ -35,10 +33,10 @@ def encrypt():
with open('crypt.key', 'rb') as filekey:
key = filekey.read()
fernet = Fernet(key)
with open('kets.env', 'rb') as file:
with open('.env', 'rb') as file:
original = file.read()
encrypted = fernet.encrypt(original)
with open('kets.env', 'wb+') as encrypted_file:
with open('.env', 'wb+') as encrypted_file:
encrypted_file.write(encrypted)
enc=encrypted_file.read()
print(enc)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This bot can automate these following tasks

7. Commands : This command returns all the available commands

8. Reels : When the user sends the command "/sos ,the bot asks the user to send instagram reel link, when the user sends the link the bot retrieves the reels video from instagram and sends it to the user
8. Reels : When the user sends the command "/reels ,the bot asks the user to send instagram reel link, when the user sends the link the bot retrieves the reels video from instagram and sends it to the user
## Links
[Releases](https://github.com/Philotheephilix/Multi-funtional-telegram-bot/releases)

Expand Down
61 changes: 8 additions & 53 deletions multi_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@
load_dotenv(tempdir+"\.env")
username=os.getenv("E-mail_for_checking_email")
password=os.getenv("Password_for_checking_mail")
TELE_API_KEY = os.getenv("TELE_API_KEY")
TELE_API_KEY = os.getenv("Telegram_bot_API")
print(TELE_API_KEY)
OW_API = os.getenv("Open_Weather_API")
USERNAME = os.getenv("Instagram_username")
PASSWORD = os.getenv("Instagram_password")
with open(".env","r") as credentials:
Credentials=credentials.readlines()
print(Credentials)
Expand Down Expand Up @@ -279,56 +277,13 @@ def city(message):
bot.reply_to(message,sos)
sos_active="0"
elif reels_active=="1":
def login_user():
global cl
session = cl.load_settings("session.json")
login_via_session = False
login_via_pw = False
if session:
try:
cl.set_settings(session)
cl.login(USERNAME, PASSWORD)
try:
cl.get_timeline_feed()
print("logged using session")
except LoginRequired:
old_session = cl.get_settings()
cl.set_settings({})
cl.set_uuids(old_session["uuids"])
cl.login(USERNAME, PASSWORD)
login_via_session = True
except Exception as e:
pass
if not login_via_session:
try:
if cl.login(USERNAME, PASSWORD):
login_via_pw = True
except Exception as e:
pass
if not login_via_pw and not login_via_session:
raise Exception("Couldn't login user with either password or session")
def download_reels():
global cl
info = cl.media_pk_from_url(URL)
clip_url = cl.media_info(info).video_url
print("download folder:"+tempdir+"\reels")
cl.clip_download_by_url(clip_url, folder = tempdir+"\\reels")
print("downloaded")
def sendreels():
dlist=os.listdir(tempdir+"\\reels")
reeldir=dlist[0]
print(reeldir)
reel=open(tempdir+"\\reels\\"+reeldir,"rb")
print("opened")
bot.send_video(message.chat.id,reel,timeout=120)
print("reels sent")
reel.close()
os.remove(tempdir+"\\reels\\"+reeldir)
URL= str(message.text)
login_user()
download_reels()
sendreels()
reels_active="0"
ori_reel=str(message.text)
reel=ori_reel.split("https://www.instagram.com/reel/")
base_url="https://www.ddinstagram.com/reel/"
Reel_to_send=base_url+reel[1]
Reel_markup="[REEL]("+Reel_to_send+")"
print(Reel_markup)
bot.reply_to(message,Reel_markup)
else:
bot.reply_to(message,"Enter valid command \n type /commands to list all commands")
#polling command to receive commands from bot
Expand Down

0 comments on commit 2d9262b

Please sign in to comment.