Closed VickiLanger closed 2 years ago
This doesn't make sense. We already get rid of the year. So, why did this event post when it did?
# 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 in key]
length_list_history_tweets = len(list_of_history_tweets)
This is searching for MM-DD in each key, and each key is YYYY-MM-DD, so, if the key for an event is '2004-07-20', on 7th April code will match it with '04-07' which is present in the date, and on 20th July it'll be checked against '07-20' which it also has. the MM-DD for today needs to be matched with only the last 5 characters of the date not all of it. I'll make a pr with a fix
This is searching for MM-DD in each key, and each key is YYYY-MM-DD, so, if the key for an event is '2004-07-20', on 7th April code will match it with '04-07' which is present in the date, and on 20th July it'll be checked against '07-20' which it also has. the MM-DD for today needs to be matched with only the last 5 characters of the date not all of it. I'll make a pr with a fix
That would be awesome. I'm still confused though. I thought we already sliced the first 5 characters in the date. 🤷🏼
We are removing the first 5 letters of today's date but the dates of events are still in "YYYY-MM-DD" format, so we need to compare the variable month_and_day
with only the last 5 letters of the keys
Hey I made a pull request resolving the issue.
Hope it helps!
Describe the bug An event for
2004-07-20
will post on04-07
and07-20
https://twitter.com/lgbtqotd/status/1379660512082944002?s=21
Expected behavior Only have post on the correct date
Screenshots![Screenshot of faulty tweet, posted on April 7th, with the above-described bug "17 years ago this day in LGBTQ history 2004-07-20: Guido Westerwelle, leader of the FDP, becomes the first leader of a major party to come out."](https://user-images.githubusercontent.com/46823403/114186913-66068b80-9915-11eb-8b62-1e907f1808e3.png)
Don't forget to follow the bot on Twitter to see the hard work you put in.