-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
37 lines (33 loc) · 1.16 KB
/
main.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
import time
from PIL import Image
import requests
from io import BytesIO
from selenium import webdriver
import instabot
import random
import os
def get_random_image():
res=random.randint(32,108)
res*=10
print(res)
link=f'https://source.unsplash.com/random/{res}x{res}'
response = requests.get(link)
img = Image.open(BytesIO(response.content))
img.save('post.jpg')
print("Image Fatched !")
def get_random_caption():
driver = webdriver.Chrome()
driver.get("https://randomtextgenerator.com/")
caption = driver.find_element_by_id('generatedtext')
captions = caption.text.split('.')
print("Caption Fatched !")
return captions[0] + '. '+ f'#{captions[1].split()[0]} ' + f'#{captions[1].split()[1]} ' + f'#{captions[1].split()[2]}'
def post(caption,username="",password=""):
caption+=" #bot #random"
bot=instabot.Bot()
bot.login(username=username,password=password)
bot.upload_photo('C:\\Users\\Deep Raval\\Desktop\\Projects\\Insta-Bot\\post.jpg', caption=caption)
if __name__ == "__main__":
get_random_image()
caption=get_random_caption()
post(caption,username="insta_bot_1729",password="XXX")