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.5 KiB
42 lines
1.5 KiB
import csv
|
|
import jwt
|
|
from django.conf import settings
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
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)
|
|
for row in fr:
|
|
email = row[0]
|
|
course_token = row[1]
|
|
period = row[2]
|
|
payload = {
|
|
'period': period,
|
|
'course_token': course_token,
|
|
'email': email.lower(),
|
|
}
|
|
token = jwt.encode(payload, settings.COURSE_PROGRESS_SECRET_KEY, algorithm='HS256').decode("utf-8")
|
|
url = "https://go.skillbox.ru/api/v1/progress/progress_token/?token=%s" % str(token)
|
|
fw.writerow([email.lower(), url])
|
|
|