-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheadline.py
More file actions
45 lines (34 loc) · 1.16 KB
/
headline.py
File metadata and controls
45 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from datetime import datetime
class Headline:
"""Represents a headline from Hacker News (ycombinator.com)."""
def __init__(self, data):
self._title = data['title']
self._link = data['link']
self._score = int(data['score'])
self._author = data['author']
self._date = datetime.fromisoformat(data['date'])
def __str__(self):
return f"Title: {self._title} | Link: {self._link} | {self._score} Points\nAuthor: {self._author} | Date: {self._date}\n"
def to_dict(self):
return {
'title': self._title,
'link': self._link,
'score': self._score,
'author': self._author,
'date': self._date.isoformat()
}
def get_title(self):
return self._title
def get_link(self):
return self._link
def get_score(self):
return self._score
def get_author(self):
return self._author
def get_date(self):
return self._date
def match_keywords(self, keywords):
for k in keywords:
if k.lower() in self._title.lower():
return True
return False