def tweet_annual_event():
    api = authenticate_api()
    
    # declare empty string
    annual_event_tweet = ""
    tweet_template = "Today is "
    
    # get today's date
    today = str(date.today())
    
    # get today's month and day
    month_and_day = today[5:]
    
    # make a list of the events that match month_and_day
    list_of_event_tweets = [key + ": " + val for key, val in events.items() if month_and_day in key]
    length_list_event_tweets = len(list_of_event_tweets)
    
    '''if list has multiple events for the same month and day,
    then pick random,
    else return the item then update api, if none, no update'''
    # IDEA: generate a thread of tweets if it has multiple events

    if length_list_event_tweets != 0:
        if length_list_event_tweets > 1:
            event_tweet = tweet_template + random.choice(list_of_event_tweets)
        else:
            event_tweet = tweet_template + list_of_event_tweets[0]
        api.update_status(event_tweet)
        print('tweet accomplished')
    else:
        print('no tweet today')
Exemplo n.º 2
0
def tweet_historicat_event():
    api = authenticate_api()

    # declare empty string
    history_tweet = ""
    tweet_template = "This day in LGBTQ history: "

    # get today's date
    today = str(date.today())

    # extract month and day
    month_and_day = today[5:]  # slice off the first 5 characters

    # make a list of the events that match month_and_day
    list_of_history_tweets = [
        key + ": " + val for key, val in events.items() if month_and_day in key
    ]
    length_list_history_tweets = len(list_of_history_tweets)
    '''if list has multiple events for the same month and day,
    then pick random,
    else return the item then update api, if none, no update'''
    # IDEA: generate a thread of tweets if it has multiple events in chronological order

    if length_list_history_tweets != 0:
        if length_list_history_tweets > 1:
            history_tweet = tweet_template + random.choice(
                list_of_history_tweets)
        else:
            history_tweet = tweet_template + list_of_history_tweets[0]
        api.update_status(history_tweet)
        print('tweet accomplished')
    else:
        print('no tweet today')
Exemplo n.º 3
0
def tweet_annual_event():
    api = authenticate_api()

    events_today = []

    def add_events(events_to_add):
        # extend events list if a list of multiple events are given
        if isinstance(events_to_add, list):
            events_today.extend(events_to_add)
        else:
            events_today.append(events_to_add)

    # get today's date
    date_today = date.today()
    today = str(date_today)

    month = today[5:7]
    day = today[8:10]

    # GET EVENTS TODAY

    # get today's month and day
    month_and_day = f'{month}-{day}'

    # find and add events matching the case
    add_events(events.get(month_and_day, []))

    # GET RELATIVE EVENTS THAT RESOLVE TO TODAY

    # get today's weekday - 0-6 = Monday-Sunday
    weekday_index = date_today.weekday()

    # convert to letter
    # MTWRFSU - Monday, Tuesday, Wednesday, thuRsday, Friday, Saturday, sUnday

    weekday_letters = "MTWRFSU"
    weekday = weekday_letters[weekday_index]

    # determine which week we are in
    week = ceil(int(day) / 7)
    # create the code to look up - format 'MM-nU' would be the nth sUnday of the current Month
    nth_weekday_of_month = f'{month}-{week}{weekday}'

    # find and add events matching the case
    add_events(events.get(nth_weekday_of_month, []))
    '''Pick a random Event from the list of events today and tweet it'''
    # IDEA: generate a thread of tweets if it has multiple events

    if events_today:
        chosen_event = choice(events_today)
        event_tweet = f'Today is {chosen_event}'
        api.update_status(event_tweet)
        print('annual event tweet accomplished')
    else:
        print('no annual event tweet today')
def tweet_annual_event():
    api = authenticate_api()

    # declare empty string
    annual_event_tweet = ""
    tweet_template = "Today is "

    # get today's date
    today = str(date.today())

    # get today's month and day
    month_and_day = today[5:]

    # get today's weekday - 0 = Monday
    weekday_index = date.today().weekday()

    # convert to letter
    weekday_letters = "MTWRFSU"
    weekday = weekday_letters[weekday_index]

    # determine which week we are in
    week = ceil(int(today[8:]) / 7)

    # create the code to look up - format '2M' would be the 2nd Monday
    nth_weekday = str(week) + weekday

    # make a list of the events that match month_and_day or specific day of the month
    list_of_event_tweets = [
        val for key, val in events.items() if month_and_day in key
    ]
    list_of_event_tweets.append(
        [val for key, val in events.items() if nth_weekday in key])

    #removes empty list from list_of_events
    list_of_event_tweets = [x for x in list_of_event_tweets if x != []]
    length_list_event_tweets = len(list_of_event_tweets)
    '''if list has multiple events for the same month and day,
    then pick random,
    else return the item then update api, if none, no update'''
    # IDEA: generate a thread of tweets if it has multiple events

    if length_list_event_tweets != 0:
        if length_list_event_tweets > 1:
            event_tweet = tweet_template + str(choice(list_of_event_tweets))
        else:
            event_tweet = tweet_template + str(
                list_of_event_tweets[0]
            )  # str(list_of_event_tweets) == ['a good day for testing yet another feature in production. We now support annual events with variable dates like "5th Friday of October"']
        api.update_status(event_tweet)
        print('annual event tweet accomplished')
    else:
        print('no annual event tweet today')
Exemplo n.º 5
0
def tweet_historicat_event():
    api = authenticate_api()
    # check events list for date that matches today's date
    count = 0
    for event in events:
        event_date = events[count][
            0]  # get date from 1st element in tuple from list
        today = date.today()
        count = count + 1  # save the current iteration in a variable
        if event_date == today:  # only tweet if date is today
            title = events[count][
                1]  # get date from 2nd element in tuple from list
            reference_link = events[count][
                2]  # get date from 3rd element in tuple from list
            history_tweet = f"This day in LGBTQ history: {title}\n\n{reference_link}"
            api.update_status(history_tweet)
            print('tweet accomplished')
Exemplo n.º 6
0
def tweet_historicat_event():
    api = authenticate_api()

    # declare empty string
    history_tweet = ""
    tweet_template = "this day in LGBTQ history 🏳️‍🌈🏳️‍⚧️📜\n\n"

    # get today's date
    today = str(date.today())

    # extract month and day
    month_and_day = today[5:]  # slice off the first 5 characters

    # make a list of the events that match month_and_day
    list_of_history_tweets = [
        key + ":\n" + val for key, val in events.items()
        if month_and_day == key[5:]
    ]
    length_list_history_tweets = len(list_of_history_tweets)
    '''if list has multiple events for the same month and day,
    then pick random,
    else return the item then update api, if none, no update'''
    # IDEA: generate a thread of tweets if it has multiple events in chronological order

    if length_list_history_tweets != 0:
        history_tweet = random.choice(list_of_history_tweets)
        year_difference = int(today[:4]) - int(history_tweet[:4])
        if (year_difference > 1):
            tweet_template = str(
                year_difference) + " years ago " + tweet_template
        else:
            tweet_template = str(
                year_difference) + " year ago " + tweet_template
        history_tweet = tweet_template + history_tweet
        api.update_status(history_tweet)
        print('tweet accomplished')
    else:
        print('no tweet today')