-
Notifications
You must be signed in to change notification settings - Fork 12
/
bot.py
119 lines (95 loc) · 3.58 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from aiogram import Bot, Dispatcher, executor, types, executor
import aiogram.utils.markdown as fmt
from instaloader import Instaloader
from tg_token import TOKEN
from insta_config import USERNAME, PASSWORD
import asyncio
import os, os.path, glob
import keyboard as kb
bot = Bot(TOKEN)
dp = Dispatcher(bot)
L = Instaloader()
L.login(USERNAME, PASSWORD)
URL = 'https://www.instagram.com/'
''' Command Start '''
@dp.message_handler(commands="start")
async def cmd_start(message: types.Message):
user_id = message.from_user.id
await bot.send_sticker(user_id, sticker='CAACAgIAAxkBAAEEeItiWG7TWqCapeRnGLmb0JhzlfO6UwACAQEAAladvQoivp8OuMLmNCME')
await message.answer(f"Hi, {message.from_user.first_name}")
await message.answer("List of available commands: /help ")
""" Download stories """
@dp.message_handler(commands="stories")
async def cmd_start(message: types.Message):
await message.answer("Input a username or send profile link")
@dp.message_handler()
async def get_username(message: types.Message):
get_username = message.text
username = get_username.replace(URL, '').replace('/', '')
print(username)
profile = L.check_profile_id(username)
print(profile.userid)
await message.answer("User found, please wait... ⏳", disable_notification=True)
profile = L.check_profile_id(username)
L.download_stories(userids=[profile.userid],filename_target='{}'.format(profile.username))
dirname = str(username)
print('path: ', dirname)
await asyncio.sleep(1)
media = types.MediaGroup()
await types.ChatActions.upload_photo()
os.chdir(dirname)
# send photo
for file in glob.glob("*.jpg"):
print(file)
media.attach_photo(types.InputFile(file))
await message.reply_media_group(media=media)
media = types.MediaGroup()
await types.ChatActions.upload_video()
# send video
for file in glob.glob("*.mp4"):
print(file)
media.attach_video(types.InputFile(file))
await message.reply_media_group(media=media)
''' Download posts '''
@dp.message_handler(commands="posts")
async def cmd_start(message: types.Message):
await message.answer("Input a username or send profile link")
@dp.message_handler()
async def get_username(message: types.Message):
get_username = message.text
username = get_username.replace(URL, '').replace('/', '')
print(username)
profile = L.check_profile_id(username)
await message.answer("User found, please wait... ⏳", disable_notification=True)
profile = L.check_profile_id(username)
L.download_profile(profile)
dirname = str(username)
print('path: ', dirname)
await asyncio.sleep(1)
media = types.MediaGroup()
await types.ChatActions.upload_photo()
os.chdir(dirname)
# send photo
for file in glob.glob("*.jpg"):
print(file)
media.attach_photo(types.InputFile(file))
await message.reply_media_group(media=media)
media = types.MediaGroup()
await types.ChatActions.upload_video()
# send video
for file in glob.glob("*.mp4"):
print(file)
media.attach_video(types.InputFile(file))
await message.reply_media_group(media=media)
''' Get Help '''
@dp.message_handler(commands="help")
async def cmd_start(message: types.Message):
await message.answer(
fmt.text(
fmt.text("/stories — get a stories"),
fmt.text("/posts — get a posts"),
sep="\n"
), parse_mode="HTML"
)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)