forked from bengolder/py-adobe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyDataMerge.py
46 lines (37 loc) · 1.19 KB
/
MyDataMerge.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
import os
import xlrd
import xlwt
class Merge(object):
def __init__(self, xls=None, folder=None, objects=None):
self.xls = xls
self.folder = folder
self.objects = self._getObjs()
def _getObjs(self):
if self.xls:
objects = self.xlsToObjs()
else:
objects = []
return objects
def xlsToObjs(self, path=None):
if path:
self.xls = path
sht = xlrd.open_workbook(self.xls).sheet_by_index(0)
col_names = [c.value for c in sht.row(0)]
objs = []
for n in range(sht.nrows - 1):
vals = [c.value for c in sht.row(n+1)]
objs.append(dict(zip(col_names, vals)))
return objs
def readXLS(self, path=None):
self.objects = self.xlsToObjs(path)
if __name__=='__main__':
f = '/Users/benjamingolder/Portfolio Resources/Projects/ARCH 299X/species-webmap-merge.xls'
folder = '/Users/benjamingolder/Portfolio Resources/Projects/ARCH 299X/SpeciesPowerPointGroupSlides Folder/Links'
m = Merge()
m.xls = f
m.folder = folder
m.readXLS()
#things = os.listdir(folder)
#print '\n'.join(things)
for o in m.objects:
print o