-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmp_api.py
executable file
·174 lines (125 loc) · 4.33 KB
/
xmp_api.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from libxmp import XMPFiles
'''
____ _____ _ _____ ___ ____ ____
/ ___|_ _|/ \|_ _|_ _/ ___/ ___|
\___ \ | | / _ \ | | | | | \___ \
___) || |/ ___ \| | | | |___ ___) |
|____/ |_/_/ \_\_| |___\____|____/
'''
#static variables
INSPO_URI = "https://www.claytondunavant.com/inspo" #insponizer URI
#all possible articles of clothing
ARTICLES = ["id", "url", "author","instagram","hat","glasses","jacket", "top", "undershirt", "one piece", "bag","watch","jewelry","belt","bottom","socks","shoes"]
'''
____ _____ _ ____
| _ \| ____| / \ | _ \
| |_) | _| / _ \ | | | |
| _ <| |___ / ___ \| |_| |
|_| \_\_____/_/ \_\____/
'''
#check to see if inspo xmp data exists
def check_inspo_xmp(file):
#get xmp from file
xmpfile = XMPFiles(file_path=file, open_forupdate=True)
xmp = xmpfile.get_xmp()
#check to see
if xmp.does_property_exist(INSPO_URI, 'id') == True:
xmpfile.close_file()
return True
else:
xmpfile.close_file()
return False
#return inspo xmp from f ile as dict
def inspo_xmp_to_dict(file):
out = {}
# get xmp from file
xmpfile = XMPFiles(file_path=file, open_forupdate=True)
xmp = xmpfile.get_xmp()
for article in ARTICLES:
if xmp.does_property_exist(INSPO_URI, article):
out[article] = xmp.get_property(INSPO_URI, article)
return out
'''
__ ______ ___ _____ _____
\ \ / / _ \|_ _|_ _| ____|
\ \ /\ / /| |_) || | | | | _|
\ V V / | _ < | | | | | |___
\_/\_/ |_| \_\___| |_| |_____|
'''
#check to see if xmp can be written
def check_xmp_writable(file):
# get xmp from file
xmpfile = XMPFiles(file_path=file, open_forupdate=True)
xmp = xmpfile.get_xmp()
try:
#if you can write new xmp
if xmpfile.can_put_xmp(xmp) == True:
xmpfile.close_file()
return True
else:
xmpfile.close_file()
return False
except Exception as e:
print("Error: " + str(e))
#write INSPO data from dictonary
def dictonary_write(file, dict):
# get xmp from file
xmpfile = XMPFiles(file_path=file, open_forupdate=True)
xmp = xmpfile.get_xmp()
if check_xmp_writable(file) == True: #if xmp can be written to file
if check_inspo_xmp(file) == False: #if INSPO xmp does not exist
# register or update INSPO namespace URI
xmp.register_namespace(INSPO_URI, "INSPO")
# for each possible article
for article in ARTICLES:
try:
value = dict[article]
xmp.set_property(INSPO_URI, article, value)
except:
pass
xmpfile.put_xmp(xmp)
xmpfile.close_file()
return
else:
xmpfile.close_file()
print("INSPO DATA ALREADY EXISTS")
return
else:
xmpfile.close_file()
print("XMP NOT WRITEABLE")
return
#manually write INSPO data in terminal
def terminal_write(file):
# get xmp from file
xmpfile = XMPFiles(file_path=file, open_forupdate=True)
xmp = xmpfile.get_xmp()
if check_xmp_writable(file) == True: #if xmp can be written to file
if check_inspo_xmp(file) == False: #if INSPO xmp does not exist
# register or update INSPO namespace URI
xmp.register_namespace(INSPO_URI, "INSPO")
# for each possible article
for article in ARTICLES:
value = input("What " + article + " are they wearing?: ") # ask if they are wearing a certain article of clothing
if value == "": # if the value is empty then pass
pass
else: # else set that article of clothing
xmp.set_property(INSPO_URI, article, value)
xmpfile.put_xmp(xmp)
xmpfile.close_file()
else:
xmpfile.close_file()
print("INSPO DATA ALREADY EXISTS")
return
else:
xmpfile.close_file()
print("XMP NOT WRITEABLE")
return
'''
____ _____ _ _ _____ ____ _ _
/ ___| ____| \ | | ____| _ \ / \ | |
| | _| _| | \| | _| | |_) | / _ \ | |
| |_| | |___| |\ | |___| _ < / ___ \| |___
\____|_____|_| \_|_____|_| \_\/_/ \_\_____|
'''
def get_ARTICLES():
return ARTICLES