-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
43 lines (33 loc) · 1 KB
/
app.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
import os
from flask import Flask
from flask_restful import Resource, Api
from flask_pymongo import PyMongo
from flask_restful import reqparse
app = Flask(__name__)
app.config["MONGO_URI"] = (
os.environ.get("MONGO_URI", "mongodb://localhost:27017")
) + "/spider"
mongo = PyMongo(app)
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument("id", type=str)
parser.add_argument("ts1")
parser.add_argument("ts2")
class Pools(Resource):
def get(self):
powers = mongo.db.pools.find({}, {"_id": 0})
return list(powers)
class Snapshot(Resource):
def get(self):
args = parser.parse_args()
_id = args["id"]
ts1 = int(args["ts1"])
ts2 = int(args["ts2"])
snapshots = mongo.db.snapshot.find(
{"id": _id, "update_time": {"$gte": ts1, "$lt": ts2}}, {"_id": 0}
)
return list(snapshots)
api.add_resource(Pools, "/")
api.add_resource(Snapshot, "/snapshot")
if __name__ == "__main__":
app.run(debug=False, host="0.0.0.0")