-
Notifications
You must be signed in to change notification settings - Fork 0
/
plistmaker.py
72 lines (42 loc) · 2.13 KB
/
plistmaker.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
sheet = 'Sheet 2'
plist_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
import pandas as pd
def make_plist(file=str):
file_name = file
image_name_numpy = pd.read_excel(io=file_name, usecols=[0], skiprows=1).to_numpy()
id_numpy = pd.read_excel(io=file_name, usecols=[1], skiprows=1).to_numpy()
model_name_numpy = pd.read_excel(io=file_name, usecols=[2], skiprows=1).to_numpy()
"\n<plist version=\"1.0\">"
dict = "\n</dict>"
key = "<key>"
"\n</plist>"
def key_wrapper(key, space):
return "\n{}<key>".format(space) + key + "</key>"
def string_wrapper(string, space):
return "\n{}<string>".format(space) + string + "</string>"
def dict_wrapper(keys_vals, space):
return "{}<dict>".format(space) + keys_vals + "\n</dict>"
def key_val_wrapper(key, key_name, val, val_name, space, back):
return "\n{}<{}>".format(space, key_name) + key + "</{}>".format(key_name) + "\n" + "{}<{}>".format(space,
val_name) + val + "{}</{}>".format(
back, val_name)
def plist_wrapper(dict):
return plist_header + "\n<plist version=\"1.0\">\n{}\n</plist>".format(dict)
def make_dict(keyObject, valObject):
i = 0
dict = ""
while i < len(image_name_numpy):
key = keyObject[i][0]
val = valObject[i][0]
val.replace('&', '&')
dict += key_val_wrapper(key, "key", val, "string", " ", "")
i += 1
return dict
inner_dict = key_val_wrapper("Models-ID", "key", make_dict(image_name_numpy, id_numpy), "dict", " ", "\n ")
inner_dict2 = key_val_wrapper("Models-Names", "key", make_dict(image_name_numpy, model_name_numpy), "dict", " ",
"\n ")
main_dict = dict_wrapper(inner_dict + inner_dict2, "")
pre_final = plist_wrapper(main_dict)
final = pre_final.replace("&", "&")
print("Done!")
return final