4 def create_initial_portfolio(sqlite_db):
5 cursor_sql = sqlite_db.cursor()
6 cursor_sql.execute('CREATE TABLE Portfolio (symbol text, name text, '
7 'shares text, price text)')
11 def load_portfolio(sqlite_db):
13 for table in sqlite_db.execute('select * from Portfolio'):
14 portfolio.append([table[0], table[1], table[2], table[3]])
18 def insert_new_item_to_portfolio(sqlite_db, item):
19 cursor_sql = sqlite_db.cursor()
20 cursor_sql.execute('INSERT INTO Portfolio VALUES (?, ?, ?, ?)',
21 (item[0], item[1], item[2], item[3]))
26 def save_portfolio(sqlite_db, portfolio):
27 cursor_sql = sqlite_db.cursor()
29 for item in portfolio:
30 cursor_sql.execute('INSERT INTO Portfolio VALUES (?, ?, ?, ?)',
31 (item[0], item[1], item[2], item[3]))
36 def clear_portfolio(sqlite_db):
37 cursor_sql = sqlite_db.cursor()
38 sqlite_db.execute('delete from Portfolio')
42 def delete_item_from_portfolio(sqlite_db, symbol):
43 cursor_sql = sqlite_db.cursor()
44 sqlite_db.execute('delete from Portfolio where symbol="%s"' % symbol)
48 def define_paths(locally, HOME):
49 configdir = HOME + '/.stockthis/'
50 logfile = configdir + 'log.txt'
52 if not os.path.exists(configdir):
55 if os.path.exists(configdir + 'settings'):
56 settingsdb = sqlite3.connect(configdir + 'settings')
58 settingsdb = sqlite3.connect(configdir + 'settings')
59 create_initial_portfolio(settingsdb)
64 imgdir = '/usr/share/stockthis/pixmaps/'
66 return settingsdb, imgdir, configdir, logfile