-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
59 lines (48 loc) · 1.69 KB
/
parser.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
import os
import csv
from pixel import Pixel
def main():
create_csv('flip')
return 0
def create_csv(path):
i = 0
fields = ['n', 'grey', 'avgColor(hex)', 'filePath']
with open('photos.csv', 'w') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
for root, dirs, files in os.walk(path):
for filename in files:
row = []
newPixel = Pixel(path+'/'+filename, 5, None, None)
i+=1
row.append(i)
row.append(newPixel.GreyPool)
row.append(newPixel.avgColor)
row.append(newPixel.path)
csvwriter.writerow(row)
class Parser:
pixelDict = {}
csv = None
def __init__(self, csvFile):
self.csv = csvFile
def create_pixel_list(self, multiple):
self.pixelDict['d'] = []
self.pixelDict['dl'] = []
self.pixelDict['ld'] = []
self.pixelDict['l'] = []
with open(self.csv, 'r') as csvFile:
reader = csv.DictReader(csvFile)
for row in reader:
dictRow = dict(row)
newPixel = Pixel(dictRow['filePath'], multiple, dictRow['avgColor(hex)'], dictRow['grey'])
if dictRow['grey'] == 'd':
self.pixelDict['d'].append(newPixel)
elif dictRow['grey'] == 'dl':
self.pixelDict['dl'].append(newPixel)
elif dictRow['grey'] == 'ld':
self.pixelDict['ld'].append(newPixel)
else:
self.pixelDict['l'].append(newPixel)
return self.pixelDict
if __name__ == "__main__":
main()