Skip to content

Commit

Permalink
Add basic viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
robputt committed Dec 19, 2017
1 parent 750d0ad commit f36fc73
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions this_is_scraper/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def main():
logging.info("%s new articles added to DB." % added)
logging.info("Fetching pending articles.")
process_pending_articles(db_sess)
logging.info("Done!")


if __name__ == '__main__':
Expand Down
36 changes: 36 additions & 0 deletions this_is_scraper/templates/article_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<html>
<head>
<title>ThisIsScraper Article Viewer</title>
</head>
<body>
<h2>ThisIsScraper &middot; Article Viewer</h2>
<table style='width:100%;'>
<thead>
<tr>
<th>Article Date</th>
<th>Article Title</th>
<th>Scrape Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for article in articles %}
<tr>
<td>{{ article.article_dt.isoformat() }}</td>
<td>{{ article.article_title }}</td>
{% if article.article_status == 'complete' %}
<td bgcolor='lime'>{{ article.article_status }}</td>
{% elif article.article_status == 'pending' %}
<td bgcolor='orange'>{{ article.article_status }}</td>
{% elif article.article_status == 'failed' %}
<td bgcolor='red'>{{ article.article_status }}</td>
{% else %}
<td>{{ article.article_status }}</td>
{% endif %}
<td>{% if article.article_status == 'complete' %}<a href='/view'>View Summary</a> &middot; {% endif %}<a href='{{ article.article_link }}' target='_blank'>View Original</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
38 changes: 38 additions & 0 deletions this_is_scraper/viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from flask import Flask
from flask import g
from flask import render_template
from this_is_scraper.db import get_db_session
from this_is_scraper.db import Articles


app = Flask(__name__)


@app.before_request
def pre_req():
g.db = get_db_session()


@app.after_request
def post_req(resp):
try:
g.db.close()
except:
pass
return resp


def get_articles():
articles = g.db.query(Articles).order_by(Articles.article_dt.desc()).all()
return articles


@app.route('/')
def display_article_list():
articles = get_articles()
return render_template('article_list.html',
articles=articles)


if __name__ == "__main__":
app.run('0.0.0.0', 5000, threaded=True, debug=True)

0 comments on commit f36fc73

Please sign in to comment.