Skip to content

Commit

Permalink
init 11/11/2021
Browse files Browse the repository at this point in the history
  • Loading branch information
jonstod authored Nov 11, 2021
1 parent 04ad614 commit 719d289
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
51 changes: 51 additions & 0 deletions app.py
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)
1 change: 1 addition & 0 deletions countries.py
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']
25 changes: 25 additions & 0 deletions templates/country.html
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>
14 changes: 14 additions & 0 deletions templates/index.html
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>

0 comments on commit 719d289

Please sign in to comment.