Created
December 9, 2017 04:13
-
-
Save mroswell/970fe23e5f80862f89b800fc26d0491f to your computer and use it in GitHub Desktop.
ind.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xlrd | |
import sys | |
import uuid | |
from lxml import etree as ET | |
def _gen_group_indices(book, sheet_index): | |
""" | |
Create data structure to store lists of row indices keyed by _parent_index. | |
Sample dict: | |
{3.0: [2, 3], 2.0: [1], u'_parent_index': [0], 4.0: [4, 5], 5.0: [6]} | |
""" | |
colnames = book.sheet_by_index(sheet_index).row_values(0) | |
print "########## -", colnames, "########" | |
g_parent_table_name_column_index = colnames.index("_parent_table_name") | |
g_parent_index_col_index = colnames.index("_parent_index") | |
# _parent_table_name_col_index = _get_col_index(1, headers, '_parent_table_name') | |
group_indices = {} | |
group_sheet = book.sheet_by_index(sheet_index) | |
for i, v in enumerate(group_sheet.col_values(g_parent_index_col_index)): | |
if v in group_indices: | |
group_indices[v].append(i) | |
else: | |
group_indices[v] = [i] | |
# print group_indices | |
return group_indices | |
# def _gen_group_index_list(book): | |
""" | |
Create list of dicts store lists of row indices keyed by _parent_index, keyed by sheetname | |
Sample dict: | |
{{3.0: [2, 3], 2.0: [1], u'_parent_index': [0], 4.0: [4, 5], 5.0: [6]}} | |
""" | |
book = xlrd.open_workbook('xls-to-xml-nrepeats.xlsx') | |
group_index_list = [] | |
groups_indices = {} | |
for s_i, sheetname in enumerate(book.sheet_names()): | |
if s_i == 0: | |
print group_index_list, "o" | |
pass | |
else: | |
print "-----------------",s_i, 's_i' | |
groups_indices[sheetname] = _gen_group_indices(book, s_i) | |
group_index_list.append(groups_indices) | |
# print groups_indices, "lalalalalallalalalala" | |
# print " line 184 !!!!!!!!!!o!!!!!!!!!!!", group_indices | |
# group_indices = _gen_group_indices(book, sheet_i) | |
# print "*%*%*%*%*%*%*%*%*" "*%*%*%*%*%*%*%*%*", [x_i for x_i, count in group_sheet_indices.iteritems()] | |
# for k, v in group_indices.iteritems(): | |
# print "*%*%*%*%*%*%*%*%*", "bbb", k,"-----", v | |
print "lineeeeee 57", group_index_list, '&*&*&*&*&*&*&*' | |
# print "LLLLLLLLine 58", group_indices | |
# [{u'group_cooking': {3.0: [2, 3], 2.0: [1], u'_parent_index': [0], 4.0: [4, 5], 5.0: [6]}, u'pets': {3.0: [2], 2.0: [1], u'_parent_index': [0], 4.0: [3, 4, 5]}}, {u'group_cooking': {3.0: [2, 3], 2.0: [1], u'_parent_index': [0], 4.0: [4, 5], 5.0: [6]}, u'pets': {3.0: [2], 2.0: [1], u'_parent_index': [0], 4.0: [3, 4, 5]}}, {u'group_cooking': {3.0: [2, 3], 2.0: [1], u'_parent_index': [0], 4.0: [4, 5], 5.0: [6]}, u'pets': {3.0: [2], 2.0: [1], u'_parent_index': [0], 4.0: [3, 4, 5]}}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment