def loadline(line):
    "Save a particular line to the database."
    if line[-1] == "\n":
        line = line[:-1]
    doc = parseline(line)
    print doc
    1 / 0
    db.deathfile.insert(doc)
Esempio n. 2
0
 def test_names(self):
     with self.assertRaises(ValueError):
         parseline(' 242250680TATE                    Ronnie         D              V1113200211161957                   ')
     with self.assertRaises(ValueError):
         parseline(' 242250680TATE            6       RONNIE         D              V1113200211161957                   ')
     with self.assertRaises(ValueError):
         parseline(' 242250680TATE                     RONNIE         D              V1113200211161957                   ')
    def run(self):
        num_lines = sum(1 for line in open(self.LogFile))
        f = open(self.LogFile)
        filesize = os.stat(self.LogFile).st_size
        oldfilesize = filesize

        line_nb = 1

        while not self.kill_received:
            filesize = os.stat(self.LogFile).st_size
            if filesize < oldfilesize:  # check if file has been rotated
                f.close()
                f = open(self.LogFile)
            oldfilesize = filesize
            line = f.readline()
            if line != '':
                line_nb = line_nb + 1
                parseline(line)
                time.sleep(.001)
                if line_nb < num_lines:
                    print('log at line %s of %s' % (line_nb, num_lines))
                else:
                    print('log at line %s' % line_nb)
connection = psycopg2.connect('dbname=middlenames user=tlevine')
cursor = connection.cursor(r

def schema():
    cursor.execute('CREATE TABLE IF NOT EXISTS 

def load():
    'Go throug all of the files and import everything.'
    for filepart in range(1, 4):
        def o(prefix):
            return open('deathfile/ssdm%d' % filepart, 'r')

        try:
            f = o('/tmp/') # From the ramdisk
        except IOError:
            f = o('') #From the hard disk

        for line in f:
            loadline(line)

def loadline(line):
    'Save a particular line to the database.'
    if line[-1] == '\n':
        line = line[:-1]
    doc = parseline(line)
    doc['_id'] = doc['ssn']
    db.deathfile.insert(doc)

if __name__ == '__main__':
    load()
Esempio n. 5
0
 def test_length(self):
     with self.assertRaises(ValueError):
         parseline(' 242250680TATE                    RONNIE         D              V1113200211161957                      ')
Esempio n. 6
0
 def test_padding1(self):
     with self.assertRaises(ValueError):
         parseline(' 242250680TATE                    RONNIE         D              V1113200211161957          _        ')
Esempio n. 7
0
 def test_datetimes(self):
     with self.assertRaises(ValueError):
         parseline(' 242250680TATE                    RONNIE         D              V13132002111619572                  ')
Esempio n. 8
0
 def test_parser(self):
     self.assertDictEqual(parseline(self.line), self.expected_result)