CyberPunkMetalHead / Binance-News-Sentiment-Bot

This is a fully functioning Binance trading bot that takes into account the news sentiment for the top 100 crypto feeds. If you like this project consider donating though the Brave browser to allow me to continuously improve the script.
MIT License
1.57k stars 290 forks source link

Exclude articles after defined time has past #24

Closed adteague closed 3 years ago

adteague commented 3 years ago

Here's how I implemented it: Add timezone to datetime import

# define how old an article can be to be included
# in hours
HOURS_PAST = 24
# convert pubDat to datetime
published = datetime.strptime(pubDate.replace("GMT", "+0000"), '%a, %d %b %Y %H:%M:%S %z')
# calculate timedelta
time_between = datetime.now(timezone.utc) - published

if (time_between.total_seconds() / (60 * 60) <= HOURS_PAST):

Add ^ before the following... https://github.com/CyberPunkMetalHead/Binance-News-Sentiment-Bot/blob/56da3d171a77d2b6a574ba63cbae0887eaa3b2e8/news-analysis.py#L224-L230

adteague commented 3 years ago

I implemented this because I noticed an article from May 2020 was being included in the sentiment analysis 😄 Thanks for the great code to build off of!

CyberPunkMetalHead commented 3 years ago

This is a good idea, thanks for pointing that out! Feel free to create a pull request for the latest commit.

CyberPunkMetalHead commented 3 years ago

This has now been merged to main in the last commit!