-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.py
More file actions
32 lines (28 loc) · 1.09 KB
/
Copy pathBot.py
File metadata and controls
32 lines (28 loc) · 1.09 KB
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
import tweepy
import json
import random
import os
from dotenv import load_dotenv
# تحميل المفاتيح من الملف المخفي
load_dotenv('/home/Bot/.env')
# قراءة المصحف المحلي
try:
with open('/home/Bot/quran.json', 'r', encoding='utf-8') as f:
quran = json.load(f)
random_ayah = random.choice(quran)
tweet_text = f"{random_ayah['text']}\n[{random_ayah['surah']} - الآية {random_ayah['number']}]"
except Exception as e:
print(f"خطأ في قراءة الملف: {e}")
exit()
# سحب المفاتيح بأمان من البيئة
client = tweepy.Client(
consumer_key=os.getenv("TWITTER_CONSUMER_KEY"),
consumer_secret=os.getenv("TWITTER_CONSUMER_SECRET"),
access_token=os.getenv("TWITTER_ACCESS_TOKEN"),
access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET")
)
try:
tweet = client.create_tweet(text=tweet_text)
print(f"تم النشر في إكس بنجاح! الرابط: https://x.com/Aziz_Quran_Bot/status/{tweet.data['id']}")
except Exception as e:
print(f"حدث خطأ أثناء النشر في إكس: {e}")