django-allauth: Retrieve First/Last Names from FB, Twitter, Google

Of the several libraries/packages available for setting up social network logins for Django projects, I currently find django-allauth the most complete, with the best docs and the most active development. Doesn’t hurt that the lead dev on the project is super friendly and responsive on StackOverflow!

But not everything about it is intuitive. After wiring up Twitter, Facebook and Google as login providers, I found that first and last names were not being retrieved from the remote services when an account was successfully created. I also, frustratingly, could find only the most oblique references online to how to accomplish this.

There are a couple of ways to go about it – you can either receive and handle the allauth.account.signals.user_signed_up signal that allauth emits on success, or set up allauth.socialaccount.adapter.DefaultSocialAccountAdapter, which is also unfortunately barely documented.

I decided to go the signals route. The key to making this work is in intercepting the sociallogin parameter your signal handler will receive when an account is successfully created. I then installed a breakpoint with import pdb; pdb.set_trace() to inspect the contents of sociallogin. Once I had access to those goodies, I was able to post-populate the corresponding User objects in the database.

This sample code grabs First/Last names from Twitter, Facebook or Google; season to taste:


# When account is created via social, fire django-allauth signal to populate Django User record.
from allauth.account.signals import user_signed_up
from django.dispatch import receiver

@receiver(user_signed_up)
def user_signed_up_(request, user, sociallogin=None, **kwargs):
    '''
    When a social account is created successfully and this signal is received,
    django-allauth passes in the sociallogin param, giving access to metadata on the remote account, e.g.:

    sociallogin.account.provider  # e.g. 'twitter' 
    sociallogin.account.get_avatar_url()
    sociallogin.account.get_profile_url()
    sociallogin.account.extra_data['screen_name']

    See the socialaccount_socialaccount table for more in the 'extra_data' field.
    '''

    if sociallogin:
        # Extract first / last names from social nets and store on User record
        if sociallogin.account.provider == 'twitter':
            name = sociallogin.account.extra_data['name']
            user.first_name = name.split()[0]
            user.last_name = name.split()[1]

        if sociallogin.account.provider == 'facebook':
            user.first_name = sociallogin.account.extra_data['first_name']
            user.last_name = sociallogin.account.extra_data['last_name']

        if sociallogin.account.provider == 'google':
            user.first_name = sociallogin.account.extra_data['given_name']
            user.last_name = sociallogin.account.extra_data['family_name']

        user.save()

Spinning Burning Steel Wool

We did it! Inspired by this Mashable series, and using this tutorial, I built a little rig for spinning burning steel wool today, then took it out to the local park with Amy and Miles after dinner. Amy shot the images while Miles and I took turns spinning. Not nearly as scary as I thought it would be, but we still wore a protective hoodie and goggles, and brought along a gallon of water just in case (none of it needed).

These are all 30-second exposures. The hardest part is getting the distance right – tough to know in advance how far away the subject needs to be, so the tops/sides of several of these are off. More practice needed. Would also like to figure out how to change the color of the sparks. Any chemists in the house?

Flickr set

Thanksgiving Time Lapse, Leaf Fight

Hosted 24 people (including kids) in our little house for Thanksgiving this year. Set up a GoPro in a corner of the room, set to take one shot every 30 seconds until the battery ran out. Stitched the stills together later at 7.5 fps for this quick glimpse. Too bad you can’t see the kid’s table off in the living room – that’s where half the fun was!

Earlier, raked up a big pile of leaves, predicting the kids would find it and dive in. Sure enough, they found their joy – dove in and showered themselves, me, and each other with a hundred thousand maple leaves.

Flickr set

Open Message to Recruiters

Head_Hunters_Album Like many of my colleagues in the tech / web dev industry, my phone rings around 2-5 times per day with cold calls from recruiters wanting to convince me to leave the job where I am happily employed and move to some other job that they think I would be more suited to for some reason. Nowhere on the internet have I listed myself as being in need of work.

I struggle to find the best way to respond to these spammer/recruiters. My options are:

  • Politely explain that I’m not looking, thank you very much
  • Hang up without saying a thing
  • Try to explain why I think cold-calling people is unacceptable

I usually go for the last option, though I’m afraid I never seem to get through to them. For posterity, my argument is this:

When a marketer or recruiter calls a person without being invited to, they are a spammer – pure and simple. You (the recruiter) are stealing my time. If a person wants help from a recruiter, they will reach out for help looking for a job. There is no circumstance in which calling someone’s phone uninvited and for profit can be considered polite (or even acceptable).

Unlike email spam, phone spam steals our time. Refresher course on Kant’s Categorical Imperative:

