-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (62 loc) · 2.37 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from flask import Flask, render_template, redirect
from flask_restful import Api
from json import load, dumps
from random import randint
from threading import Thread
from api_methods.animals import AnimalsAPI
from api_methods.morse import MorseAPI
from api_methods.strange_planet import StrangePlanetAPI
from api_methods.logic.logic import LogicAPI
from api_methods.games.games import GamesAPI
from api_methods.quotes.quotes import QuotesAPI
from api_methods.secret.redirects import RedirectsAPI
from api_methods.secret.omegapsi import OmegaPsiAPI
# # # # # # # # # # # # # # # # # # # #
app = Flask("Fellow Hashbrown APIs")
api = Api(app)
# # # # # # # # # # # # # # # # # # # #
@app.route("/")
def home():
# Load the API data
with open("apis.json", "r") as api_json:
apis_json = load(api_json)
# Convert the response JSONs to a string formatted
# in json style
for api in apis_json:
for request in api["requests"]:
for response in request["responses"]:
response["response"] = dumps(
response["response"],
indent = " ").replace(
"\n", "<br>")
return render_template(
"api.html",
apis = apis_json,
page = {
"page": "api",
"title": "APIs",
"description": "if you're a developer, you've reached the available APIs that i've written and you know exactly what to do! if you're not a developer, you may not understand this but feel free to try :)"
}
), 200
@app.route("/favicon")
@app.route("/favicon.ico")
def favicon():
return redirect("/static/favicon.ico"), 302
api.add_resource(AnimalsAPI, '/animals')
api.add_resource(MorseAPI.Encode, '/morse/encode')
api.add_resource(MorseAPI.Decode, '/morse/decode')
api.add_resource(StrangePlanetAPI, '/strangePlanet')
api.add_resource(GamesAPI.GameOfLife, '/games/gameOfLife')
api.add_resource(QuotesAPI.Llamas, '/quotes/llamas')
api.add_resource(QuotesAPI.TheOffice, '/quotes/office')
api.add_resource(LogicAPI.Parse, '/logic/parse')
api.add_resource(LogicAPI.QuineMcCluskey, '/logic/qm')
api.add_resource(RedirectsAPI, '/redirects')
api.add_resource(OmegaPsiAPI, '/omegapsi')
# # # # # # # # # # # # # # # # # # # #
def run():
app.run(
host = '0.0.0.0',
port = randint(1000, 9999))
t = Thread(target = run)
t.start()