import azure.cosmos.cosmos_client as cosmos_client
import json
config = {
    'ENDPOINT': 'https://pes.documents.azure.com:443/',
    'PRIMARYKEY': 'AtZKUUeFCbpfaJpfVgLuua4hwlccrx8jTrenMwixuDQpbt9QVbKuZcWBiVG64vOw3OfUYwJAlrTgSzQIgxOBuQ==',
    'DATABASE': 'pes'
}

# Initialize the Cosmos client
client = cosmos_client.CosmosClient(url_connection=config['ENDPOINT'], auth={
                                    'masterKey': config['PRIMARYKEY']})

students=client.ReadContainer('dbs/pes/colls/students')['_self']
teachers=client.ReadContainer('dbs/pes/colls/teachers')['_self']
tc=client.ReadContainer('dbs/pes/colls/tc')['_self']
assignments=client.ReadContainer('dbs/pes/colls/assignments')['_self']
student_tc=client.ReadContainer('dbs/pes/colls/student_tc')['_self']
courses=client.ReadContainer('dbs/pes/colls/courses')['_self']

items = json.load(open('data/students.json'))
for i in items:
	client.CreateItem(students,i)
items = json.load(open('data/teachers.json'))
for i in items:
	client.CreateItem(teachers,i)
items = json.load(open('data/tc.json'))
for i in items:
	client.CreateItem(tc,i)
items = json.load(open('data/assignments.json'))
for i in items:
	client.CreateItem(assignments,i)
items = json.load(open('data/student_tc.json'))
for i in items:
	client.CreateItem(student_tc,i)
items = json.load(open('data/courses.json'))
for i in items:
	client.CreateItem(courses,i)



result_iterable = client.QueryItems(	students,
					'SELECT s.name FROM server s', 
					{'enableCrossPartitionQuery':True}
				   )
for item in iter(result_iterable):
    print(item['name'])
