**Guys who is know how check new direct messagee from instagram ** I want to run code in real time and read new unreaded messages from instagram.
import json
from instagrapi import Client
from instagrapi.types import StoryMention, StoryMedia, StoryLink, StoryHashtag
def get_user_access(data):
with open(data, 'r', encoding='utf-8') as file:
f = json.load(file)
return f['login'], f['password']
USERNAME, PASSWORD = get_user_access('data.json')
cl = Client()
cl.login(USERNAME, PASSWORD)
user_id = cl.user_id_from_username(USERNAME)
thread = cl.direct_threads(1)
messages = cl.direct_threads(amount=10)
for message in messages:
text = message.messages[0].text
user_id = message.messages[0].user_id
username = cl.user_info(user_id).username
print(message.messages[0].text)