Skip to content

Commit 81f8880

Browse files
explicitly set UTF-8 encoding
1 parent 499ca54 commit 81f8880

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

README.md

182 Bytes
  1. Create a systemd service
cd /etc/systemd/system
sudo touch hackernewsd.service
sudo tee -a hackernewsd.service > /dev/null <<EOT
[Unit]
Description=hackernewsd

[Service]
WorkingDirectory=/bin
ExecStart=/bin/hackernewsd
Restart=always
# Restart service after 10 seconds if the service crashes:
RestartSec=10
User=USER_HERE
Group=USER_HERE
KillSignal=SIGINT
SyslogIdentifier=log.hackernewsd
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target
EOT

sudo sed -i -e "s/USER_HERE/$USER/g" hackernewsd.service
sudo systemctl start hackernewsd
sudo systemctl enable hackernewsd

Build from source

  1. Install the dependency list

src/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def feed():
2222
rssPath = Path.home() / ".hackernewsdrss"
2323
if os.path.exists(rssPath):
24-
with open(rssPath, "r") as rss:
24+
with open(rssPath, "r", encoding="utf-8") as rss:
2525
return Response(rss.read(), mimetype='text/xml')
2626
else:
2727
return render_template_string('PageNotFound {{ errorCode }}', errorCode='404'), 404
@@ -30,7 +30,7 @@ def feed():
3030
def feedHn():
3131
rssPath = Path.home() / ".hackernewsdrss_hn"
3232
if os.path.exists(rssPath):
33-
with open(rssPath, "r") as rss:
33+
with open(rssPath, "r", encoding="utf-8") as rss:
3434
return Response(rss.read(), mimetype='text/xml')
3535
else:
3636
return render_template_string('PageNotFound {{ errorCode }}', errorCode='404'), 404
@@ -46,7 +46,7 @@ def initLogger():
4646
logFilePath = str(Path.home() / ".hackernewsdlog")
4747

4848
if not os.path.exists(logFilePath):
49-
with open(logFilePath, "w") as logFile:
49+
with open(logFilePath, "w", encoding="utf-8") as logFile:
5050
logFile.write("")
5151

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

src/hackernewsd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def processPage(self, pageNumber):
7979

8080
def readRcFile(self):
8181
rcFilePath = Path.home() / ".hackernewsdrc"
82-
with open(rcFilePath, "r") as rcFile:
82+
with open(rcFilePath, "r", encoding="utf-8") as rcFile:
8383
return rcFile.read()
8484

8585

@@ -100,21 +100,21 @@ def generateRss(self, stories, useHackernewsUrl=False):
100100

101101
rss = fg.rss_str(pretty=True).decode('utf-8')
102102
rssFilePath = Path.home() / ".hackernewsdrss_hn" if useHackernewsUrl else Path.home() / ".hackernewsdrss"
103-
with open(rssFilePath, "w") as rssPath:
103+
with open(rssFilePath, "w", encoding="utf-8") as rssPath:
104104
rssPath.write(rss)
105105

106106

107107
def getOldStories(self):
108108
storiesDbPath = Path.home() / ".hackernewsddb"
109109
if os.path.exists(storiesDbPath):
110-
with open(storiesDbPath, "r") as dbFile:
110+
with open(storiesDbPath, "r", encoding="utf-8") as dbFile:
111111
return jsonpickle.decode(dbFile.read())
112112
else:
113113
return []
114114

115115
def writeOldStories(self, stories):
116116
storiesDbPath = Path.home() / ".hackernewsddb"
117-
with open(storiesDbPath, "w") as dbFile:
117+
with open(storiesDbPath, "w", encoding="utf-8") as dbFile:
118118
dbFile.write(jsonpickle.encode(stories))
119119

120120
def scrape(self):

0 commit comments

Comments
 (0)