import requests
import os

import time

# Zaman damgası oluşturma
timestamp = str(int(time.time()))  #

image_path = 'resimler/resim.jpg'  # Resmin yolunu doğru şekilde belirtin

# Resim dosyasını oku
with open(image_path, 'rb') as file:
    image_data = file.read()  # Resim dosyasının verisini oku

data = image_data

cookies = {
buraya çerez  ekleyin...
}

headers = {
    'authority': 'i.instagram.com',
    'accept': '*/*',
    'accept-language': 'tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7',
    'content-type': 'image/jpeg',
    'offset': '0',
    'origin': 'https://www.instagram.com',
    'referer': 'https://www.instagram.com/',
    'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
    'sec-ch-ua-mobile': '?1',
    'sec-ch-ua-platform': '"Android"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36',
    'x-asbd-id': '129477',
    'x-entity-length': '67615',
    'x-entity-name': f'fb_uploader_{timestamp}',
    'x-entity-type': 'image/jpeg',
    'x-ig-app-id': '936619743392459',
    'x-instagram-ajax': '1010609776',
    'x-instagram-rupload-params': '{"media_type":1,"upload_id":"'+timestamp+'","upload_media_height":512,"upload_media_width":512}',
}


response = requests.post(
    f'https://i.instagram.com/rupload_igphoto/fb_uploader_{timestamp}',
    cookies=cookies,
    headers=headers,
    data=data,
)


upload_id = response.json()['upload_id']

headers = {
    'authority': 'www.instagram.com',
    'accept': '*/*',
    'accept-language': 'tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7',
    'content-type': 'application/x-www-form-urlencoded',
    'dpr': '2',
    'origin': 'https://www.instagram.com',
    'referer': 'https://www.instagram.com/',
    'sec-ch-prefers-color-scheme': 'light',
    'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
    'sec-ch-ua-full-version-list': '"Not_A Brand";v="8.0.0.0", "Chromium";v="120.0.6099.130", "Google Chrome";v="120.0.6099.130"',
    'sec-ch-ua-mobile': '?1',
    'sec-ch-ua-model': '"Nexus 5"',
    'sec-ch-ua-platform': '"Android"',
    'sec-ch-ua-platform-version': '"6.0"',
    'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36',
    'viewport-width': '790',
    'x-asbd-id': '129477',
    'x-csrftoken': 'dfgdf',
    'x-ig-app-id': '936619743392459',
    'x-ig-www-claim': 'dfgd',
    'x-instagram-ajax': '1010609776',
    'x-requested-with': 'XMLHttpRequest',
}

data = {
    'archive_only': 'false',
    'caption': 'Açıklama',
    'clips_share_preview_to_feed': '1',
    'disable_comments': '0',
    'disable_oa_reuse': 'false',
    'igtv_share_preview_to_feed': '1',
    'is_meta_only_post': '0',
    'is_unified_video': '1',
    'like_and_view_counts_disabled': '0',
    'source_type': 'library',
    'upload_id': f'{upload_id}',
    'video_subtitles_enabled': '0',
}

response = requests.post('https://www.instagram.com/api/v1/media/configure/', cookies=cookies, headers=headers, data=data)