示例#1
0
def account_for_twitter_user(userdata, person=None):
    try:
        account = Account.objects.get(service='twitter.com', ident=str(userdata['id']))
    except Account.DoesNotExist:
        if person is None:
            avatar = Media(
                width=48,
                height=48,
                image_url=userdata['profile_image_url'],
            )
            avatar.save()
            person = Person(
                display_name=userdata['name'],
                avatar=avatar,
                permalink_url='http://twitter.com/%s' % userdata['screen_name'],
            )
            person.save()
        account = Account(
            service='twitter.com',
            ident=str(userdata['id']),
            display_name=userdata['name'],
            person=person,
            status_background_color=userdata.get('profile_background_color') or '',
            status_background_image_url=userdata.get('profile_background_image_url') or '',
            status_background_tile=userdata.get('profile_background_tile') or False,
        )
        account.save()
    else:
        person = account.person
        if not person.avatar_source or person.avatar_source == 'twitter.com':
            if not person.avatar or person.avatar.image_url != userdata['profile_image_url']:
                avatar = Media(
                    width=48,
                    height=48,
                    image_url=userdata['profile_image_url'],
                )
                avatar.save()
                person.avatar = avatar
                person.avatar_source = 'twitter.com'
                person.save()
            elif not person.avatar_source:
                person.avatar_source = 'twitter.com'
                person.save()

        # We can always update these (but only pay for saving if they changed).
        if not (account.status_background_color == (userdata.get('profile_background_color') or '')
            and account.status_background_image_url == userdata.get('profile_background_image_url') or ''
            and account.status_background_tile == (userdata.get('profile_background_tile') or False)):
            account.status_background_color = userdata.get('profile_background_color') or ''
            account.status_background_image_url = userdata.get('profile_background_image_url') or ''
            account.status_background_tile = userdata.get('profile_background_tile') or False
            account.save()

    return account
示例#2
0
def account_for_typepad_user(tp_user, person=None):
    try:
        account = Account.objects.get(service='typepad.com',
                                      ident=tp_user.url_id)
    except Account.DoesNotExist:
        if person is None:
            if tp_user.avatar_link.url_template:
                avatar = Media(
                    width=50,
                    height=50,
                    image_url=tp_user.avatar_link.url_template.replace(
                        '{spec}', '50si'),
                )
            else:
                avatar = Media(
                    width=tp_user.avatar_link.width,
                    height=tp_user.avatar_link.height,
                    image_url=tp_user.avatar_link.url,
                )
            avatar.save()
            person = Person(
                display_name=tp_user.display_name
                or tp_user.preferred_username,
                avatar=avatar,
                permalink_url=tp_user.profile_page_url,
            )
            person.save()
        account = Account(
            service='typepad.com',
            ident=tp_user.url_id,
            display_name=tp_user.display_name or tp_user.preferred_username,
            person=person,
        )
        account.save()
    else:
        person = account.person
        if not person.avatar_source or person.avatar_source == 'typepad.com':
            if tp_user.avatar_link.url_template:
                tp_avatar_url = tp_user.avatar_link.url_template.replace(
                    '{spec}', '50si')
            else:
                tp_avatar_url = tp_user.avatar_link.url

            if not person.avatar or person.avatar.image_url != tp_avatar_url:
                if tp_user.avatar_link.url_template:
                    avatar = Media(
                        width=50,
                        height=50,
                        image_url=tp_avatar_url,
                    )
                else:
                    avatar = Media(
                        width=tp_user.avatar_link.width,
                        height=tp_user.avatar_link.height,
                        image_url=tp_avatar_url,
                    )
                avatar.save()
                person.avatar = avatar
                person.avatar_source = 'typepad.com'
                person.save()
            elif not person.avatar_source:
                person.avatar_source = 'typepad.com'
                person.save()

    return account
示例#3
0
def account_for_typepad_user(tp_user, person=None):
    try:
        account = Account.objects.get(service='typepad.com', ident=tp_user.url_id)
    except Account.DoesNotExist:
        if person is None:
            if tp_user.avatar_link.url_template:
                avatar = Media(
                    width=50,
                    height=50,
                    image_url=tp_user.avatar_link.url_template.replace('{spec}', '50si'),
                )
            else:
                avatar = Media(
                    width=tp_user.avatar_link.width,
                    height=tp_user.avatar_link.height,
                    image_url=tp_user.avatar_link.url,
                )
            avatar.save()
            person = Person(
                display_name=tp_user.display_name or tp_user.preferred_username,
                avatar=avatar,
                permalink_url=tp_user.profile_page_url,
            )
            person.save()
        account = Account(
            service='typepad.com',
            ident=tp_user.url_id,
            display_name=tp_user.display_name or tp_user.preferred_username,
            person=person,
        )
        account.save()
    else:
        person = account.person
        if not person.avatar_source or person.avatar_source == 'typepad.com':
            if tp_user.avatar_link.url_template:
                tp_avatar_url = tp_user.avatar_link.url_template.replace('{spec}', '50si')
            else:
                tp_avatar_url = tp_user.avatar_link.url

            if not person.avatar or person.avatar.image_url != tp_avatar_url:
                if tp_user.avatar_link.url_template:
                    avatar = Media(
                        width=50,
                        height=50,
                        image_url=tp_avatar_url,
                    )
                else:
                    avatar = Media(
                        width=tp_user.avatar_link.width,
                        height=tp_user.avatar_link.height,
                        image_url=tp_avatar_url,
                    )
                avatar.save()
                person.avatar = avatar
                person.avatar_source = 'typepad.com'
                person.save()
            elif not person.avatar_source:
                person.avatar_source = 'typepad.com'
                person.save()

    return account
示例#4
0
def account_for_twitter_user(userdata, person=None):
    try:
        account = Account.objects.get(service='twitter.com',
                                      ident=str(userdata['id']))
    except Account.DoesNotExist:
        if person is None:
            avatar = Media(
                width=48,
                height=48,
                image_url=userdata['profile_image_url'],
            )
            avatar.save()
            person = Person(
                display_name=userdata['name'],
                avatar=avatar,
                permalink_url='http://twitter.com/%s' %
                userdata['screen_name'],
            )
            person.save()
        account = Account(
            service='twitter.com',
            ident=str(userdata['id']),
            display_name=userdata['name'],
            person=person,
            status_background_color=userdata.get('profile_background_color')
            or '',
            status_background_image_url=userdata.get(
                'profile_background_image_url') or '',
            status_background_tile=userdata.get('profile_background_tile')
            or False,
        )
        account.save()
    else:
        person = account.person
        if not person.avatar_source or person.avatar_source == 'twitter.com':
            if not person.avatar or person.avatar.image_url != userdata[
                    'profile_image_url']:
                avatar = Media(
                    width=48,
                    height=48,
                    image_url=userdata['profile_image_url'],
                )
                avatar.save()
                person.avatar = avatar
                person.avatar_source = 'twitter.com'
                person.save()
            elif not person.avatar_source:
                person.avatar_source = 'twitter.com'
                person.save()

        # We can always update these (but only pay for saving if they changed).
        if not (account.status_background_color ==
                (userdata.get('profile_background_color') or '')
                and account.status_background_image_url
                == userdata.get('profile_background_image_url')
                or '' and account.status_background_tile ==
                (userdata.get('profile_background_tile') or False)):
            account.status_background_color = userdata.get(
                'profile_background_color') or ''
            account.status_background_image_url = userdata.get(
                'profile_background_image_url') or ''
            account.status_background_tile = userdata.get(
                'profile_background_tile') or False
            account.save()

    return account