-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (23 loc) · 697 Bytes
/
main.py
File metadata and controls
30 lines (23 loc) · 697 Bytes
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
from flask import Flask, jsonify,request
from flask_cors import CORS
import json
import pymongo
import urllib
app = Flask(__name__)
CORS(app)
client = pymongo.MongoClient("mongodb+srv://instacluster:<password>@instacluster.iapeyji.mongodb.net/?retryWrites=true&w=majority")
db = client.insta
collection = db.gif
@app.route("/")
def hello_world():
cursor = collection.find({}, {"_id": 0})
documents = []
for document in cursor:
documents.append(document["data"])
return jsonify(documents)
@app.route("/add")
def add():
gif = urllib.parse.unquote(request.args.get("gif"))
collection.insert_one({"data": {"link": gif}})
return "success"
app.run(debug=True)