From c7b96ab835baca369c754b22a7715f24fd7da7ea Mon Sep 17 00:00:00 2001 From: geekwriter2 Date: Sun, 3 Jan 2021 17:38:24 -0800 Subject: [PATCH 1/6] init commit --- .idea/.gitignore | 3 + .idea/inspectionProfiles/Project_Default.xml | 56 +++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 7 +++ .idea/modules.xml | 8 +++ .idea/ustjay-ethay-actsfayig.iml | 11 ++++ .idea/vcs.xml | 6 ++ main.py | 34 ++++++++--- requirements.bak | 12 ++++ static/css/styles.css | 23 ++++++++ templates/base.jinja2 | 15 +++++ templates/pig_latin_translator.jinja2 | 5 ++ 12 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/ustjay-ethay-actsfayig.iml create mode 100644 .idea/vcs.xml create mode 100644 requirements.bak create mode 100644 static/css/styles.css create mode 100644 templates/base.jinja2 create mode 100644 templates/pig_latin_translator.jinja2 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c513edf --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,56 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..66d986f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e7c7e7b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/ustjay-ethay-actsfayig.iml b/.idea/ustjay-ethay-actsfayig.iml new file mode 100644 index 0000000..8dc09e5 --- /dev/null +++ b/.idea/ustjay-ethay-actsfayig.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.py b/main.py index bc096fb..fc1b18b 100644 --- a/main.py +++ b/main.py @@ -1,28 +1,46 @@ -import os +"""a simple app to serve up pig latin""" +import os import requests -from flask import Flask, send_file, Response +from flask import Flask, send_file, Response, render_template from bs4 import BeautifulSoup app = Flask(__name__) - +FACT_URL = 'http://unkno.com' +PIG_LATINIZER_URL = 'http://hidden-journey-62459.herokuapp.com/piglatinize' def get_fact(): + """ get the pig latin """ - response = requests.get("http://unkno.com") - + response = requests.get(FACT_URL) soup = BeautifulSoup(response.content, "html.parser") facts = soup.find_all("div", id="content") + pig_latin_prhase = facts[0].getText().strip() - return facts[0].getText() + return pig_latin_prhase @app.route('/') def home(): - return "FILL ME!" + """main functionality""" + + my_fact = get_fact() + fact_dict = {'input_text': my_fact} + print(fact_dict) + pig_latin_response = requests.post(PIG_LATINIZER_URL, + allow_redirects=False, + data=fact_dict) + print(pig_latin_response.headers) + pig_latin_location = pig_latin_response.headers['Location'] + print('test_' + pig_latin_location) + pig_latin_url = f'{pig_latin_location}' + return render_template('pig_latin_translator.jinja2', pig_latin=pig_latin_url) + + if __name__ == "__main__": port = int(os.environ.get("PORT", 6787)) - app.run(host='0.0.0.0', port=port) + # app.run(host='0.0.0.0', port=port) # heroku + app.run(host='localhost', port=port) # local diff --git a/requirements.bak b/requirements.bak new file mode 100644 index 0000000..c4fd48f --- /dev/null +++ b/requirements.bak @@ -0,0 +1,12 @@ +beautifulsoup4==4.6.0 +certifi==2018.4.16 +chardet==3.0.4 +click==6.7 +Flask==1.0.1 +idna==2.6 +itsdangerous==0.24 +Jinja2==2.10 +MarkupSafe==1.1.1 +requests==2.18.4 +urllib3==1.22 +Werkzeug==0.14.1 diff --git a/static/css/styles.css b/static/css/styles.css new file mode 100644 index 0000000..75438c3 --- /dev/null +++ b/static/css/styles.css @@ -0,0 +1,23 @@ +body { + font-family: "Calibri", "Helvetica", "sans-serif"; +} +h1 { + font-size: 1.313em; +} + +h2 { + font-size: 0.9167em; + +p { + font-size: 0.9167em; +} +input { + font-size: 0.9167em; +} +input { + font-size: 0.9167em; +} +} +a:link { + text-decoration: none; +} \ No newline at end of file diff --git a/templates/base.jinja2 b/templates/base.jinja2 new file mode 100644 index 0000000..5cbd54b --- /dev/null +++ b/templates/base.jinja2 @@ -0,0 +1,15 @@ + + +Random Facts in Pig Latin + + + + + +

Pig Latin

+

{% block subtitle %} {% endblock subtitle %}

+ {% block content %} {% endblock content %} + + diff --git a/templates/pig_latin_translator.jinja2 b/templates/pig_latin_translator.jinja2 new file mode 100644 index 0000000..df82c69 --- /dev/null +++ b/templates/pig_latin_translator.jinja2 @@ -0,0 +1,5 @@ +{% extends 'base.jinja2' %} +{% block subtitle %}translated:{% endblock subtitle %} +{% block content %} +

{{pig_latin}}

