Skip to content

Instantly share code, notes, and snippets.

@MinekPo1
Last active September 8, 2022 22:23
Show Gist options
  • Save MinekPo1/be23e83603acb3857697e14d99190ce4 to your computer and use it in GitHub Desktop.
Save MinekPo1/be23e83603acb3857697e14d99190ce4 to your computer and use it in GitHub Desktop.
a python api, written in what can be a single line
[flask := __import__("flask"), yaml := __import__("yaml"), secrets := __import__("secrets"), random := __import__("random"), app := flask.Flask(__name__), "load data", file := open("hellapidata.yml"), data := yaml.safe_load(file), file.close(), update_db := lambda : [ file := open("hellapidata.yml","w"), yaml.dump(data,file), file.close() ], name := lambda func, name: type(func)(func.__code__.replace(co_name=name),globals(),name), app.route("/api/hell")( name(lambda : {"is_hell":True},"hell") ), app.route("/api/demon/get/<d_id>")( name(lambda d_id: data["demons"][d_id] if d_id in data["demons"] else 404, "demon_get" ) ), app.route("/api/demon/create/<name>")( name(lambda name: [ d_id := secrets.token_urlsafe(16), data["demons"].__setitem__(d_id, { "name": name, "age": random.randint(300,5000), }), update_db(), {"d_id":d_id}, ][-1], "demon_create" ) ) ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment