Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVP dashboard #9

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _extract(element):
logger.info('Extracting titles and urls...')
headlines_df = pd.DataFrame(list(map(_extract, elements)))
res = headlines_df.dropna().drop_duplicates()
logger.info(f"Scraped {len(res)} from NYTimes.com.")
logger.info(f"Scraped {len(res)} from NY Times.")
return res


Expand Down Expand Up @@ -136,7 +136,7 @@ def _extract(element):
logger.info('Extracting titles and urls...')
headlines_df = pd.DataFrame(list(map(_extract, elements)))
res = headlines_df.dropna().drop_duplicates()
logger.info(f'Scraped {len(res)} from NYTimes.com.')
logger.info(f'Scraped {len(res)} from Washington Post.')
return res


Expand Down Expand Up @@ -168,12 +168,11 @@ def main():
headlines.to_csv(os.path.join(args.dir, args.file).format(NOW),
index=False, encoding='utf-8')
else:
db_url = os.environ['DATABASE_URL']
db_url = os.environ['HEROKU_POSTGRESQL_CHARCOAL_URL']
engine = create_engine(db_url)
current = pd.read_sql_query('SELECT * FROM headlines;', engine)
mask = ~(headlines['headline'].isin(current['headline']) | ~(
headlines['url'].isin(current['url'])))
toappend = headlines.loc[mask]
in_current = headlines['headline'].isin(current['headline'])
toappend = headlines.loc[~in_current]
if len(current) == 0:
toappend = headlines
toappend['timestamp'] = NOW
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ psycopg2
requests
bs4
lxml
dash
dash-renderer
dash-html-components
dash-core-components
plotly
networkx==2.1
Loading