1
0
mirror of https://gitlab.com/2-chainz/2-chainz-rest.git synced 2025-08-03 03:51:24 +00:00

converted to azure function

This commit is contained in:
2020-03-01 15:21:22 -07:00
parent 28b2c39c4c
commit a94cdfeb44
15 changed files with 243 additions and 79 deletions

4
.funcignore Normal file
View File

@@ -0,0 +1,4 @@
.git*
.vscode
local.settings.json
test

131
.gitignore vendored
View File

@@ -1 +1,130 @@
__pycache__ # 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/
pip-wheel-metadata/
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/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that dont work, or not
# install all needed dependencies.
#Pipfile.lock
# 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/
# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json
.python_packages

6
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-python.python"
]
}

12
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python Functions",
"type": "python",
"request": "attach",
"port": 9091,
"preLaunchTask": "func: host start"
}
]
}

7
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~3",
"debug.internalConsoleOptions": "neverOpen"
}

11
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"command": "host start",
"problemMatcher": "$func-watch",
"isBackground": true
}
]
}

View File

@@ -1,3 +0,0 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
COPY ./ /app

10
chainz-rest/__init__.py Normal file
View File

@@ -0,0 +1,10 @@
import logging
import json
import azure.functions as func
import random
from . import quotes
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info("Python HTTP trigger function processed a request.")
return func.HttpResponse(json.dumps({"message": random.choice(quotes.quotes)}))

20
chainz-rest/function.json Normal file
View File

@@ -0,0 +1,20 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}

31
chainz-rest/quotes.py Normal file
View File

@@ -0,0 +1,31 @@
quotes = [
"My side chick got pregnant by her main dude and i'm offended.",
"I kiss your lady, eat her pussy, then kiss the baby.",
"Left hand on that steering wheel, right hand on that pussy!",
"For my birthday I threw me a surprise party!",
"She got a big booty so I call her big booty",
"My girl got a big purse with a purse in it, and her pussy so clean, I can go to church in it!",
"Beat the pussy up, I need riot gear.",
"Gas in a Ziplock, now thats loud and clear.",
"My wrist deserve a shout out, 'I'm like what up wrist?' / My stove deserve a shout out, 'I'm like what up stove?'",
"I'm in the kitchen. Yams errrrrwhere.",
"I encourage everyone to pay attention to the issues that matter to you, from jobs and the economy, to education and our schools, to criminal justice reform. Whatever it is that you care about, make sure you use your voice.",
"If you a chicken head, go somewhere and lay some eggs",
"Chain hang to my ding-a-ling, chain hang, chain hang to my ding-a-ling",
"I tried to get a tan but I'm black already.",
"Then I put a fat rabbit on a Craftmatic!",
"Yeah, I love them strippers",
"If I wasn't rapping I'd be trapping.",
"Started from the trap, now I rap",
"Im so high I can sing to a chandelier / My flow a glass of Ace of Spade and yours a can of beer.",
"I look you right in your face, sing to your bitch like I'm Drake!",
"Ass so big, I told her to look back at it!",
"Drunk and high at the same time. / Drinking champagne on an airplane!",
"Wood grain, chestnut / Titty fuck, chest nut",
"Horsepower, horsepower, all this Polo on, I got horsepower",
"If I die, bury me inside the Louis store",
"GI-VEN-CHY, nigga God Bless you.",
"My favorite dish is turkey lasagna / Even my pajamas designer.",
"Walked in, ill nigga alert! ill nigga alert!",
"Like fuck your baby daddy, his daddy should've worn a condom",
]

7
host.json Normal file
View File

@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}

44
main.py
View File

@@ -1,44 +0,0 @@
from fastapi import FastAPI
import json
import random
from starlette.responses import HTMLResponse
quotes = json.load(open("quotes.json"))
app = FastAPI()
@app.get("/api")
async def quote():
return {"message": random.choice(quotes)}
@app.get("/api/dump")
async def dump():
return quotes
@app.get("/", response_class=HTMLResponse)
async def index():
quote = random.choice(quotes)
return f"""
<html>
<head>
<title>{quote}</title>
</head>
<body background='https://images.unsplash.com/photo-1540206395-68808572332f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1762&q=80'>
<h1 style='font-family: Impact, Charcoal, sans-serif;
font-size: 75px;
letter-spacing: 2px;
word-spacing: 2px;
color: #FFFFFF;
position: absolute;
top: 30%;
font-weight: 400;
text-decoration: none;
font-style: normal;
font-variant: normal;
text-transform: uppercase;'>{quote.replace('/','<br/>')}</h1>
</body>
</html>
"""

4
proxies.json Normal file
View File

@@ -0,0 +1,4 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {}
}

View File

@@ -1,31 +0,0 @@
[
"My side chick got pregnant by her main dude and i'm offended.",
"I kiss your lady, eat her pussy, then kiss the baby.",
"Left hand on that steering wheel, right hand on that pussy!",
"For my birthday I threw me a surprise party!",
"She got a big booty so I call her big booty",
"My girl got a big purse with a purse in it, and her pussy so clean, I can go to church in it!",
"Beat the pussy up, I need riot gear.",
"Gas in a Ziplock, now thats loud and clear.",
"My wrist deserve a shout out, 'I'm like what up wrist?' / My stove deserve a shout out, 'I'm like what up stove?'",
"I'm in the kitchen. Yams errrrrwhere.",
"I encourage everyone to pay attention to the issues that matter to you, from jobs and the economy, to education and our schools, to criminal justice reform. Whatever it is that you care about, make sure you use your voice.",
"If you a chicken head, go somewhere and lay some eggs",
"Chain hang to my ding-a-ling, chain hang, chain hang to my ding-a-ling",
"I tried to get a tan but I'm black already.",
"Then I put a fat rabbit on a Craftmatic!",
"Yeah, I love them strippers",
"If I wasn't rapping I'd be trapping.",
"Started from the trap, now I rap",
"Im so high I can sing to a chandelier / My flow a glass of Ace of Spade and yours a can of beer.",
"I look you right in your face, sing to your bitch like I'm Drake!",
"Ass so big, I told her to look back at it!",
"Drunk and high at the same time. / Drinking champagne on an airplane!",
"Wood grain, chestnut / Titty fuck, chest nut",
"Horsepower, horsepower, all this Polo on, I got horsepower",
"If I die, bury me inside the Louis store",
"GI-VEN-CHY, nigga God Bless you.",
"My favorite dish is turkey lasagna / Even my pajamas designer.",
"Walked in, Ill nigga alert! ill nigga alert!",
"Like fuck your baby daddy, his daddy should've worn a condom"
]

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
azure-functions