def load_authors():
    users_mapping = load_users_mapping()

    for user_api in users_data_stream('users'):
        mapped_user = users_mapping[str(user_api['id'])]
        if not mapped_user['duplicate'] and not mapped_user['delete']:
            mapped_user_title = '{0} {1}'.format(mapped_user['first_name'],
                                                 mapped_user['last_name'])
            mapped_user_slug = slugify(mapped_user_title)
            print("id is: ")
            print(user_api['id'])
            db_user = Person.objects.filter(slug=mapped_user_slug).first()

            role_info = get_role_info(user_api['roles'])
            if not db_user and mapped_user_slug:
                db_user = Person(
                    search_description='',
                    seo_title='',
                    show_in_menus=False,
                    slug=mapped_user_slug,
                    title=mapped_user_title,
                    first_name=mapped_user['first_name'],
                    last_name=mapped_user['last_name'],
                    position_at_new_america=user_api['title'],
                    role=role_info['role_title'],
                    email=user_api['email'],
                    expert=role_info['expert'],
                    depth=4,
                    profile_image=download_image(
                        user_api['image'],
                        mapped_user_slug + "_person_image.jpeg"),
                    short_bio=user_api['short_bio'],
                    long_bio=user_api['long_bio'],
                )
                our_people_page.add_child(instance=db_user)
                db_user.save()
                print("New user")
                print(db_user)
            elif db_user and mapped_user_slug:
                db_user.search_description = ''
                db_user.seo_title = ''
                db_user.show_in_menus = False
                db_user.slug = mapped_user_slug
                db_user.title = mapped_user_title
                db_user.first_name = mapped_user['first_name']
                db_user.last_name = mapped_user['last_name']
                db_user.position_at_new_america = user_api['title']
                db_user.role = role_info['role_title']
                db_user.email = user_api['email']
                db_user.expert = role_info['expert']
                db_user.depth = 4
                db_user.short_bio = user_api['short_bio']
                db_user.long_bio = user_api['long_bio']
                db_user.profile_image = download_image(
                    user_api['image'], mapped_user_slug + "_person_image.jpeg")
                print("Existing user")
                print(db_user)
                db_user.save()
Esempio n. 2
0
 def create_person(self):
     person = Person()
     person.sex = self.__generate_sex()
     person.birth_date = self.__generate_date()
     person.first_name = self.__generate_name(person.sex)
     person.last_name = self.__generate_surname(person.sex)
     person.pesel = self.__generate_pesel(person.birth_date, person.sex)
     person.email = self.__generate_email(person.first_name,
                                          person.last_name)
     person.phone = self.__generate_phone()
     person.password = self.__generate_password()
     logging.basicConfig(level=logging.DEBUG)
     logging.info(
         f"Created person {person.first_name} {person.last_name} with pesel {person.pesel}"
     )
     return person