-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-main.py
executable file
·24 lines (21 loc) · 1001 Bytes
/
11-main.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
#!/usr/bin/env python3
""" 11-main """
from pymongo import MongoClient
list_all = __import__('8-all').list_all
insert_school = __import__('9-insert_school').insert_school
schools_by_topic = __import__('11-schools_by_topic').schools_by_topic
if __name__ == "__main__":
client = MongoClient('mongodb://127.0.0.1:27017')
school_collection = client.my_db.school
j_schools = [
{ 'name': "Holberton school", 'topics': ["Algo", "C", "Python", "React"]},
{ 'name': "UCSF", 'topics': ["Algo", "MongoDB"]},
{ 'name': "UCLA", 'topics': ["C", "Python"]},
{ 'name': "UCSD", 'topics': ["Cassandra"]},
{ 'name': "Stanford", 'topics': ["C", "React", "Javascript"]}
]
for j_school in j_schools:
insert_school(school_collection, **j_school)
schools = schools_by_topic(school_collection, "Python")
for school in schools:
print("[{}] {} {}".format(school.get('_id'), school.get('name'), school.get('topics', "")))