Project

General

Profile

Download (1.1 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / scripts / import_db.py @ 2ff5e689

1
#!/usr/bin/env python
2

    
3
import os
4
import csv
5

    
6
from datetime import datetime
7

    
8
import calebasse.settings
9
import django.core.management
10

    
11
django.core.management.setup_environ(calebasse.settings)
12

    
13
# Config
14
db_path = "/home/jschneider/dav/temp/20121015-120922"
15

    
16
dbs = ["F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD", "F_ST_ETIENNE_SESSAD_TED"]
17
tables = ["notes", "ev"]
18

    
19
def _get_dict(cols, line):
20
    """"""
21
    res = {}
22
    for i, data in enumerate(line):
23
        res[cols[i]] = data
24
    return res
25

    
26

    
27
def ev_mapper(data):
28
    """ """
29
    pass
30

    
31
def notes_mapper(data, note):
32
    """ """
33
    pass
34

    
35
mappers = {
36
        "ev": ev_mapper
37
        "notes": notes_mapper
38
        }
39

    
40
def main():
41
    """ """
42
    for db in dbs:
43
        for table in tables:
44
            csvfile = open(os.path.join(db_path, db, '%s.csv' % table), 'rb')
45
            csvlines = csv.reader(csvfile, delimiter=',', quotechar='"')
46
            cols = csvlines.next()
47
            for line in csvlines:
48
                data = _get_dict(cols, line)
49
                mappers[table](data)
50
            csvfile.close()
51

    
52

    
53
if __name__ == "__main__":
54
    main()
55

    
(2-2/2)