+{% endblock content %} \ No newline at end of file From ca9ca29949a1ad6600b697d154e5356d288b5472 Mon Sep 17 00:00:00 2001 From: geekwriter2 Date: Sun, 3 Jan 2021 17:49:20 -0800 Subject: [PATCH 2/6] init commit --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 629b83a..0c123b8 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: python main.py +web: python main.py runserver 0.0.0.0:6738 From d8930a46aef7db05369174743f6baa5eeb316552 Mon Sep 17 00:00:00 2001 From: geekwriter2 Date: Sun, 3 Jan 2021 17:53:22 -0800 Subject: [PATCH 3/6] init commit --- Procfile | 2 +- main.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Procfile b/Procfile index 0c123b8..acec4de 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: python main.py runserver 0.0.0.0:6738 +web: python main.py runserver 0.0.0.0:6787 diff --git a/main.py b/main.py index fc1b18b..e80b5a4 100644 --- a/main.py +++ b/main.py @@ -41,6 +41,6 @@ def home(): if __name__ == "__main__": port = int(os.environ.get("PORT", 6787)) - # app.run(host='0.0.0.0', port=port) # heroku - app.run(host='localhost', port=port) # local + app.run(host='0.0.0.0', port=port) # heroku + #app.run(host='localhost', port=port) # local From dd361388102f2e8d07e70915e5c7b6a7c16e2d2d Mon Sep 17 00:00:00 2001 From: geekwriter2 Date: Mon, 4 Jan 2021 08:26:07 -0800 Subject: [PATCH 4/6] init commit --- main.py | 18 +++++++++--------- templates/base.jinja2 | 6 +++--- templates/pig_latin_translator.jinja2 | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index e80b5a4..e974ef6 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,8 @@ app = Flask(__name__) FACT_URL = 'http://unkno.com' -PIG_LATINIZER_URL = 'http://hidden-journey-62459.herokuapp.com/piglatinize' +PIG_LATINIZER_URL = 'https://hidden-journey-62459.herokuapp.com/piglatinize/' + def get_fact(): """ get the pig latin """ @@ -16,7 +17,6 @@ def get_fact(): soup = BeautifulSoup(response.content, "html.parser") facts = soup.find_all("div", id="content") pig_latin_prhase = facts[0].getText().strip() - return pig_latin_prhase @@ -27,20 +27,20 @@ def home(): my_fact = get_fact() fact_dict = {'input_text': my_fact} print(fact_dict) + pig_latin_response = requests.post(PIG_LATINIZER_URL, allow_redirects=False, data=fact_dict) print(pig_latin_response.headers) pig_latin_location = pig_latin_response.headers['Location'] print('test_' + pig_latin_location) - pig_latin_url = f'{pig_latin_location}' - return render_template('pig_latin_translator.jinja2', pig_latin=pig_latin_url) - - + content = f""" +
+ {my_fact}
""" + return render_template('pig_latin_translator.jinja2', body=content) if __name__ == "__main__": port = int(os.environ.get("PORT", 6787)) - app.run(host='0.0.0.0', port=port) # heroku - #app.run(host='localhost', port=port) # local - + #app.run(host='0.0.0.0', port=port) # heroku + app.run(host='localhost', port=port) # local diff --git a/templates/base.jinja2 b/templates/base.jinja2 index 5cbd54b..d12de96 100644 --- a/templates/base.jinja2 +++ b/templates/base.jinja2 @@ -4,11 +4,11 @@ - + -

Pig Latin

+

Pig Latin Translator

{% block subtitle %} {% endblock subtitle %}

{% block content %} {% endblock content %} diff --git a/templates/pig_latin_translator.jinja2 b/templates/pig_latin_translator.jinja2 index df82c69..cf2c0c7 100644 --- a/templates/pig_latin_translator.jinja2 +++ b/templates/pig_latin_translator.jinja2 @@ -1,5 +1,5 @@ {% extends 'base.jinja2' %} -{% block subtitle %}translated:{% endblock subtitle %} +{% block subtitle %}Click to view the translated fact:{% endblock subtitle %} {% block content %} -

{{pig_latin}}

+

{{body}}

{% endblock content %} \ No newline at end of file From cd16348f59424bf8be0b6253bd8af8b46645adfd Mon Sep 17 00:00:00 2001 From: geekwriter2 Date: Mon, 4 Jan 2021 08:28:12 -0800 Subject: [PATCH 5/6] init commit --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index e974ef6..577826e 100644 --- a/main.py +++ b/main.py @@ -42,5 +42,5 @@ def home(): if __name__ == "__main__": port = int(os.environ.get("PORT", 6787)) - #app.run(host='0.0.0.0', port=port) # heroku - app.run(host='localhost', port=port) # local + app.run(host='0.0.0.0', port=port) # heroku + #app.run(host='localhost', port=port) # local From c5d1f214d6200020bc58467892ac1b316d6d8db3 Mon Sep 17 00:00:00 2001 From: geekwriter2 Date: Mon, 4 Jan 2021 08:42:46 -0800 Subject: [PATCH 6/6] lesson 5 commit --- main.py | 4 ++-- templates/base.jinja2 | 7 +++---- templates/pig_latin_translator.jinja2 | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 577826e..7f68b3c 100644 --- a/main.py +++ b/main.py @@ -35,8 +35,8 @@ def home(): pig_latin_location = pig_latin_response.headers['Location'] print('test_' + pig_latin_location) content = f""" - """ +
{my_fact}
+

Translate: {pig_latin_location}

""" return render_template('pig_latin_translator.jinja2', body=content) diff --git a/templates/base.jinja2 b/templates/base.jinja2 index d12de96..4777d14 100644 --- a/templates/base.jinja2 +++ b/templates/base.jinja2 @@ -5,11 +5,10 @@ -

Pig Latin Translator

-

{% block subtitle %} {% endblock subtitle %}

{% block content %} {% endblock content %} + diff --git a/templates/pig_latin_translator.jinja2 b/templates/pig_latin_translator.jinja2 index cf2c0c7..fa2f371 100644 --- a/templates/pig_latin_translator.jinja2 +++ b/templates/pig_latin_translator.jinja2 @@ -1,5 +1,4 @@ {% extends 'base.jinja2' %} -{% block subtitle %}Click to view the translated fact:{% endblock subtitle %} {% block content %}

{{body}}

{% endblock content %} \ No newline at end of file