Hi @biksco, welcome to the forum!
feedparser returns two values that hold the published date for the item:
published retains the format used in the feed, e.g.
Monday, June 10 2019.
published_parsed, on the other hand, returns a tuple in the same format as that returned from
So, what we can do, is this:
from time import gmtime
now = gmtime()
print(now,now,now) # the current YEAR MONTH DAY
dgtw = feedparser.parse('https://investorshub.advfn.com/boards/rss.aspx?board_id=22658')
pub_today = 0
for entry in dgtw['entries']:
#print(entry.published_parsed,entry.published_parsed,entry.published_parsed) # print entry YEAR MONTH DAY for debugging
if (entry.published_parsed,entry.published_parsed,entry.published_parsed) == (now,now,now):
pub_today += 1
print("There were %d entries published today!" % pub_today)
What we’re doing is getting the value of
gmtime(), which returns a tuple with the current date and time, iterating over the
entries and comparing the relevant fields (year, month, day) to the same fields as returned by the feed.
Edit 2: I’ve used
gmtime() here in this example, which returns the current time in UTC. If you want to respect a local time offset, e.g. your local timezone is Eastern Standard, you could use
If they match, the entry was published today and so we increment the counter. If not, we don’t.
Does that make sense?
Here are the relevant docs for the stuff I’ve used.
struct_time(): https://docs.python.org/3/library/time.html#time.struct_time (this is info on the time tuple!)