import glob
import os
import csv
import dataserv
import statistics
import sqlite3
from datetime import date
import time
import cmd, sys

class dataservShell(cmd.Cmd):
    '''user interface to do everything in a few steps. PyQt suggested for GUI.
    1: user puts in csv files
    2: this class creates DB using dataserv.LocalDB
    3: creates reports for each: ATV, CLV, LTS and CLS
    4: runs Output.stats_getall()
    5: notifies user when finished
    '''
    def importer(dbname, csvarray):
        ''' csvarray should be string including .csv extension in local folder '''
        for csvfile in csvarray:
            importer = dataserv.LocalDB()
            tbldata = importer.get_csv(csvfile)

            tblname = csvfile.split('.')[0]  # replace this with func to return tblname based on what user says the file is
            new_headerrow = tbldata[0]
            remove_duplicates(new_headerrow)
            tbldata[0] = new_headerrow

            importer.sendto_sqlite(tbldata, tblname, db=dbname)

    def remove_duplicates(headerrow):
        ''' Infusionsoft csv files often have duplicate strings as header row.
        When importing to sql, this raises sqlite3.OperationalError. Pass in the
        first row of your csv file to fix this. importer() calls this for you as well.
        '''
        for item in headerrow:  #  this is horrible but works for now
            if headerrow.count(item) > 1:
                idx = headerrow.index(item)
                for col in range(idx + 1, len(headerrow)):
                    if headerrow[col] == item:
                        headerrow[col] = '_' + headerrow[col]

                print(item, ':', headerrow.count(item))

    def make_tablename():
        '''choose your file. include the .csv extension'''  # use input() for this?
        '''LocalDB.get_csv(chosen_file)'''
        '''tablename is contacts, sales, products as chosen by user'''
        '''return filename, tablename'''

    def test_make_tablename():
        '''this belongs in testfile when done'''
        '''choose file'''
        '''check file exists'''
        '''assert filetype is chosen'''
        '''assert filetype is (sales|contacts|products)'''

# this is straigh out of the docs for cmd module:
def parse(arg):
    'Convert a series of zero or more numbers to an argument tuple'
    return tuple(map(int, arg.split()))

''' DO THIS to run dataservShell:
if __name__ == '__main__':
    dataservShell().cmdloop()
'''
def histogram():
    '''
    using bokeh to visualise:
    >>> from bokeh.plotting import figure, output_file, show
    >>> output_file('histogram.html')
    >>> p = figure(title = 'insert title')
    >>> x = datescount.keys()
    >>> y = datescount.values()
    >>> p.line(x,y)
    >>> show(p)
    '''

    dates = eval(open('dates.txt', 'r+').read())
    from collections import Counter
    datescount = Counter(dates)

    return datescount

def sourcelist(cxn):
    testlist = [cxn.dates(), cxn.tags(), cxn.leadsources()]

    return testlist

def filelinecount(filename):
    if type(filename) != str:
        filename = str(filename)

    with open(filename) as file:
        for i, l in enumerate(file):
            pass

        return i + 1

def linecount():
    numlines = []
    for file in list(os.walk('.'))[0][2]:
        if file.endswith('py'):
            try:
                numlines.append(filelinecount(file))
            except: pass

    return sum(numlines)


if __name__ == "__main__":
    x = linecount()
    print(x)

@@ -117,352 +117,10 @@
 ime%0A
-import cmd, sys%0A%0Aclass dataservShell(cmd.Cmd):%0A    '''user interface to do everything in a few steps. PyQt suggested for GUI.%0A    1: user puts in csv files%0A    2: this class creates DB using dataserv.LocalDB%0A    3: creates reports for each: ATV, CLV, LTS and CLS%0A    4: runs Output.stats_getall()%0A    5: notifies user when finished%0A    '''%0A    
+%0A%0A
 def 
@@ -147,20 +147,16 @@
 array):%0A
-    
     ''' 
@@ -222,28 +222,24 @@
  folder '''%0A
-    
     for csvf
@@ -255,36 +255,32 @@
 varray:%0A        
-   
- 
 importer = datas
@@ -293,20 +293,16 @@
 calDB()%0A
-    
         
@@ -338,20 +338,16 @@
 vfile)%0A%0A
-    
         
@@ -466,20 +466,16 @@
         
-    
 new_head
@@ -501,20 +501,16 @@
         
-  
-  
 remove_d
@@ -538,28 +538,24 @@
 ow)%0A        
-    
 tbldata%5B0%5D =
@@ -574,28 +574,24 @@
 ow%0A%0A        
-  
-  
 importer.sen
@@ -631,20 +631,16 @@
 bname)%0A%0A
-    
 def remo
@@ -669,20 +669,16 @@
 w):%0A    
- 
-   
 ''' Infu
@@ -744,20 +744,16 @@
 ow.%0A    
- 
-   
 When imp
@@ -821,20 +821,16 @@
 the%0A    
- 
-   
 first ro
@@ -904,20 +904,16 @@
 ll.%0A
-    
     '''%0A
     
@@ -904,28 +904,24 @@
 ll.%0A    '''%0A
-    
     for item
@@ -974,36 +974,32 @@
 for now%0A        
-   
- 
 if headerrow.cou
@@ -1024,20 +1024,16 @@
         
-    
 idx = he
@@ -1060,28 +1060,24 @@
             
-  
-  
 for col in r
@@ -1119,28 +1119,24 @@
             
-    
 if headerrow
@@ -1170,20 +1170,16 @@
         
-  
-  
 headerro
@@ -1209,20 +1209,16 @@
 w%5Bcol%5D%0A%0A
-    
         
@@ -1262,20 +1262,16 @@
 item))%0A%0A
-    
 def make
@@ -1280,28 +1280,24 @@
 ablename():%0A
-    
     '''choos
@@ -1364,20 +1364,16 @@
 r this?%0A
-    
     '''L
@@ -1403,28 +1403,24 @@
 ile)'''%0A    
-   
- 
 '''tablename
@@ -1466,28 +1466,24 @@
  by user'''%0A
-    
     '''retur
@@ -1508,20 +1508,16 @@
 ame'''%0A%0A
-    
 def test
@@ -1535,20 +1535,16 @@
 name():%0A
-    
     '''t
@@ -1580,28 +1580,24 @@
 done'''%0A    
-  
-  
 '''choose fi
@@ -1598,28 +1598,24 @@
 ose file'''%0A
-    
     '''check
@@ -1626,36 +1626,32 @@
 e exists'''%0A    
- 
-   
 '''assert filety
@@ -1666,20 +1666,16 @@
 osen'''%0A
-    
     '''a
@@ -1901,103 +1901,8 @@
 ))%0A%0A
-''' DO THIS to run dataservShell:%0Aif __name__ == '__main__':%0A    dataservShell().cmdloop()%0A'''%0A
 def 

remove class definition for dataservShell, keep parse() function