-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 · 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> · {% endif %}<a href='{{ article.article_link }}' target='_blank'>View Original</a></td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |