-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonify.py
62 lines (43 loc) · 1.82 KB
/
jsonify.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
import numpy as np
from xlrd import open_workbook
import re
import fileinput
START_ROW = 1
START_COLUMN = 0
END_COLUMN = 3
INPUT_EXCEL = 'album_info.xls'
wb = open_workbook(INPUT_EXCEL,'UTF-8')
OUTPUT_FILE_NAME = 'album_info.json'
json_file = open(OUTPUT_FILE_NAME,'w')
def main():
i = 1
for s in wb.sheets():
print 'In Sheet: ', s.name.capitalize()
END_COLUMN = s.ncols # End Column changed here
for row in range(START_ROW,s.nrows):
json_file_contents = "\n{ \n\t \"id\" : \"" + str(i) + "\", " # Change here for index
for col in range(START_COLUMN,END_COLUMN):
cell_value = s.cell(row,col).value
title = ''
album = ''
url = ''
if (s.cell(0, col).value.encode('UTF-8') == 'title'): # Title value got here
title = s.cell(row, col).value.encode('UTF-8')
print title
if (s.cell(0, col).value.encode('UTF-8') == 'album'): # Album value got here
album = s.cell(row, col).value.encode('UTF-8')
print album
if (s.cell(0,col).value.encode('UTF-8') == 'mobile_url'): # Mobile Url got here
url = s.cell(row, col).value.encode('UTF-8')
if len(title)!=0: # Last item is last column to enter json
json_file_contents = json_file_contents + "\n\t \"title\" : \"" + title + "\"," # Title put here
if len(album)!=0:
json_file_contents = json_file_contents + "\n\t \"album\" : \"" + album + "\"\n}" # Album put here - < Last item >
if row != s.nrows-1:
json_file_contents = json_file_contents + ','
if len(url)!=0:
json_file_contents = json_file_contents + "\n\t \"url\" : \"" + url + "\"," # Mobile url put here
i = i + 1
json_file.write(json_file_contents)
if __name__ == '__main__':
main()