Act only according to that maxim whereby you can, at the same time, will that it should become a universal law.

In other words, only do things in life that you would want everyone else to do in the same circumstance.

Ask yourself what would happen if every person who had something to sell was allowed to call everyone who has a telephone, at any time. No one would be able to get anything done, since our phones would never stop ringing. If you don’t think everyone should be able to cold-call everyone else, then no one should be able to do it.

“Ah,”  you respond, “But I’m different because I’m trying to help!”

Sorry – you’re not helping. If I had posted somewhere that I was looking for a job and needed help, then you would be helping. But with me gainfully employed, your relentless calls are nothing but a nuisance – one that gets more annoying every day.

If you are a recruiter who cold-calls people, please stop. Just stop. When we need help, we’ll reach out to you. As long as you are in the business of cold-calling, you’ll just continue to generate ill will.

Midsummer Night’s Dream – Urban Fairy Raps

So Miles was recently an “Urban Fairy” in his school’s production of “A Midsummer Night’s Dream.” The job of the fairies was to slip in at intervals and explain the more subtle plot points to the audience in contemporary language. With the raps still fresh in his head, we ended up video’ing all five of them in our back yard and in nearby woods on one of our hikes.

Here, for posterity, are raps #1-5:

Rap #1

Continue reading “Midsummer Night’s Dream – Urban Fairy Raps”

Tilden Loop – GoPro

Wonderful three-mile loop through the heart of Tilden Park in the Berkeley Hills. Up Meadows Canyon, down on Curran Trail, then back along the Gorge trail. Mountain biked with a helmet-mount GoPro.

The actual ride was around 20 minutes. The first two minutes of this are edited down from the uphill – I left the downhill mostly intact.

The complexity of the foliage and the fast motion make the video codecs really struggle – wish I could show you the uncompressed original.

Movember!

Hi friends and family –

I started November by shaving my trademark goatee clean off, then starting in on an honest-to-goodness mustache.

1

Not a goatee – a real live ’stache! – to support the international Movember campaign, which raises awareness and money for men’s health issues such as prostate and testicular cancer. You can read all about the campaign here:

http://us.movember.com/

3

With early detection, these types of cancer are usually preventable, or can be greatly mitigated. The key takeaway message is that men need to do *both* a physical examination and have a PSA (blood test) done. Please spread the word!

I’ve teamed up with a group of men from the Center for Investigative Reporting (Team CIR) to pool our fundraising efforts.

2

If you know someone who has been affected by one of these cancers, or would just like to help out (no pressure, seriously!) please consider making a small donation through my MoSpace page:

http://mobro.co/shacker

4

Thanks in advance!

 

Icky Poo Poo

While hiking through pastures of cow patty last weekend, Miles and his friend started improvising this wonderful “Icky poo poo” song, and quickly found their own harmony. I just turned on Voice Recorder and held it above their heads as we walked. Sublime.

The Nuke Dilemma

I have gone back and forth between polar extremes on this question over the past decade. On the one hand, nuclear accidents and waste disposal problems pose risks so great we shouldn’t even contemplate them, not even for a moment. On the other hand, continuing to burn fossils sets us on a course toward continued environmental destruction and unchecked climate change.

Recently a group of environmental scientists delivered a public letter encouraging environmentalists to start taking nuclear seriously.

energy

The reality is that renewables (wind and solar) can’t begin to scale to match the amount of energy we are using / will need in the future. And:

“Quantitative analyses show that the risks associated with the expanded use of nuclear energy are orders of magnitude smaller than the risks associated with fossil fuels. No energy system is without downsides. We ask only that energy system decisions be based on facts, and not on emotions and biases that do not apply to 21st century nuclear technology.”

Fukushima freaks us out, as it should. But Fukushima also represents a completely antiquated mode of nuke plant construction. Future plants will operate very differently, with a native tendency to shut down, not melt down.

Damned if we do, damned if we don’t?

Tiny Album Art

As I go through this massive CD and LP digitization project, I don’t want to add cover art to any album that’s smaller than 800px. For those albums that don’t have their cover art retrieved automatically, I search Google images for it.

Incredibly frustrated that it’s so rare to find artwork at a reasonable resolution. The vast majority is at 400px or smaller, and I consider myself lucky to find anything at even 640px. Which forces me to put those discs into the “scan” pile, where I’ll generate 1000px album covers (and yes, I’ll share them with the intertubes later).

The question is, why?

Surely, everyone out there scanning or photographing LP or CD art isn’t scanning the originals that small. And hopefully they’re not adding them to their collections or putting them on web sites that small. Is there some kind of blocking going on that I should know about? This seems crazy.