55from pathlib import Path
66from flask import Flask , render_template_string , Response
77from flask_apscheduler import APScheduler
8- from hackernewsd import HackerNewsScraper
8+ from scrapers import HackerNewsScraper , LobstersScraper
99from waitress import serve
1010import logging
1111from logging import handlers
1717scheduler = APScheduler ()
1818
1919
20- @app .route ('/feed .xml' )
21- def feed ():
22- rssPath = Path .home () / ".hackernewsdrss "
20+ @app .route ('/feed_hn_blog .xml' )
21+ def feedHnBlog ():
22+ rssPath = Path .home () / ".hackernewsdrss_hn_blog "
2323 if os .path .exists (rssPath ):
2424 with open (rssPath , "r" , encoding = "utf-8" ) as rss :
2525 return Response (rss .read (), mimetype = 'text/xml' )
@@ -37,11 +37,33 @@ def feedHn():
3737 return render_template_string ('PageNotFound {{ errorCode }}' , errorCode = '404' ), 404
3838
3939
40+ @app .route ('/feed_lobsters_blog.xml' )
41+ def feedLobstersBlog ():
42+ rssPath = Path .home () / ".hackernewsdrss_lobsters_blog"
43+ if os .path .exists (rssPath ):
44+ with open (rssPath , "r" , encoding = "utf-8" ) as rss :
45+ return Response (rss .read (), mimetype = 'text/xml' )
46+ else :
47+ return render_template_string ('PageNotFound {{ errorCode }}' , errorCode = '404' ), 404
48+
49+
50+ @app .route ('/feed_lobsters.xml' )
51+ def feedLobsters ():
52+ rssPath = Path .home () / ".hackernewsdrss_lobsters"
53+ if os .path .exists (rssPath ):
54+ with open (rssPath , "r" , encoding = "utf-8" ) as rss :
55+ return Response (rss .read (), mimetype = 'text/xml' )
56+ else :
57+ return render_template_string ('PageNotFound {{ errorCode }}' , errorCode = '404' ), 404
58+
59+
4060@scheduler .task ('interval' , id = 'scrapeJob' , seconds = 60 , max_instances = 1 )
4161def scrapeJob ():
4262 print ('Executing scraping job.' )
43- scraper = HackerNewsScraper ()
44- scraper .scrape ()
63+ hnScraper = HackerNewsScraper ()
64+ hnScraper .scrape ()
65+ lobstersScraper = LobstersScraper ()
66+ lobstersScraper .scrape ()
4567
4668
4769def readRcFile ():
0 commit comments