def __init__(self, args): config = config_path() sqlite_file = args.sqlite_file or config.dir("DB_FILE") log_file = args.log_file or config.dir("DB_LOG") if os.path.exists(sqlite_file): open(sqlite_file, 'w').close() self.conn = sqlite3.connect(sqlite_file) self.cursor = self.conn.cursor() self.log_file = open(log_file, 'w')
import cgitb cgitb.enable() # pylint: disable=C0321 import sys import os from collections import namedtuple, OrderedDict from datetime import date, datetime, timedelta import sqlite3 from jinja2 import Environment, FileSystemLoader from foodlog.my_info import config_path SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '') ITEM = namedtuple( 'item', 'id comment carbs description servings calories fat ' 'day time protein meal size ini_id thumb_id') config = config_path() # pylint: disable=invalid-name DB_FILE = config.dir('DB_FILE') IGNORE = frozenset('template cmd jinjatemplate'.split()) VALID = set('start end range title reverse dieter'.split()) VALID_RANGES = set('today yesterday lastweek thisweek'.split()) def spacenone(value): if value is None: return "" if value == '': return "" try: return "{:.1f}".format(value).rstrip('0').rstrip('.') except (ValueError, TypeError):