h = (struct.unpack('>I', h[o:o + 4])[0] & 2147483647) % 1000000
return h

def get_totp_token(secret):
    return get_hotp_token(secret, intervals_no=int(time.time()) // 30)
Google Authenticator implementation in Python