Search code examples
twittertweepytweetstwitter-api-v2

Tweet Every 30 Minutes


i have a bot to create tweets, and i would like to run it every 30 minutes.

so far i run it just for testing via Terminal like this: PS C:\Users\XXX> python "C:\Users\xxx\module1.py" this is the actual bot code:

from typing import Text
import tweepy
import random

from tweepy import Response, tweet
client = tweepy.Client(
    consumer_key="XXXXXX",
    consumer_secret="XXXXXX",
    access_token="XXXXXX",
    access_token_secret="XXXXXX"
)

import requests
from bs4 import BeautifulSoup
import webbrowser

while True:
    url = requests.get("https://he.wikipedia.org/wiki/Special:Random")
    soup = BeautifulSoup(url.content, "html.parser")
    title = soup.find(class_="firstHeading").text
    printed = print(title)
    break
try:
   client.create_tweet(text="לשטח את " + title)
   print("וואלה יופי הצלחת יא בתול")
   print("יא קינג יא אלוף אין עליך יא גאון מחשבים")
except tweepy.errors.TweepyException as e:
   print("שגיאה על הראש שלך")
   print("יא אפס")


Solution

  • If you need to create a tweet every 30 minutes, you can set up a CRON job to execute the task at that interval.

    Additionally, remember to use a different title each time, as tweets from the same account cannot have the same title.