Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_tinvest_robot-master/examples/fetch.py
5932 views
1
"""This is an example on how to use the news fetcher module.
2
"""
3
from pytz import utc
4
import datetime
5
6
from apscheduler.schedulers.blocking import BlockingScheduler
7
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
8
9
from tinvest_robot_perevalov import news_fetcher
10
11
jobstores = {
12
'default': SQLAlchemyJobStore(url='sqlite:///../data/fetch-jobs.sqlite')
13
}
14
15
rss_feeds = [
16
"https://www.investing.com/rss/news.rss",
17
"https://www.investing.com/rss/stock.rss"
18
]
19
20
# We can use any scheduler here, but we use BlockingScheduler for simplicity.
21
scheduler = BlockingScheduler(jobstores=jobstores, timezone=utc)
22
23
24
def main():
25
"""Here we fetch and analyze the news each 5 minutes.
26
"""
27
job = scheduler.add_job(news_fetcher.fetch_and_analyze, 'interval', [rss_feeds], minutes=5, next_run_time=datetime.datetime.now(tz=utc))
28
scheduler.start()
29
30
31
if __name__ == "__main__":
32
main()
33