Path: blob/master/ invest-robot-contest_tinvest_robot-master/examples/fetch.py
5932 views
"""This is an example on how to use the news fetcher module.1"""2from pytz import utc3import datetime45from apscheduler.schedulers.blocking import BlockingScheduler6from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore78from tinvest_robot_perevalov import news_fetcher910jobstores = {11'default': SQLAlchemyJobStore(url='sqlite:///../data/fetch-jobs.sqlite')12}1314rss_feeds = [15"https://www.investing.com/rss/news.rss",16"https://www.investing.com/rss/stock.rss"17]1819# We can use any scheduler here, but we use BlockingScheduler for simplicity.20scheduler = BlockingScheduler(jobstores=jobstores, timezone=utc)212223def main():24"""Here we fetch and analyze the news each 5 minutes.25"""26job = scheduler.add_job(news_fetcher.fetch_and_analyze, 'interval', [rss_feeds], minutes=5, next_run_time=datetime.datetime.now(tz=utc))27scheduler.start()282930if __name__ == "__main__":31main()3233