-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_models.py
31 lines (26 loc) · 923 Bytes
/
cache_models.py
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
import time
class CachedData:
def __init__(self, cached_arr):
self.topic = cached_arr[0]
self.parsed_articles = cached_arr[1]
self.sentiments = cached_arr[2]
self.times_queried = cached_arr[3]
self.time_at_query = cached_arr[4]
def contains_topic(self, topic):
found_in_desc = False
for _, parsed_arr in self.parsed_articles.items():
if (parsed_arr[1] and topic in parsed_arr[1]) or (
parsed_arr[2] and topic in parsed_arr[2]
):
found_in_desc = True
return self.topic == topic or found_in_desc
def is_fresh(self):
return (time.time() - self.time_at_query) / (24 * 60 * 60) < 1
def to_list(self):
return [
self.topic,
self.parsed_articles,
self.sentiments,
self.times_queried,
self.time_at_query,
]