You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
42 lines
1.4 KiB
import csv
|
|
from django.core.management.base import BaseCommand
|
|
from django.db import IntegrityError
|
|
|
|
from progress.models import OpenToken
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Добавляет 1 или нескольких юзеров в указанные группы'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--from',
|
|
type=str,
|
|
dest='from',
|
|
help='Файл подгрузки данных'
|
|
)
|
|
parser.add_argument(
|
|
'--to',
|
|
type=str,
|
|
dest='to',
|
|
help='Файл выгрузки'
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
from_path = options['from']
|
|
to_path = options['to']
|
|
with open(from_path) as f:
|
|
with open(to_path, 'w') as out_f:
|
|
fw = csv.writer(out_f)
|
|
fr = csv.reader(f, delimiter=';')
|
|
for row in fr:
|
|
try:
|
|
token = OpenToken.objects.create(
|
|
email=row[0].lower(),
|
|
course_token=row[1],
|
|
period_days=row[2],
|
|
)
|
|
url = "https://go.skillbox.ru/api/v1/progress/progress_token/?token=%s" % str(token.token)
|
|
fw.writerow([token.email.lower(), url])
|
|
except IntegrityError:
|
|
pass
|
|
|