import json
import time
from instagrapi import Client
from instagrapi.types import StoryMention, StoryMedia, StoryLink, StoryHashtag
cl = Client()
def instalogin():
cl.login("shahinloo.hadafazadi_fanpage", input("password"), True,verification_code=input("verification"))
timnow = time.strftime( "%Y %m %d %H %M %S")
print( f" ${timnow=}" )
def downupload():
username = "shahinloo.hadafazadi"
userid = cl.user_id_from_username(username)
shahinloo = cl.user_info_by_username(username)
hashtagmahsaaminifarsi = cl.hashtag_info('مهسا_امینی')
hashtagmahsaamini = cl.hashtag_info('mahsaamini')
hashtagopiran = cl.hashtag_info('opiran')
stories = []
while True:
try:
text_file = open(r"listpk.txt", "r")
data = text_file.read()
listpk = json.loads(data)
text_file.close()
print(listpk.__len__())
time.sleep(12)
timnow = time.strftime( "%Y %m %d %H %M %S")
print( f" start {timnow=}" )
stories = cl.user_stories(userid,0)
while stories.__len__() < 1:
instalogin()
#listpk = []
stories = cl.user_stories(userid,0)
print(f" stories " + str(stories.__len__()))
for storyinfo in stories:
if listpk.count(storyinfo.pk) < 1 :
listpk.append(storyinfo.pk)
print(storyinfo.pk)
#from instagrapi import Client
#from instagrapi.types import StoryMention, StoryMedia, StoryLink, StoryHashtag
#cl = Client()
#cl.login(input("Username"), input("Password"), True,verification_code=input("verification"))
#shahinloo = cl.user_info_by_username("shahinloo.hadafazadi")
#stories = cl.user_stories(shahinloo.pk,0)
#for storyinfo in stories:
story = cl.story_download(storyinfo.pk)
if storyinfo.media_type == 1:
print(story)
cl.photo_upload_to_story( story,
mentions=[StoryMention(user=shahinloo, x=0.49892962, y=0.703125, width=0.8333333333333334, height=0.125)],
hashtags=[StoryHashtag(hashtag=hashtagmahsaamini, x=0.23, y=0.32, width=0.5, height=0.22),
StoryHashtag(hashtag=hashtagmahsaaminifarsi, x=0.23, y=0.62, width=0.5, height=0.22),
StoryHashtag(hashtag=hashtagopiran, x=0.23, y=0.92, width=0.5, height=0.22)]
)
elif storyinfo.media_type == 2:
print(story)
cl.video_upload_to_story(
story,
mentions=[StoryMention(user=shahinloo, x=0.49892962, y=0.703125, width=0.8333333333333334, height=0.125)],
hashtags=[StoryHashtag(hashtag=hashtagmahsaamini, x=0.23, y=0.32, width=0.5, height=0.22),
StoryHashtag(hashtag=hashtagmahsaaminifarsi, x=0.23, y=0.62, width=0.5, height=0.22),
StoryHashtag(hashtag=hashtagopiran, x=0.23, y=0.92, width=0.5, height=0.22)]
)
time.sleep(12)
timnow = time.strftime( "%Y %m %d %H %M %S")
print( f" ${timnow=}" )
else :
print( f"exist ${storyinfo.pk=}" )
print(listpk.__len__())
timnow = time.strftime( "%Y %m %d %H %M %S")
print( f" ${timnow=}" )
jsonString = json.dumps(listpk)
text_file = open(r'listpk.txt', 'w')
text_file.write(jsonString)
text_file.close()
except Exception as inst:
timnow = time.strftime( "%Y %m %d %H %M %S")
print( f" ${timnow=}" )
print(type(inst))
print(inst.args) # arguments stored in .args
print(inst) # __str__ allows args to be printed directly,
print( f"exist ${storyinfo.pk=}" )
downupload()