codeforpakistan / Numainda

Numainda a democracy focused knowledge bot
https://numainda.streamlit.app
MIT License
5 stars 1 forks source link

Implement X bot as a cloud function #5

Open aliirz opened 5 months ago

aliirz commented 5 months ago

Open for discussion, but the idea is that we implement the bot as a time-based cloud function that can read tweets @ it every n seconds. It then formulates a reply based on the open AI assistant and sends that back, mentioning the original x user

here is a a very poor man's idea to get tweets @ numaindapk every 5 minutes:

from datetime import datetime, timedelta
# Twitter API v2 endpoint for recent search
url = 'https://api.twitter.com/2/tweets/search/recent'

end_time = datetime.utcnow() - timedelta(minutes=5)
end_time_str = end_time.strftime('%Y-%m-%dT%H:%M:%SZ')

# Replace 'your_bot_username' with your bot's actual username without @
params = {
    'query': '@numaindapk',
    'tweet.fields': 'author_id,created_at',
    # Use a fixed start time
    'start_time': '2024-02-08T00:00:00Z',
    # Dynamically calculated end_time based on current time
    'end_time': end_time_str,
}

response = oauth.get(url,  params=params)
tweets = response.json()

# Print the tweets to verify
print(json.dumps(tweets, indent=4))
aliirz commented 5 months ago

@humblepenguinn lets groom this. what are your thoughts?

humblepenguinn commented 5 months ago

@humblepenguinn lets groom this. what are your thoughts?

Seems like a great idea, but I don't think we need to directly interact with the API ourselves.

We can use the tweepy package. What do you say?

aliirz commented 5 months ago

i am good with your implementation in #2 we can use tweepy

humblepenguinn commented 5 months ago

@aliirz I opened a pull request for a simple draft I wrote for the service.

Let me know what you think.