Skip to content

Commit

Permalink
Can now view articles
Browse files Browse the repository at this point in the history
  • Loading branch information
robputt committed Dec 19, 2017
1 parent f36fc73 commit b27cb81
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bs4
requests
sqlalchemy
pymysql
pymysql
flask
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
# Adds dependencies
install_requires = ['bs4',
'sqlalchemy',
'pymysql']
'pymysql',
'flask']
)
2 changes: 1 addition & 1 deletion this_is_scraper/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def extract_content(link):
paragraphs = div.findAll("p")
ret_text = ""
for paragraph in paragraphs:
ret_text += "%s \r\n\r\n" % paragraph.get_text().strip()
ret_text += "%s <br/><br/>" % paragraph.get_text().strip()
return title, ret_text.encode('utf-8')


Expand Down
2 changes: 1 addition & 1 deletion this_is_scraper/templates/article_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2>ThisIsScraper &middot; Article Viewer</h2>
{% 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>
<td>{% if article.article_status == 'complete' %}<a href='/view?url={{ article.article_link }}'>View Summary</a> &middot; {% endif %}<a href='{{ article.article_link }}' target='_blank'>View Original</a></td>
</tr>
{% endfor %}
</tbody>
Expand Down
12 changes: 12 additions & 0 deletions this_is_scraper/templates/view_article.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>ThisIsScraper &middot {{ article.article_title }}</title>
</head>
<body>
<h2>ThisIsScraper &middot; Article Viewer</h2>
<p><a href='/'>&lt; Back</a></p>
<h3>{{ article.article_title }}</h3>
<p>{{ article.article_dt.isoformat() }}</p>
<p>{{ article.article_content|safe }}</p>
</body>
</html>
16 changes: 16 additions & 0 deletions this_is_scraper/viewer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Flask
from flask import g
from flask import render_template
from flask import request
from this_is_scraper.db import get_db_session
from this_is_scraper.db import Articles

Expand All @@ -27,12 +28,27 @@ def get_articles():
return articles


def get_article(link):
article = g.db.query(Articles).filter(Articles.article_link == link).one()
return article


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


@app.route('/view')
def display_article():
url = request.args.get('url')
article = get_article(url)
content = article.article_content.replace('\r\n', '<br/>')
return render_template('view_article.html',
article=article,
content=content)


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

0 comments on commit b27cb81

Please sign in to comment.