From 2ba1a804b909711e1625561c34c1bf0d65c7fea5 Mon Sep 17 00:00:00 2001 From: trin Date: Thu, 20 Jun 2024 13:41:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=82=20@igoose1=20=D0=BA=D1=80=D0=BE=D0=BC=D0=B5=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8,=20=D0=B4=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BC=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BE=D0=BE?= =?UTF-8?q?=D0=B1=D1=89=D0=B5=D1=81=D1=82=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authn/management/commands/import_posts_to_dev.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/authn/management/commands/import_posts_to_dev.py b/authn/management/commands/import_posts_to_dev.py index 83d30087b..f99ba81ec 100644 --- a/authn/management/commands/import_posts_to_dev.py +++ b/authn/management/commands/import_posts_to_dev.py @@ -49,12 +49,12 @@ def handle(self, *args, **options): url = "https://vas3k.club/feed.json?page={}".format(x + 1) self.stdout.write("📁 {}".format(url)) req = urllib.request.Request(url) - req.add_header('User-Agent', 'Mozilla/5.0') + req.add_header('User-Agent', 'posts-to-dev') response = urllib.request.urlopen(req) data = json.load(response) for item in data['items']: # приватные нафиг - if not (item['_club']['is_public']): + if not item['_club']['is_public']: continue author, created = create_user(item['authors'][0]) @@ -111,8 +111,7 @@ def handle(self, *args, **options): def create_user(author): - split = author['url'].split('/') - slug = split[-2] + *_, slug, _ = author['url'].split('/') defaults = dict( slug=slug, @@ -124,13 +123,11 @@ def create_user(author): balance=10000, created_at=datetime.utcnow(), updated_at=datetime.utcnow(), - membership_started_at=datetime.now(), + membership_started_at=datetime.utcnow(), membership_expires_at=datetime.utcnow() + timedelta(days=365 * 100), is_email_verified=True, moderation_status=User.MODERATION_STATUS_APPROVED, roles=[], ) - user, created = User.objects.get_or_create(slug=slug, defaults=defaults) - - return user, created + return User.objects.get_or_create(slug=slug, defaults=defaults)