-
Notifications
You must be signed in to change notification settings - Fork 2.2k
PCC16 covrebo #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
PCC16 covrebo #794
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
| # CanHazDadJoke | ||
| A single page [flask](https://flask.palletsprojects.com/en/1.1.x/) app that presents a button to press for a dad joke. A dad joke is received from the [icanhazdadjoke](https://icanhazdadjoke.com/) API as `json`. The `json` is then parsed and presented in a modal to the user. Page is styled using [Bootstrap](https://getbootstrap.com/) v5.0. A more detailed description of the project can be found [here](https://covrebo.com/retrieving-json-with-flask.html). | ||
This file contains hidden or 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,11 @@ | ||
| from flask import Flask, render_template | ||
| import services | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
|
|
||
| @app.route('/') | ||
| def hello_world(): | ||
| # get dad joke | ||
| joke = services.get_dad_joke() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice you added a service layer. |
||
| return render_template('index.html', title='Funny', joke=joke) | ||
This file contains hidden or 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,20 @@ | ||
| attrs==19.3.0 | ||
| certifi==2020.6.20 | ||
| chardet==3.0.4 | ||
| click==7.1.2 | ||
| Flask==1.1.2 | ||
| idna==2.10 | ||
| itsdangerous==1.1.0 | ||
| Jinja2==2.11.2 | ||
| MarkupSafe==1.1.1 | ||
| more-itertools==8.4.0 | ||
| packaging==20.4 | ||
| pluggy==0.13.1 | ||
| py==1.9.0 | ||
| pyparsing==2.4.7 | ||
| pytest==5.4.3 | ||
| requests==2.24.0 | ||
| six==1.15.0 | ||
| urllib3==1.25.9 | ||
| wcwidth==0.2.5 | ||
| Werkzeug==1.0.1 |
This file contains hidden or 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,11 @@ | ||
| import json | ||
| import requests | ||
|
|
||
|
|
||
| def get_dad_joke(): | ||
| url = "https://icanhazdadjoke.com/" | ||
| headers = {'User-Agent': 'My Library (https://github.com/clark_griswold)', | ||
| 'Accept': 'application/json'} | ||
| r = requests.get(url, headers=headers) | ||
| joke = json.loads(r.text) | ||
| return joke['joke'] |
This file contains hidden or 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,32 @@ | ||
| {% extends "layout.html" %} | ||
| {% block content %} | ||
| <main class="px-3"> | ||
| <div class="container mt-5"> | ||
| <!-- Button trigger modal --> | ||
| <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#dadJoke"> | ||
| Get Funny | ||
| </button> | ||
| </div> | ||
|
|
||
| <!-- Dad Joke Modal --> | ||
| <div class="modal fade" id="dadJoke" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> | ||
| <div class="modal-dialog"> | ||
| <div class="modal-content"> | ||
| <div class="modal-header"> | ||
| <h5 class="modal-title" id="dadJoke">A dad joke:</h5> | ||
| <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
| </div> | ||
| <div class="modal-body"> | ||
| {{ joke }} | ||
| </div> | ||
| <div class="modal-footer"> | ||
| <button onClick="window.location.reload();" type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> | ||
| </div> | ||
| <div class="about-modal-credit m-2"> | ||
| <span class="text-muted">Thanks <a href="https://icanhazdadjoke.com">icanhazdadjoke.com</a>.</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| {% endblock content %} |
This file contains hidden or 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,28 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <!-- Required meta tags --> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
|
||
| <!-- Bootstrap CSS --> | ||
| <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> | ||
|
|
||
| <title>Hello, world!</title> | ||
| </head> | ||
| <body class="text-center"> | ||
|
|
||
| {% block content %}{% endblock %} | ||
|
|
||
| <!-- Optional JavaScript; choose one of the two! --> | ||
|
|
||
| <!-- Option 1: Bootstrap Bundle with Popper --> | ||
| <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script> | ||
|
|
||
| <!-- Option 2: Separate Popper and Bootstrap JS --> | ||
| <!-- | ||
| <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.6.0/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script> | ||
| <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.min.js" integrity="sha384-nsg8ua9HAw1y0W1btsyWgBklPnCUAFLuTMS2G72MMONqmOymq585AcH49TLBQObG" crossorigin="anonymous"></script> | ||
| --> | ||
| </body> | ||
| </html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool idea, didn't know about that API