turns-00067.parquet:27986
3c5c6d8139fb2bc5938d0200
turn 3/5gpt-4o-mini-2024-07-18EnglishAlgeria1106 words
degenerate_repetitionAbsentFinal dense release
USER
from instagrapi import Client
from instagrapi.exceptions import ChallengeRequired, ClientError
import time
import random
import os
from pathlib import Path
class InstagramGrowthBot:
def __init__(self):
self.cl = Client()
self.SESSION_FILE = "ig_session.json"
self.cl.delay_range = [1, 3]
self.actions_today = 0
self.MAX_ACTIONS = 150
self.DELAY_RANGE = (8, 25)
self.username = ""
self.load_session()
def load_session(self):
if Path(self.SESSION_FILE).exists():
try:
self.cl.load_settings(self.SESSION_FILE)
self.cl.get_timeline_feed()
self.username = self.cl.account_info().username
print("✅ تم استعادة الجلسة بنجاح!")
self.show_daily_stats()
return True
except Exception as e:
print(f"❌ الجلسة منتهية: {e}")
os.remove(self.SESSION_FILE)
return False
def save_session(self):
self.cl.dump_settings(self.SESSION_FILE)
print("🔒 تم حفظ الجلسة!")
def safe_login(self):
if self.load_session():
return
print("\n" + "="*30)
print("🎭 تسجيل الدخول إلى إنستجرام")
self.username = input("أدخل اسم المستخدم: ").strip()
password = input("أدخل كلمة المرور: ").strip()
try:
self.cl.login(self.username, password)
print(f"\n✅ تم تسجيل الدخول كـ {self.username} بنجاح!")
self.save_session()
self.show_daily_stats()
except ChallengeRequired:
self.handle_challenge()
except ClientError as e:
print(f"\n❌ خطأ في التسجيل: {e}")
exit()
def handle_challenge(self):
print("\n⚠️ يلزم تأكيد الهوية (تم إرسال رمز إلى بريدك أو رقم الهاتف)")
code = input("أدخل الرمز المكون من 6 أرقام: ").strip()
try:
self.cl.challenge_resolve(self.cl.last_json, code)
print("✅ تم تأكيد الهوية بنجاح!")
self.save_session()
self.show_daily_stats()
except Exception as e:
print(f"❌ فشل التأكيد: {e}")
exit()
def show_daily_stats(self):
print("\n" + "="*30)
print(f"📊 إحصائيات اليوم ({time.strftime('%Y-%m-%d')}):")
print(f"- الإجراءات المتبقية: {self.MAX_ACTIONS - self.actions_today}")
print(f"- الإجراءات المستخدمة: {self.actions_today}")
if self.actions_today >= self.MAX_ACTIONS * 0.8:
print("\n⚠️ اقتربت من الحد اليومي!")
def human_delay(self):
delay = random.uniform(*self.DELAY_RANGE)
print(f"\n⏳ انتظر {delay:.1f} ثانية...", end="", flush=True)
time.sleep(delay)
print("\r" + " "*30 + "\r", end="")
def interactive_menu(self):
while True:
print("\n" + "="*30)
print("📱 قائمة التحكم الرئيسية:")
print("1. التفاعل مع المنشورات")
print("2. متابعة الحسابات")
print("3. نشر محتوى")
print("4. الإحصائيات")
print("5. الخروج")
choice = input("\nاختر إجراء (1-5): ").strip()
if choice == "1":
self.run_interaction_flow()
elif choice == "2":
self.run_follow_flow()
elif choice == "3":
self.run_post_flow()
elif choice == "4":
self.show_daily_stats()
elif choice == "5":
self.cl.logout()
print("\n✅ تم تسجيل الخروج!")
exit()
else:
print("\n❌ خيار غير صحيح!")
def run_interaction_flow(self):
print("\n" + "="*30)
print("💬 تفاعل مع المنشورات")
hashtags = self.select_hashtags()
amount = self.get_number_input("عدد المنشورات (10-50): ", 10, 50)
self.engage_with_content(hashtags, amount)
def run_follow_flow(self):
print("\n" + "="*30)
print("👥 متابعة الحسابات")
hashtags = self.select_hashtags()
amount = self.get_number_input("عدد المتابعات (5-30): ", 5, 30)
self.smart_follow(hashtags, amount)
def run_post_flow(self):
print("\n" + "="*30)
print("📤 نشر محتوى جديد")
image_path = input("مسار الصورة: ").strip()
if not os.path.exists(image_path):
print("\n❌ الملف غير موجود!")
return
caption = input("وصف المنشور: ").strip()
hashtags = self.select_hashtags()
self.post_content(image_path, caption, hashtags)
def select_hashtags(self):
print("\n" + "-"*20)
print("اختر فئة الهاشتاجات:")
categories = [
["تصوير", "فن", "إبداع"],
["تكنولوجيا", "برمجة", "ذكاء_اصطناعي"],
["رياضة", "لياقة", "صحة"]
]
for i, cat in enumerate(categories, 1):
print(f"{i}. {' '.join(f'#{h}' for h in cat)}")
choice = self.get_number_input("اختر فئة (1-3): ", 1, 3)
return categories[choice-1]
def get_number_input(self, prompt, min_val, max_val):
while True:
try:
num = int(input(prompt))
if min_val <= num <= max_val:
return num
print(f"يجب أن يكون بين {min_val}-{max_val}!")
except ValueError:
print("أدخل رقمًا صحيحًا!")
def engage_with_content(self, hashtags, amount):
for hashtag in hashtags:
try:
posts = self.cl.hashtag_medias_recent(hashtag, amount=amount)
for post in posts:
if self.actions_today >= self.MAX_ACTIONS:
return
if not post.has_liked:
self.cl.media_like(post.id)
print(f"♥️ إعجاب: @{post.user.username}")
self.actions_today += 1
self.human_delay()
if random.random() < 0.3:
comments = ["رائع 👏", "إبداع ❤️", "جميل 😍"]
self.cl.media_comment(post.id, random.choice(comments))
self.actions_today += 1
self.human_delay()
except ClientError as e:
print(f"❌ خطأ في #{hashtag}: {e}")
def smart_follow(self, hashtags, limit):
followed_users = set()
for hashtag in hashtags:
try:
posts = self.cl.hashtag_medias_recent(hashtag, amount=50)
for post in posts:
if self.actions_today >= self.MAX_ACTIONS:
return
user_id = post.user.pk
username = post.user.username
try:
# الحل البديل للتحقق من المتابعة
user_info = self.cl.user_info(user_id)
if not user_info.friendship_status.following:
self.cl.user_follow(user_id)
followed_users.add(user_id)
print(f"→ متابعة: @{username}")
self.actions_today += 1
self.human_delay()
if len(followed_users) >= limit:
return
except Exception as e:
print(f"❌ خطأ في متابعة @{username}: {str(e)[:50]}")
self.human_delay()
continue
except ClientError as e:
print(f"❌ خطأ في #{hashtag}: {e}")
self.human_delay()
def post_content(self, image_path, caption, hashtags):
if self.actions_today >= self.MAX_ACTIONS:
return
try:
caption += "\n\n" + " ".join(f"#{h}" for h in hashtags[:25])
self.cl.photo_upload(image_path, caption=caption)
print("✅ تم النشر بنجاح!")
self.actions_today += 1
except ClientError as e:
print(f"❌ خطأ في النشر: {e}")
if __name__ == "__main__":
bot = InstagramGrowthBot()
bot.safe_login()
bot.interactive_menu() انظر الخطاء ✅ تم استعادة الجلسة بنجاح!
==============================
📊 إحصائيات اليوم (2025-03-15):
- الإجراءات المتبقية: 150
- الإجراءات المستخدمة: 0
✅ تم استعادة الجلسة بنجاح!
==============================
📊 إحصائيات اليوم (2025-03-15):
- الإجراءات المتبقية: 150
- الإجراءات المستخدمة: 0
==============================
📱 قائمة التحكم الرئيسية:
1. التفاعل مع المنشورات
2. متابعة الحسابات
3. نشر محتوى
4. الإحصائيات
5. الخروج
اختر إجراء (1-5): 2
==============================
👥 متابعة الحسابات
--------------------
اختر فئة الهاشتاجات:
1. #تصوير #فن #إبداع
2. #تكنولوجيا #برمجة #ذكاء_اصطناعي
3. #رياضة #لياقة #صحة
اختر فئة (1-3): 1
عدد المتابعات (5-30): 4
يجب أن يكون بين 5-30!
عدد المتابعات (5-30): 2
يجب أن يكون بين 5-30!
عدد المتابعات (5-30): 8
❌ خطأ في متابعة @nature.fhotography: 'User' object has no attribute 'friendship_status'
⏳ انتظر 16.8 ثانية...ASSISTANT
The error message you're encountering indicates that the `User` object returned by the `instagrapi` library does not have an attribute `friendship_status`. This likely means that the way to check a user's friendship status has changed in the `instagrapi` library or you're using an outdated method.
To resolve this issue, you should check the correct attribute that contains friendship status information and make sure you're using the latest version of the `instagrapi` library. The attribute in question likely needs to be accessed differently.
### Suggested Fix
You can replace the line where you check the friendship status. The correct way to get the friendship status should look something like this:
```python
friendship_status = self.cl.user_friendship(user_id)
if friendship_status == "none":
# The bot does not follow the user yet, so follow them
self.cl.user_follow(user_id)
```
Here's how you can modify your `smart_follow` method accordingly:
```python
def smart_follow(self, hashtags, limit):
followed_users = set()
for hashtag in hashtags:
try:
posts = self.cl.hashtag_medias_recent(hashtag, amount=50)
for post in posts:
if self.actions_today >= self.MAX_ACTIONS:
return
user_id = post.user.pk
username = post.user.username
try:
# Check if the bot is following the user
friendship = self.cl.user_friendship(user_id)
if not friendship.following:
self.cl.user_follow(user_id)
followed_users.add(user_id)
print(f"→ متابعة: @{username}")
self.actions_today += 1
self.human_delay()
if len(followed_users) >= limit:
return
except Exception as e:
print(f"❌ خطأ في متابعة @{username}: {str(e)[:50]}")
self.human_delay()
continue
except ClientError as e:
print(f"❌ خطأ في #{hashtag}: {e}")
self.human_delay()
```
### General Steps to Take:
1. **Check Attributes:**
Read the documentation or source code of `instagrapi` to confirm the correct ways to check if a user is already followed. Attributes and methods might change.
2. **Update the Library:**
Run the following command to ensure you have the latest version:
```bash
pip install --upgrade instagrapi
```
3. **Error Handling:**
You can add additional error handling if necessary, ensuring that if an error occurs, it does not stop your bot from continuing its tasks.
4. **Testing:**
After making changes, run the bot again to test if the issue is resolved.
By making these adjustments, you should be able to check a user's friendship status correctly without running into the previous error. Always ensure you're referencing the most current methods available in your library version.