57 lines
2.8 KiB
Python
57 lines
2.8 KiB
Python
import requests
|
|
import pandas as pd
|
|
from neo4j import GraphDatabase
|
|
|
|
def createReporters(startMail: str):
|
|
|
|
url = 'https://graph.microsoft.com/v1.0/users/' + startMail + '/directReports'
|
|
graph_result = requests.get(url=url, headers=headers)
|
|
if graph_result.status_code == 200:
|
|
with graphDB_Driver.session() as graphDB_Session:
|
|
for i in range(len(graph_result.json()["value"])):
|
|
graphDB_Session.run("CREATE (u:USER {displayName: $displayName, id: $id, mail: $mail, title: $jobTitle, office: $officeLocation})",
|
|
id=graph_result.json()["value"][i]['id'],
|
|
displayName=graph_result.json()["value"][i]['displayName'],
|
|
mail=graph_result.json()["value"][i]['mail'],
|
|
jobTitle=graph_result.json()["value"][i]['jobTitle'],
|
|
officeLocation=graph_result.json()["value"][i]['officeLocation'])
|
|
graphDB_Session.run("MATCH (a:USER {mail: $vorgesetzter}), (b:USER {mail: $mail}) CREATE (a)-[:vorgesetzter]->(b)",
|
|
mail=graph_result.json()["value"][i]['mail'],
|
|
vorgesetzter=startMail)
|
|
createReporters(graph_result.json()["value"][i]['mail'])
|
|
|
|
if __name__ == '__main__':
|
|
# Log in to online graph explorer: https://developer.microsoft.com/en-us/graph/graph-explorer and copy the access token
|
|
# the online graph explorer has an autocompletion
|
|
access_token = 'foobar'
|
|
headers = {
|
|
'Authorization': access_token
|
|
}
|
|
|
|
# local neo4j Database
|
|
uri = "bolt://localhost:7687"
|
|
userName = "neo4j"
|
|
password = "org"
|
|
graphDB_Driver = GraphDatabase.driver(uri, auth=(userName, password))
|
|
|
|
startMail = 'Sascha.Daesler@crossnative.com'
|
|
#startMail = 'Mirko.Kuehne@crossnative.com'
|
|
url = 'https://graph.microsoft.com/v1.0/users/' + startMail
|
|
graph_result = requests.get(url=url, headers=headers)
|
|
|
|
with graphDB_Driver.session() as graphDB_Session:
|
|
graphDB_Session.run("""CREATE (u:USER {displayName: $displayName,
|
|
id: $id,
|
|
mail: $mail,
|
|
title: $jobTitle,
|
|
office: $officeLocation})""",
|
|
id=graph_result.json()['id'],
|
|
displayName=graph_result.json()['displayName'],
|
|
mail=graph_result.json()['mail'],
|
|
jobTitle=graph_result.json()['jobTitle'],
|
|
officeLocation=graph_result.json()['officeLocation'])
|
|
print(graph_result.json())
|
|
|
|
createReporters(startMail)
|
|
|