Source code for noboraw2sqlite
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Created on Mon May 25 21:11:26 2015
"""Select with a simple GUI inteface the NOBO sqlite database and select a
directory with raw NOBO-csv-data files only(!). The NOBO-files will be fed
into the data base. Please observe console output.
Yes: INSERT new and IGNORE existing records
No: INSERT new and REPLACE existing records."""
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
import sys
import os.path as op
import Tkinter as tk
import tkFileDialog as tkfd
import tkMessageBox as tkmb
try:
import nobotouls.noboinout as inout
except ImportError:
import noboinout as inout
PROGN = op.basename(sys.argv[0])
DESCRIBEPROG = __doc__
[docs]def main():
"""Main"""
root = tk.Tk()
root.withdraw()
inout.version()
ync = tkmb.askyesnocancel(title=PROGN, message=DESCRIBEPROG)
if not (ync is None):
dbfile = tkfd.askopenfilename(title="Select nobo sqlite-database")
if not dbfile:
print('No DB-FIle selected', file=sys.stderr)
print('Exit!', file=sys.stderr)
sys.exit()
print("SQLite-DB: ", dbfile)
nobodir = tkfd.askdirectory(title="Directory with raw nobo files")
if not nobodir:
sys.exit()
print("Directory with raw NOBO file: ", nobodir)
filelist = inout.all_nobo_raw_files(nobodir, pattern='*.txt')
for fn in filelist:
print("Insert ", fn)
try:
station, headers, data = inout.read_nobo_file(fn)
if ync is True:
inout.insert_ignore_aichfeld_db(dbfile, data)
else:
inout.insert_replace_aichfeld_db(dbfile, data)
except IOError as e:
tkmb.showerror(title=PROGN,
message='Some silly error!\n' +
'Maybe wrong file or dir?\n' + dbfile + "\n" +
nobodir + str(e))
sys.exit(e)
tkmb.showinfo(title=PROGN, message='Finished')
if __name__ == '__main__':
inout.version()
sys.exit(main())