Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ethancedwards8/ethancedwards-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ethancedwards8 committed Jul 16, 2023
2 parents ca34cc1 + f2f1fc8 commit ff1a246
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 45 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Docker Image CI

on:
push:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Public to Registry
uses: elgohr/Publish-Docker-Github-Action@v4
with:
name: ethancedwards8/ethancedwards-api
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:alpine

COPY . /app
RUN pip install flask flask-restful
ENTRYPOINT ["python", "/app/ethancedwards_quotes.py"]
RUN pip3 install flask flask-restful
ENTRYPOINT ["python3", "/app/src/ethancedwards_api.py"]
27 changes: 3 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,11 @@
with open("README.md") as readme_file:
README = readme_file.read()

# setup_args = dict(
# name="ethancedwards-quotes",
# version="1.0",
# description="A cool api that gives you my favorite quotes :)",
# author="Ethan Edwards",
# author_email="ethan@ethancedwards.com",
# long_description=README,
# long_description_content_type="text/markdown",
# license="GPLv3",
# packages=find_packages(),
# url="https://github.com/ethancedwards8/api-quotes",
# entry_points={
# 'console_scripts': ['ethancedwards-quotes = ethancedwards-quotes:run']
# }
# )

# install_requires = [ "flask", "flask-restful" ]

# if __name__ == "__main__":
# setup(**setup_args, install_requires=install_requires)

setup(
name='ethancedwards_quotes',
name='ethancedwards_api',
version='0.1',
py_modules=['ethancedwards_quotes'],
py_modules=['ethancedwards_api'],
entry_points={
'console_scripts': ['ethancedwards_quotes = ethancedwards_quotes:run']
'console_scripts': ['ethancedwards_api = ethancedwards_api:run']
},
)
23 changes: 23 additions & 0 deletions src/ethancedwards_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3


# Flask imports
from flask import Flask
from flask_restful import Api, Resource, reqparse

# vanilla imports
import os

# imports for different modules
from quotes.quotes import *

app = Flask(__name__)
api = Api(app)
DEV = os.environ.get('DEV')

# resources being added
api.add_resource(Quote, "/quotes/v1", "/quotes/v1/", "/quotes/v1/<int:id>/")
api.add_resource(Dump, "/quotes/v1/dump", "/quotes/v1/dump/")

if __name__ == '__main__':
app.run(host='0.0.0.0', port=(8000 if DEV else 80))
Binary file added src/quotes/__pycache__/quotes.cpython-311.pyc
Binary file not shown.
7 changes: 6 additions & 1 deletion quotes.json → src/quotes/quotes.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@
{
"id": 14,
"author": "Henry Ford",
"quote": "Whether you think you can or think you can't you're right"
"quote": "Whether you think you can or think you can't you're right."
},
{
"id": 15,
"author": "Will Durant",
"quote": "We are what we repeatedly do. Excellence, then, is not an act, but a habit."
},
{
"id": 16,
"author": "Victor Fontanez",
"quote": "The grass isn't greener on the other side, the grass is greener where you water it at."
}
]
19 changes: 1 addition & 18 deletions ethancedwards_quotes.py → src/quotes/quotes.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
#!/usr/bin/env python3

from flask import Flask
from flask_restful import Api, Resource, reqparse

import random
import os
import json

app = Flask(__name__)
api = Api(app)

DEV = os.environ.get('DEV')

with open('quotes.json') as f:
with open(os.path.dirname(os.path.realpath(__file__)) + '/quotes.json') as f:
quotes = json.load(f)

print(quotes)

class Quote(Resource):
def get(self, id=0):
if id == 0:
Expand All @@ -28,14 +19,6 @@ def get(self, id=0):

return "quote not found", 404


class Dump(Resource):
def get(self):
return quotes, 200


api.add_resource(Quote, "/quotes/v1", "/quotes/v1/", "/quotes/v1/<int:id>/")
api.add_resource(Dump, "/quotes/v1/dump", "/quotes/v1/dump/")

if __name__ == '__main__':
app.run(host='0.0.0.0', port=(8000 if DEV else 80))

0 comments on commit ff1a246

Please sign in to comment.