Skip to content

Commit e02f5d0

Browse files
committed
add naive objective import script
1 parent 422fcc6 commit e02f5d0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

scripts/import_objectives.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# coding: utf-8
3+
4+
"""
5+
Import objectives and rates from CSV format
6+
@author: Sébastien Renard ([email protected])
7+
@license: AGPL v3 or newer (http://www.gnu.org/licenses/agpl-3.0.html)
8+
"""
9+
10+
import csv
11+
from datetime import datetime
12+
import sys
13+
import os
14+
from os.path import abspath, join, pardir, dirname
15+
16+
17+
# # Setup django envt & django imports
18+
PYDICI_DIR = abspath(join(dirname(__file__), pardir))
19+
os.environ['DJANGO_SETTINGS_MODULE'] = "pydici.settings"
20+
21+
sys.path.append(PYDICI_DIR) # Add project path to python path
22+
23+
# Ensure we are in the good current working directory (pydici home)
24+
os.chdir(PYDICI_DIR)
25+
26+
# Init and model loading
27+
from django.core.wsgi import get_wsgi_application
28+
application = get_wsgi_application()
29+
30+
# Pydici imports
31+
from people.models import Consultant, RateObjective
32+
33+
objectives = csv.reader(open(sys.argv[1], "r"))
34+
35+
for line in objectives:
36+
if not line[0] or line[0]=="Consultant":
37+
continue
38+
try:
39+
c = Consultant.objects.get(trigramme=line[0])
40+
except:
41+
print(f"Warning, no consultant for {line[0]}")
42+
continue
43+
start = datetime.strptime(line[21], "%Y-%m-%d")
44+
prod_rate = float(line[10].strip("%"))
45+
daily_rate = int(line[7])
46+
RateObjective.objects.get_or_create(consultant=c, start_date=start, rate=daily_rate, rate_type="DAILY_RATE")
47+
RateObjective.objects.get_or_create(consultant=c, start_date=start, rate=prod_rate, rate_type="PROD_RATE")
48+

0 commit comments

Comments
 (0)