Skip to content

Commit

Permalink
bypass printing when save=true
Browse files Browse the repository at this point in the history
  • Loading branch information
akherlan committed Dec 3, 2022
1 parent 5a6364f commit 5bdf4af
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions snips.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def scrape(session, tag=None, category='recent', save=False):
csv_writer = csv.writer(fout)
csv_writer.writerows(data)
print(f"Data saved to {save_path}")
else:
for row in newsletter[1:]:
# [published] headline <url>
print('[{}] {} <{}>'.format(row[0], row[1], row[4]))
return
except Exception as e:
print(f'ERROR: {e}')
Expand All @@ -69,17 +73,13 @@ def parse(soup):
else:
newsletter = []
for item in articles:
# parse items
h1 = item.find('h1').find('a', href=True)
headline = unicodedata.normalize('NFKD', h1.get_text())
url = baseurl + h1['href']
published = item.find('time', {'class':'published'})['datetime']
published_dt = datetime.strptime(published, '%Y-%m-%d')
description = item.find('p').get_text()
tags = ', '.join([i.get_text() for i in item.find_all('a', {'rel':'tag'})])
# expose newsletter
print('[{}] {} <{}>'.format(published, headline, url))
# save newsletter list
newsletter.append([published, headline, description, tags, url])
return newsletter

Expand Down

0 comments on commit 5bdf4af

Please sign in to comment.