forked from vgrem/Office365-REST-Python-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_generator.py
65 lines (54 loc) · 2.23 KB
/
data_generator.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
import os
from faker import Faker
from office365.sharepoint.client_context import ClientContext
from tests import test_team_site_url, test_user_credentials
def generate_documents(context, amount):
"""
:type context: ClientContext
:type amount: int
"""
lib = context.web.lists.get_by_title("Documents_Archive")
include_files = False
fake = Faker()
for idx in range(0, amount):
# 1. Create a folder
folder_name = fake.date()
target_folder = lib.root_folder.add(folder_name)
context.execute_query()
print("({0} of {1}) Folder '{2}' has been created".format(idx, amount, target_folder.serverRelativeUrl))
if include_files:
# 2. Upload a file into a folder
path = "../../../tests/data/SharePoint User Guide.docx"
with open(path, 'rb') as content_file:
file_content = content_file.read()
name = os.path.basename(path)
target_file = target_folder.upload_file(name, file_content).execute_query()
print("File '{0}' has been uploaded".format(target_file.serverRelativeUrl))
def generate_contacts(context, amount):
"""
:type context: ClientContext
:type amount: int
"""
contacts_list = context.web.lists.get_by_title("Contacts_Large")
fake = Faker()
for idx in range(0, amount):
contact_properties = {
'Title': fake.name(),
'FullName': fake.name(),
'Email': fake.email(),
'Company': fake.company(),
'WorkPhone': fake.phone_number(),
'WorkAddress': fake.street_address(),
'WorkCity': fake.city(),
'WorkZip': fake.postcode(),
'WorkCountry': fake.country(),
'WebPage': {'Url': fake.url()}
}
# contact_item = contacts_list.add_item(contact_properties).execute_query()
contact_item = contacts_list.add_item(contact_properties)
print("({0} of {1}) Contact '{2}' has been created".format(idx, amount, contact_item.properties["Title"]))
ctx.execute_batch()
if __name__ == '__main__':
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
# generate_contacts(ctx, 5000)
generate_documents(ctx, 100)