Пример #1
0
def post_tweet_from_changes(changes: Iterable[dict],
                            map_changes_to_twit_msg_content: Callable,
                            dry_run: bool):
    msg = map_changes_to_twit_msg_content(changes, range(0, len(changes)),
                                          True)
    if not dry_run:
        post_tweet(msg)
    print(msg, len(msg))

    if not dry_run:
        sleep(TWEET_POST_DELAY)
Пример #2
0
def check_make_tweet():
    """
    Checks if we should post any tweets
    """

    #A run above 15 min is not already ongoing, post normal tweet
    if not run_timer.run_ongoing(forsenbot.previous_time, time.time()):
        twitter_api.post_tweet()
        forsenbot.previous_time = time.time()

    #On the Ender dragon fight
    if run_timer.check_dragon('screenshots/capture.png'):

        #Forsen is in the End, and a dragon fight is not already ongoing, post special tweet
        if not run_timer.run_ongoing(forsenbot.previous_dragon_time,
                                     time.time()):
            twitter_api.post_dragon_tweet()
            forsenbot.previous_dragon_time = time.time()
Пример #3
0
def start():
    print("Starting up...")
    api = oauth_login()
    SLEEP_INTERVAL = 60 * 20
    USER_ID = int(environ.get("USER_ID"))
    USERNAME = environ.get("USERNAME")
    tweet_day = int(environ.get("TWEET_DAY"))
    retweet_day = int(environ.get("RETWEET_DAY"))
    TWEET_INTERVAL = 6
    RETWEET_INTERVAL = 11
    line = int(environ.get("TWEET_LINE"))
    last_retweet_id = 0

    while (datetime.today().hour - 5) != 12:
        print("Waiting for noon...")
        sleep(SLEEP_INTERVAL)

    while True:
        print("Waking up")
        if (date.today().month == 1) and (date.today().day == 31):
            post_tweet(
                api,
                f"happy birthday {USERNAME}! hope you have a good one. love you!"
            )
        elif (date.today().month == 12) and (date.today().day == 25):
            post_tweet(api, "merry christmas! hope Eve has a good one.")
        elif tweet_day >= TWEET_INTERVAL:
            f = open("tweets.txt")
            content = f.readlines()
            if line >= len(content):
                line = 0
            tweet = content[line].replace("???", USERNAME)
            post_tweet(api, tweet)
            f.close()
            tweet_day = 0
        elif retweet_day >= RETWEET_INTERVAL:
            latest_tweets = get_latest_tweets(api, USER_ID)
            if latest_tweets:
                for latest_tweet in latest_tweets:
                    if latest_tweet["id"] == last_retweet_id:
                        break
                    if latest_tweet["favorite_count"] >= 10:
                        retweet(api, latest_tweet["id"])
                        last_retweet_id = latest_tweet["id"]
                        break
            retweet_day = 0

        print(f"Days since last tweet: {tweet_day}")
        print(f"Last tweet on line {line}")
        print(f"Days since last retweet: {retweet_day}")
        print(f"ID of last retweet: {last_retweet_id}")

        tweet_day += 1
        retweet_day += 1
        for i in range(3 * 24):
            print("Sleeping...")
            sleep(SLEEP_INTERVAL)
Пример #4
0
def start():
    print("Starting up...")
    api = oauth_login()
    USER_ID = int(environ.get("USER_ID"))
    USERNAME = environ.get("USERNAME")
    starting_day = environ.get("STARTING_DAY")
    starting_date = datetime.strptime(starting_day, "%B %d, %Y")
    today = datetime.today()
    days_since = (today - starting_date).days
    TWEET_INTERVAL = 6
    RETWEET_INTERVAL = 11
    tweet_day = days_since % TWEET_INTERVAL
    retweet_day = days_since % RETWEET_INTERVAL
    line = floor(days_since / TWEET_INTERVAL) - 1

    if (date.today().month == 1) and (date.today().day == 31):
        post_tweet(
            api,
            f"happy birthday {USERNAME}! hope you have a good one. love you!")
    elif (date.today().month == 12) and (date.today().day == 25):
        post_tweet(api, "merry christmas! hope Eve has a good one.")
    elif tweet_day == 0:
        f = open("tweets.txt")
        content = f.readlines()
        tweet = content[line].replace("???", USERNAME)
        while line >= len(content):
            line = len(content) - line
            tweet = content[line].replace("???", USERNAME)
        post_tweet(api, tweet)
        f.close()
    elif retweet_day == 0:
        latest_tweets = get_latest_tweets(api, USER_ID)
        if latest_tweets:
            for latest_tweet in latest_tweets:
                created_date = datetime.strptime(
                    latest_tweets[0]["created_at"].replace("+0000 ", ""), "%c")
                if RETWEET_INTERVAL <= ((today - created_date).days + 1):
                    break
                if latest_tweet["favorite_count"] >= 10:
                    retweet(api, latest_tweet["id"])
                    break

    print(f"Days since last tweet: {tweet_day}")
    print(f"Last tweet on line {line}")
    print(f"Days since last retweet: {retweet_day}")