Skip to content

Commit

Permalink
Restyled by yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Aug 2, 2023
1 parent a9c53b8 commit c2eb720
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
"https://clip.laavesh.co",
]


# Enable CORS
CORS(app, resources={r"/api/*": {"origins": origins}})


# Fetch the service account key JSON file contents
service_key = json.loads(os.environ["SERVICE_ACCOUNT_KEY"])
cred = credentials.Certificate(service_key)

# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(
cred, {"databaseURL": "https://clipboard-c6b51-default-rtdb.firebaseio.com/"}
)
cred,
{"databaseURL": "https://clipboard-c6b51-default-rtdb.firebaseio.com/"})


# Default route
Expand Down Expand Up @@ -88,23 +86,21 @@ def api():
ref.child(str(new_key)).set({"data": clip})
except:
return (
jsonify(
{
"msg": "Error while updating the database. Try again. Contact developer if problem persists at https://github.com/aviiciii ."
}
),
jsonify({
"msg":
"Error while updating the database. Try again. Contact developer if problem persists at https://github.com/aviiciii ."
}),
500,
)

return jsonify({"msg": "Data added to the database."}), 200

else:
return (
jsonify(
{
"msg": "Method not allowed. The '/api' route accepts only GET and POST."
}
),
jsonify({
"msg":
"Method not allowed. The '/api' route accepts only GET and POST."
}),
405,
)

Expand Down Expand Up @@ -138,11 +134,10 @@ def delete(key):
return jsonify({"msg": "Data deleted from the database."}), 200
except:
return (
jsonify(
{
"msg": "Error while deleting the data. Try again. Contact developer if problem persists at https://github.com/aviiciii ."
}
),
jsonify({
"msg":
"Error while deleting the data. Try again. Contact developer if problem persists at https://github.com/aviiciii ."
}),
500,
)

Expand All @@ -155,35 +150,32 @@ def delete(key):
@app.errorhandler(404)
def page_not_found(e):
return (
jsonify(
{
"msg": "Page not found. Try '/api' route for requests. Contact developer at https://github.com/aviiciii ."
}
),
jsonify({
"msg":
"Page not found. Try '/api' route for requests. Contact developer at https://github.com/aviiciii ."
}),
404,
)


@app.errorhandler(500)
def internal_server_error(e):
return (
jsonify(
{
"msg": "Internal server error. Raise issue at https://github.com/aviiciii/clipboard/issues ."
}
),
jsonify({
"msg":
"Internal server error. Raise issue at https://github.com/aviiciii/clipboard/issues ."
}),
500,
)


@app.errorhandler(405)
def method_not_allowed(e):
return (
jsonify(
{
"msg": "Method not allowed. The '/api' route accepts only GET and POST. The '/delete' route accepts only DELETE"
}
),
jsonify({
"msg":
"Method not allowed. The '/api' route accepts only GET and POST. The '/delete' route accepts only DELETE"
}),
405,
)

Expand Down

0 comments on commit c2eb720

Please sign in to comment.