Project

General

Profile

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

calebasse / scripts / import_codes_gestion.py @ 0d4bf0b4

1
# -*- coding: utf-8 -*-
2
#!/usr/bin/env python
3

    
4
import os
5
import csv
6

    
7
from datetime import datetime, time, date
8

    
9
import calebasse.settings
10
import django.core.management
11
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
12

    
13
django.core.management.setup_environ(calebasse.settings)
14

    
15
from django.contrib.auth.models import User
16

    
17
from calebasse.ressources.models import ManagementCode
18

    
19
# Configuration
20
db = "./scripts/20121221-192258/F_ST_ETIENNE_SESSAD_TED"
21

    
22

    
23
def _to_date(str_date):
24
    if not str_date:
25
        return None
26
    return datetime.strptime(str_date[:-13], "%Y-%m-%d")
27

    
28
def _to_int(str_int):
29
    if not str_int:
30
        return None
31
    return int(str_int)
32

    
33
def main():
34
        l = []
35
        csvfile = open(os.path.join(db, 'codes_gestion.csv'), 'rb')
36
        csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
37
        cols = csvlines.next()
38
        for line in csvlines:
39
            ManagementCode(old_id=line[0], code=line[1], name=line[2].decode('utf-8')).save()
40
        csvfile.close()
41

    
42
if __name__ == "__main__":
43
    main()
(14-14/47)