Skip to content

Instantly share code, notes, and snippets.

@robstenzinger
Created January 29, 2016 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robstenzinger/cb5c1e5a7d5c31b43fc0 to your computer and use it in GitHub Desktop.
Save robstenzinger/cb5c1e5a7d5c31b43fc0 to your computer and use it in GitHub Desktop.
Based on an Experience Inventory excel file where you've captured data, this script will export reports in excel
from xls2db import xls2db
import xlrd
import sqlite3 as sqlite
import xlsxwriter
import os
#
# SOURCE DATA
#
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
inventory_file_name = "experience-inventory-2015.xlsx"
db = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
db.row_factory = dict_factory
xls2db(xlrd.open_workbook(inventory_file_name), db)
# save as a sqlite db...
os.remove(inventory_file_name + ".db")
xls2db(inventory_file_name, inventory_file_name + ".db")
cursor = db.cursor()
#
# OUTPUT REPORTS
#
def save_report(query, fileName):
cursor.execute(query)
results = cursor.fetchall()
workbook = xlsxwriter.Workbook(fileName)
worksheet = workbook.add_worksheet()
data = []
for row in results:
data.append(row)
keycount = 0
for item in data[0].keys():
worksheet.write(0, keycount, item)
keycount += 1
row_count = 0
for row in data:
# print(row)
if row_count > 0:
column_count = 0
for key,value in row.items():
worksheet.write(row_count, column_count, value)
column_count += 1
row_count += 1
workbook.close()
#
# RUN THESE REPORTS
#
# -- *********** life system -> list of experiences + reactions for day job
sql_main_gig = "select [What month?], [What did you do or experience?], [What was others reaction to it? ] from [experience-inventory] where [Life system purpose? Personal, Professional, main gig, side gig, friends, family, finance, learning] = 'main gig' group by [What month?], [Life system purpose? Personal, Professional, main gig, side gig, friends, family, finance, learning], [What did you do or experience?], [What was others reaction to it? ]"
file_main_gig = "main_gig.xlsx"
save_report(sql_main_gig, file_main_gig)
# -- *********** THE BEST STUFF REPORT: FEELING, REACTION, EFFORT
sql_best = "select [What did you do or experience?], [What was others reaction to it? ], [Life system purpose? Personal, Professional, main gig, side gig, friends, family, finance, learning], [How do you feel about the EXPERIENCE overall?], [How much reaction was there overall?], [How do you feel about the EFFORT?], [How much EFFORT did it take to produce or participate in this experience?] from [experience-inventory] where [How do you feel about the EXPERIENCE overall?] > 3 and [How much reaction was there overall?] > 2 and [How do you feel about the EFFORT?] > 1 order by [How much EFFORT did it take to produce or participate in this experience?] asc"
file_best = "best.xlsx"
save_report(sql_best, file_best)
# -- *********** THE WORST STUFF REPORT: FEELING, REACTION, EFFORT
sql_worst = "select [What did you do or experience?], [What was others reaction to it? ], [Life system purpose? Personal, Professional, main gig, side gig, friends, family, finance, learning], [How do you feel about the EXPERIENCE overall?], [How much reaction was there overall?], [How do you feel about the EFFORT?], [How much EFFORT did it take to produce or participate in this experience?] from [experience-inventory] where [How do you feel about the EXPERIENCE overall?] < 3 and [How do you feel about the EFFORT?] < 4 order by [How much EFFORT did it take to produce or participate in this experience?] asc"
file_worst = "worst.xlsx"
save_report(sql_worst, file_worst)
# -- *********** THE MEH STUFF REPORT: FEELING, REACTION, EFFORT
sql_meh = "select [What did you do or experience?], [What was others reaction to it? ], [Life system purpose? Personal, Professional, main gig, side gig, friends, family, finance, learning], [How do you feel about the EXPERIENCE overall?], [How much reaction was there overall?], [How do you feel about the EFFORT?], [How much EFFORT did it take to produce or participate in this experience?] from [experience-inventory] where [How do you feel about the EXPERIENCE overall?] = 3 and [How do you feel about the EFFORT?] < 4 order by [How much EFFORT did it take to produce or participate in this experience?] asc"
file_meh = "meh.xlsx"
save_report(sql_meh, file_meh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment