Skip to content

Commit 414a53e

Browse files
parametrized port and host
1 parent 81f8880 commit 414a53e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

README.md

156 Bytes
  1. Create in your home folder (C:\Users\YOUR_USERNAME) a file called ".hackernewsdrc".
    Replace the queries in the example below with whatever keywords you want the daemon to look for
{
	"queries": [ ".NET", "C#", "Microsoft", "CLR", "F#", "Mono" ],
	"host": "127.0.0.1",
	"port": 5555
	"queries": [ ".NET", "C#", "Microsoft", "CLR", "F#", "Mono" ]
}
  1. Clone the project
  2. Install the dependencies

Install - Linux

  1. Create in your home folder (/home/YOUR_USERNAME) a file called ".hackernewsdrc".
    Replace the queries in the example below with whatever keywords you want the daemon to look for
{
	"queries": [ ".NET", "C#", "Microsoft", "CLR", "F#", "Mono" ],
	"host": "127.0.0.1",
	"port": 5555
	"queries": [ ".NET", "C#", "Microsoft", "CLR", "F#", "Mono" ]
}
  1. Download the binary

src/app.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#TODO parameterize port (int)
2-
#TODO parameterize notify (bool)
1+
2+
# TODO parameterize notify (bool)
3+
import json
34
import os
45
import sys
56
from pathlib import Path
@@ -26,6 +27,7 @@ def feed():
2627
else:
2728
return render_template_string('PageNotFound {{ errorCode }}', errorCode='404'), 404
2829

30+
2931
@app.route('/feed_hn.xml')
3032
def feedHn():
3133
rssPath = Path.home() / ".hackernewsdrss_hn"
@@ -42,6 +44,13 @@ def scrapeJob():
4244
scraper = HackerNewsScraper()
4345
scraper.scrape()
4446

47+
48+
def readRcFile():
49+
rcFilePath = Path.home() / ".hackernewsdrc"
50+
with open(rcFilePath, "r", encoding="utf-8") as rcFile:
51+
return rcFile.read()
52+
53+
4554
def initLogger():
4655
logFilePath = str(Path.home() / ".hackernewsdlog")
4756

@@ -51,8 +60,6 @@ def initLogger():
5160

5261
log_formatter = logging.Formatter('[%(asctime)s %(levelname)s] %(message)s', "%Y-%m-%d %H:%M:%S")
5362

54-
55-
5663
fileHandler = RotatingFileHandler(logFilePath, mode='a', maxBytes=25 * 1024 * 1024,
5764
backupCount=1, encoding=None, delay=0)
5865
fileHandler.setFormatter(log_formatter)
@@ -68,9 +75,11 @@ def initLogger():
6875
rootLogger.addHandler(fileHandler)
6976
rootLogger.addHandler(consoleHandler)
7077

78+
7179
if __name__ == '__main__':
7280
initLogger()
81+
rcFile = json.loads(readRcFile())
7382
scheduler.init_app(app)
7483
scheduler.start()
75-
serve(app, host="127.0.0.1", port=5555)
76-
#app.run(port=5555)
84+
serve(app, host=rcFile["host"], port=rcFile["port"])
85+
# app.run(port=5555)

0 commit comments

Comments
 (0)