Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement X bot as a cloud function #5

Open
aliirz opened this issue Apr 4, 2024 · 4 comments
Open

Implement X bot as a cloud function #5

aliirz opened this issue Apr 4, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@aliirz
Copy link
Contributor

aliirz commented Apr 4, 2024

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
Copy link
Contributor Author

aliirz commented Apr 4, 2024

@humblepenguinn lets groom this. what are your thoughts?

@humblepenguinn
Copy link
Contributor

@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 aliirz added the help wanted Extra attention is needed label Apr 4, 2024
@aliirz
Copy link
Contributor Author

aliirz commented Apr 4, 2024

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

@humblepenguinn
Copy link
Contributor

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

Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants