forked from MLH/mlh-localhost-build-and-deploy-aws-starter
-
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.
Implement initial version of event suggestion generator
- Loading branch information
0 parents
commit 1133434
Showing
14 changed files
with
633 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 @@ | ||
EVENTBRITE_AUTH_TOKEN= |
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,213 @@ | ||
|
||
# Created by https://www.gitignore.io/api/macos,flask,python,vscode | ||
# Edit at https://www.gitignore.io/?templates=macos,flask,python,vscode | ||
|
||
### Flask ### | ||
instance/* | ||
!instance/.gitignore | ||
.webassets-cache | ||
|
||
### Flask.Python Stack ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
|
||
# C extensions | ||
|
||
# Distribution / packaging | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
|
||
# Installer logs | ||
|
||
# Unit test / coverage reports | ||
|
||
# Translations | ||
|
||
# Django stuff: | ||
|
||
# Flask stuff: | ||
|
||
# Scrapy stuff: | ||
|
||
# Sphinx documentation | ||
|
||
# PyBuilder | ||
|
||
# Jupyter Notebook | ||
|
||
# IPython | ||
|
||
# pyenv | ||
|
||
# celery beat schedule file | ||
|
||
# SageMath parsed files | ||
|
||
# Environments | ||
|
||
# Spyder project settings | ||
|
||
# Rope project settings | ||
|
||
# mkdocs documentation | ||
|
||
# mypy | ||
|
||
# Pyre type checker | ||
|
||
### Python Patch ### | ||
.venv/ | ||
|
||
#!! ERROR: vscode is undefined. Use list command to see defined gitignore types !!# | ||
|
||
# End of https://www.gitignore.io/api/macos,flask,python,vscode | ||
|
||
# Elastic Beanstalk Files | ||
.elasticbeanstalk/* | ||
!.elasticbeanstalk/*.cfg.yml | ||
!.elasticbeanstalk/*.global.yml |
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,3 @@ | ||
{ | ||
"python.pythonPath": "/usr/local/opt/python/bin/python3.7" | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Major League Hacking (MLH) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,49 @@ | ||
# Bot chat | ||
|
||
This application demonstrates the use of Markov Chains [theory](https://en.wikipedia.org/wiki/Markov_chain) by building a chat-bot based on tweets. | ||
|
||
## Requirements and dependencies | ||
|
||
- [Python3](https://www.python.org/) - We recommend using virtual environments. They will help on the creation of isolated environments so different python versions can run on the same machine. Check more about virtual environments [here](https://docs.python.org/3/library/venv.html). (Needs to be installed manually) | ||
- [Pip](https://pip.pypa.io/en/latest/installing/) - The python package manager. (Needs to be installed manually) | ||
- [Flask](http://flask.pocoo.org/) - A simple and flexible Python Web Framework that provides with tools, libraries and technologies to build a web application. (Installed by pip) | ||
|
||
## Clone the project | ||
|
||
Use the command below: | ||
|
||
```sh | ||
git clone https://github.com/MLH/localhost-python-ii.git | ||
``` | ||
|
||
## Set Up Environment variables | ||
|
||
To quickly set up environment variables, make a copy of the `.env.example` and rename it to `.env`. Then make sure to modify it following the instructions below. | ||
|
||
### EventBrite API Key | ||
|
||
We need to setup the an Eventbrite Auth token to be able to fetch data from Eventbrite's API. Follow [this guide](https://www.eventbrite.com/platform/api#/introduction/authentication) to get your key. The **Personal Tokens** section is the relevant bit. | ||
|
||
After going through the tutorial, you should have the following information: | ||
|
||
``` | ||
EVENTBRITE_AUTH_TOKEN= | ||
``` | ||
|
||
## Install dependencies | ||
|
||
The next step is to install the dependencies used by the project. Run the following command: | ||
|
||
```sh | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## Executing the application | ||
|
||
After having all the dependencies installed, you only need to execute the main application file. In this case it will be the file "main.py" | ||
|
||
``` | ||
FLASK_APP=application.py FLASK_DEBUG=1 flask run | ||
``` | ||
|
||
Then open [http://localhost:5000/](http://localhost:5000/) to see the application. |
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,21 @@ | ||
from flask import Flask, render_template, jsonify | ||
import config | ||
|
||
from eventbrite import get_events | ||
|
||
application = Flask(__name__) | ||
|
||
# Renders UI | ||
@application.route("/") | ||
def home(): | ||
return render_template("homepage.html") | ||
|
||
|
||
@application.route("/api/events/<city>") | ||
def events(city): | ||
events = get_events(city) | ||
return jsonify(events) | ||
|
||
|
||
if __name__ == "__main__": | ||
application.run() |
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,7 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
FLASK_APP_SECRET_KEY = os.getenv("FLASK_APP_SECRET_KEY") | ||
EVENTBRITE_AUTH_TOKEN= os.getenv("EVENTBRITE_AUTH_TOKEN") |
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,18 @@ | ||
import config | ||
from urllib.request import Request, urlopen | ||
from urllib.parse import quote | ||
import json | ||
|
||
|
||
def get_events(city): | ||
headers = {"Authorization": "Bearer " + config.EVENTBRITE_AUTH_TOKEN} | ||
|
||
request = Request( | ||
"https://www.eventbriteapi.com/v3/events/search/?location.address=" | ||
+ quote(city), # escape url param | ||
headers=headers, | ||
) | ||
response_body = urlopen(request).read() | ||
events = json.loads(response_body)["events"] | ||
|
||
return events |
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,22 @@ | ||
{ | ||
"install": "pip3 install --user -r requirements.txt", | ||
"start": "PYTHONUNBUFFERED=true python3 main.py FLASK_DEBUG=1 flask run", | ||
"watch": { | ||
"ignore": [ | ||
"\\.pyc$" | ||
], | ||
"install": { | ||
"include": [ | ||
"^requirements\\.txt$", | ||
"^\\.env$" | ||
] | ||
}, | ||
"restart": { | ||
"include": [ | ||
"\\.py$", | ||
"^start\\.sh" | ||
] | ||
}, | ||
"throttle": 1000 | ||
} | ||
} |
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,2 @@ | ||
Flask==1.0.2 | ||
python-dotenv==0.10.1 |
Oops, something went wrong.