-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphScope365.py
executable file
·75 lines (63 loc) · 2.98 KB
/
GraphScope365.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
#import requests
from src.get_info import get_site_id,get_site_list,get_file,get_emails,get_onedrive
import argparse
import pandas as pd
from tqdm import tqdm
# Create an ArgumentParser object to parse command-line arguments
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Add command-line arguments for the module, access token, and filter
parser.add_argument("-m", "--module", help="outlook,onedrive,sharepoint")
parser.add_argument("-jwt", "--accessToken", help="Microsoft Graph access token")
parser.add_argument("-f", "--filter", help="Search Specific Keyword", default="")
# Parse the command-line arguments
args = parser.parse_args()
config = vars(args)
# Define column names for the different modules
columns_sharepoint = ["File Name","Size", "File type", "Shared", "URL", "Created Date Time", "Last Modified Date Time", "Created By", "Last Modified By"]
columns_outlook = ["Created Date Time" , "From", "To" , "CC", "Subject", "Body Preview", "URL", "Attachments"]
columns_onedrive = ["File Name","Size", "File type", "Created Date Time", "Last Modified Date Time", "Created By", "Last Modified By", "URL"]
# Define the headers for the HTTP request
headers = {
"Host": "graph.microsoft.com",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Referer": "https://developer.microsoft.com/",
"Sdkversion": "GraphExplorer/4.0, graph-js/3.0.2 (featureUsage=6)",
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"Authorization": "Bearer " + config["accessToken"],
"Origin": "https://developer.microsoft.com",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
}
def export_data(data_array,fields,file_name):
# Function to export data in a xlsx file
try:
df = pd.DataFrame(data_array, columns = fields)
df.to_excel(excel_writer = file_name, index=False)
print("Data exported successfully to the file:", file_name)
except Exception as e:
print("Error exporting data to the file:", file_name)
print("Error message:", str(e))
def main():
if config["module"] == "outlook":
output_emails = get_emails(headers, config["filter"])
export_data(output_emails,columns_outlook,"outolok_emails.xlsx")
elif config["module"] == "onedrive":
output_onedrive = get_onedrive(headers, config["filter"])
export_data(output_onedrive,columns_onedrive,"onedrive_files.xlsx")
elif config["module"] == "sharepoint":
list_site_id = get_site_id(headers, config["filter"])
array_site = get_site_list(list_site_id, headers)
output_files = get_file(array_site, headers)
export_data(output_files,columns_sharepoint,"sharepoint_files.xlsx")
else:
print("Command not Found")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nExiting program due to KeyboardInterrupt")