forked from certsocietegenerale/FIR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_todos.py
executable file
·43 lines (31 loc) · 1.02 KB
/
script_todos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
import os
import argparse
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fir.settings")
import django
django.setup()
# your imports, e.g. Django models
from fir_todos.models import TodoItem, TodoListTemplate
def import_file(filename):
''' create a todolistemplate from a file '''
todos = []
template = TodoListTemplate(name=os.path.basename(filename).split('.')[0])
template.save()
for line in open(filename).read().split('\n'):
todos.append(create_item(line))
template.todolist = todos
template.save()
print("[*] import terminé")
def create_item(line):
''' create a todo item '''
item = TodoItem(description=line)
item.save()
return item
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('fichier', help="fichier à importer")
args = parser.parse_args()
if os.path.exists(args.fichier) and os.path.isfile(args.fichier):
import_file(args.fichier)
else:
print "le fichier n'existe pas"