Skip to content

Commit 44da81c

Browse files
called distinct() on the fetched Lobsters stories to avoid duplicates
1 parent 36984d7 commit 44da81c

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/dtos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ def __init__(self, _title, _url, _hacker_news_url, _last_seen, _posted_date):
88

99
def __eq__(self, other):
1010
return self.url == other.url and self.posted_date == other.posted_date
11+
def __hash__(self):
12+
return hash((self.url, self.posted_date))
1113

1214
class RateLimitException(Exception):
1315
pass

src/scrapers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def cleanup_old_stories(self):
8181
def get_old_stories(self):
8282
try:
8383
all_stories = list(Story.select().where(Story.type == StoryType.Hackernews.value))
84-
print(all_stories)
8584
return seq(all_stories).map(lambda s: self.entity_to_dto(s)).to_list()
8685
except Exception as e:
8786
return []
@@ -177,7 +176,6 @@ def cleanup_old_stories(self):
177176
def get_old_stories(self):
178177
try:
179178
all_stories = list(Story.select().where(Story.type == StoryType.Lobsters.value))
180-
print(all_stories)
181179
return seq(all_stories).map(lambda s: self.entity_to_dto(s)).to_list()
182180
except Exception as e:
183181
return []
@@ -206,7 +204,7 @@ def scrape(self):
206204
old_stories = self.get_old_stories()
207205
rc_file = self.read_rc_file()
208206
queries = json.loads(rc_file)["queries"]
209-
all_current_stories = seq.range(1, 30).flat_map(lambda p: self.process_page(p)).to_list()
207+
all_current_stories = seq.range(1, 30).flat_map(lambda p: self.process_page(p)).distinct().to_list()
210208
self.update_last_seen_dates(all_current_stories)
211209
filtered_stories = seq(all_current_stories).filter(lambda x: seq(queries).map(lambda q: x.title.lower().find(q.lower()) != -1).any()).to_list()
212210
diff_stories = seq(filtered_stories).filter(lambda x: not seq(old_stories).filter(lambda y: y == x).any()).to_list()

0 commit comments

Comments
 (0)