import re import uuid def getUniqueID(): import uuid return str(uuid.uuid4()) def getTime(): import datetime now = str(datetime.datetime.now()) return now sampleClient ={"sheetName":"mySheet","sheetOwnerEmail":"mackaycrawford@gmil.com","columns":[["FirstName","true","owner","collaborator","largeText","medium"],["LastName","true","everyone","collaborator","text","small"]]} def buildSheet(): sheetDef = {} colDef = [] if 'sheetName' in sampleClient: sheetDef['sheetName'] = sampleClient['sheetName'] else: print "No Sheet Name" sheetDef['sheetId'] = getUniqueID() if 'sheetOwnerEmail' in sampleClient: sheetDef['sheetOwnerEmail'] = sampleClient['sheetOwnerEmail'] else: print "no User Email" sheetDef['sheetParentOrg'] = "" sheetDef['sheetOrg'] = "" sheetDef['sheetOrgTeam'] = "" sheetDef['sheetCreatedDate'] = getTime() sheetDef['sheetShared'] = "No" sheetDef['sheetSharedDate'] = "" sheetDef['sheetLocked'] = "No" sheetDef['sheetLockedDate'] = "" sheetDef['contributors'] = [] sheetDef['sharedOwners'] = [] for items in sampleClient['columns']: coldict = {} coldict["columnName"] = items[0] coldict["required"] = items[1] coldict["whoView"] = items[2] coldict["whoEdit"] = items[3] coldict["dataType"] = items[4] checkMatch = re.match("owner", items[3]) if checkMatch: coldict["hidden"] = "True" else: coldict["hidden"] = "False" #small, medium, large, verlarge checkMatch = re.match("small", items[5]) if checkMatch: coldict["colWidth"] = 90 checkMatch = re.match("medium", items[5]) if checkMatch: coldict["colWidth"] = 120 checkMatch = re.match("large", items[5]) if checkMatch: coldict["colWidth"] = 150 checkMatch = re.match("verylarge", items[5]) if checkMatch: coldict["colWidth"] = 200 colDef.append(coldict) sheetDef['columns'] = colDef return sheetDef print buildSheet()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question