-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from flask import Flask, render_template | ||
from flask_cors import CORS | ||
from countries import countries | ||
import requests | ||
import json | ||
from bs4 import BeautifulSoup | ||
|
||
# Configuration | ||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
|
||
# Routes | ||
@app.route("/") | ||
def home(): | ||
return render_template("index.html", countries=countries) | ||
|
||
@app.route("/<country>") | ||
def country(country): | ||
# Wikipedia scraper microservice implementation | ||
r1 = requests.get('http://flip3.engr.oregonstate.edu:6231/?article=%s' %country) | ||
info_dict = json.loads(r1.content) | ||
wiki_info = info_dict['info'] | ||
|
||
r2 = requests.get('http://flip3.engr.oregonstate.edu:6231/?article=%s&country_data=y' %country) | ||
data_dict = json.loads(r2.content) | ||
currency = data_dict['currency'] | ||
|
||
# Subreddit scraper microservice implementation | ||
r3 = requests.get('http://flip3.engr.oregonstate.edu:6069/sub?subreddit=%s' %country) | ||
soup = BeautifulSoup(r3.text, 'html.parser') | ||
|
||
reddit_table = soup.find('table', class_ = 'dataframe') | ||
posts = {} | ||
|
||
for post in reddit_table.find_all('tbody'): | ||
rows = post.find_all('tr') | ||
for row in rows: | ||
posts[row.find('td').text.strip()] = row.find_all('td')[1].text.strip() | ||
|
||
titles = posts.keys() | ||
content = posts.values() | ||
|
||
# Currency converter microservice implementation | ||
|
||
|
||
return render_template("country.html", country=country, wiki=wiki_info, posts=posts, currency=currency) | ||
|
||
# Listener | ||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=6207, debug=True) |
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 @@ | ||
countries = ['Albania', 'Andorra', 'Armenia', 'Austria', 'Azerbaijan', 'Belarus', 'Belgium', 'Bosnia and Herzegovina', 'Bulgaria', 'Croatia', 'Cyprus', 'Czech Republic', 'Denmark', 'Estonia', 'Finland', 'France', 'Georgia', 'Germany', 'Greece', 'Hungary', 'Iceland', 'Ireland', 'Italy', 'Kazakhstan', 'Latvia', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Malta', 'Moldova', 'Monaco', 'Montenegro', 'Netherlands', 'North Macedonia', 'Norway', 'Poland', 'Portugal', 'Romania', 'Russia', 'San Marino', 'Serbia', 'Slovakia', 'Slovenia', 'Spain', 'Sweden', 'Switzerland', 'Turkey', 'Ukraine', 'United Kingdom', 'Vatican City'] |
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,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{country}}</title> | ||
</head> | ||
<body> | ||
<h1>{{country}}</h1> | ||
|
||
<h3>About {{country}}:</h3> | ||
<ul><li>{{wiki}}</li></ul> | ||
|
||
<h3>All-time top posts in r/{{country}}:</h3> | ||
<ul> | ||
{% for key, val in posts.items() %} | ||
<li><a href="{{val}}">{{key}}</a></li> | ||
{% endfor %} | ||
</ul> | ||
|
||
<h3>Currency conversion:</h3> | ||
<ul> | ||
<li>National currency: {{currency}}</li> | ||
<li>USD conversion feature coming soon!</li> | ||
</ul> | ||
</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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>European Travel Guide - Home</title> | ||
</head> | ||
<body> | ||
<h1>European Travel Guide</h1> | ||
<h3>Select a country to learn more:</h3> | ||
{% for x in countries %} | ||
<p><a href="/{{x}}">{{x}}</a></p> | ||
{% endfor %} | ||
<img src="https://cdn.britannica.com/67/367-050-0F839196/Europe.jpg" alt="britannica.com"> | ||
</body> | ||
</html> |