Skip to content

Commit b508058

Browse files
committed
Get activities implementation
1 parent ee19e53 commit b508058

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

activities.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1+
import yaml
2+
import pymongo
13
from flask import Flask
24

35
app = Flask(__name__)
6+
app.debug = True
47

8+
with open('config.yml', 'r') as f:
9+
config_file = f.read()
510

6-
@app.route("/")
7-
def hello():
8-
return "Hello World!"
11+
config = yaml.load(config_file)
12+
13+
14+
def get_collection(collection_name):
15+
mongo_config = config.get('mongo', {})
16+
client = pymongo.MongoClient(mongo_config.get('hostname'), mongo_config.get('port'))
17+
db = client[mongo_config.get('database')]
18+
return db[collection_name]
19+
20+
21+
@app.route("/activities")
22+
def get_activities():
23+
activities = get_collection('activities').find({"user_id": 12}).sort([
24+
("created_at", pymongo.DESCENDING)
25+
])
26+
27+
return "Hello World 123!"
928

1029
if __name__ == "__main__":
1130
app.run()

0 commit comments

Comments
 (0)