Example #1
0
 def __init__(self, conn, options):
     self.conn = conn
     self.options = options
     columns = ['recstate', 'reckey', 'rechash', 'recjson']
     f = codecs.open('report.csv', encoding='utf-8', mode='w')
     self.writer = UnicodeDictWriter(f, columns, quoting=csv.QUOTE_MINIMAL)
     self.writer.writeheader()
Example #2
0
 class Report(object):
     def __init__(self, conn, options):
         self.conn = conn
         self.options = options
         columns = ['recstate', 'reckey', 'rechash', 'recjson']
         f = codecs.open('report.csv', encoding='utf-8', mode='w')
         self.writer = UnicodeDictWriter(f, columns, quoting=csv.QUOTE_MINIMAL)
         self.writer.writeheader()
     
     def execute(self):
         logging.info('Creating report')
         cursor = self.conn.cursor()            
         for row in cursor.execute('select reckey, rechash, recjson, recstate from cache'):
             recjson = simplejson.loads(row[2])
             json = simplejson.dumps(dict((k, v) for k,v in recjson.iteritems() if v))
             self.writer.writerow(dict(
                     reckey=row[0],
                     rechash=row[1],
                     recjson=json.encode('utf-8'),
                     recstate=row[3]))
         logging.info('Report saved to report.csv')