def run(self, **kwargs):
        global contacts
        global allgroups

        user = User.objects.get(email='*****@*****.**')
        contacts = []
        allgroups = []
        #print "sync google contacts"
        admin_accounts = GoogleAdminAccounts.objects.filter(enable=True).order_by('priority').reverse()
        if len(admin_accounts) > 0 :
            account = admin_accounts[0]
            gather_contacts(account.email, account.password)
            write_contacts()
            for contact in contacts:
                t = timezone.now() # offset-awared datetime
                now_aware = contact['last_changed'].replace(tzinfo=pytz.UTC)
                #t.astimezone(timezone.utc).replace(tzinfo=None)
                #print now_aware < account.last_changed
                if len(contact['phones']) > 0 :
                    p = PhoneNumber()
                    p.user = user
                    pn = phonenumbers.format_number(contact['phones'][0]['tel'], phonenumbers.PhoneNumberFormat.E164)
                    found_type = ""
                    for tel_type in tel_types:
                        if tel_type in contact['phones'][0]['type'] :
                            found_type = tel_type

                    #found = any(contact['phones'][0]['type'] in item for item in tel_types)
                    print 'fnd:', found_type
                    p.phone_type = found_type
                    p.phone_number = pn
                    p.save()
            account.last_changed = t
            account.save()
Exemple #2
0
 def setUp(self):
     Redis().flushall()
     p1 = Person(name='Test User 1', ssn='123456789')
     p1.save()
     pn1 = PhoneNumber(person=p1, label='Test 1', phone_number='5558675309')
     pn1.save()
     from django import db
     db.reset_queries()
Exemple #3
0
def authorized(request):
    c = {}
    c.update(csrf(request))
    print "pre_scraper"
    addresses = scraper.genAddrList()
    print "post_scraper"
    addresses = [(k,v + '(' + k +')') for k,v in addresses.items()]


    if request.method == 'POST': # If the form has been submitted...
        form = MACAddressForm(request.POST) # A form bound to the POST data
        form.fields['addresses'].choices = addresses
        if form.is_valid():
            choices = form.cleaned_data['addresses']
            BlacklistedMAC.objects.all().delete()
            phone = form.cleaned_data['phone'].replace('(','').replace(')','').replace('-','').replace('.','')

            if len(phone) == 10:
                p = PhoneNumber(phone=phone)
                p.save()
            else:
                c['form'] = form
                return render_to_response('auth.html', c)

            for mac in choices:
                obj = BlacklistedMAC(address=mac)
                obj.save()
            return HttpResponseRedirect('/done/') # Redirect after POST
    else:
        form = MACAddressForm()
        form.fields['addresses'].choices = addresses
        if 'code' in request.GET:
            ACCESS_TOKEN_URL = 'https://dev.tendrilinc.com/oauth/access_token'
            authToken = request.GET[u'code']    
            ACCESS_TOKEN_URL += '?grant_type=authorization_code'
            ACCESS_TOKEN_URL += '&code='+str(authToken)  
            ACCESS_TOKEN_URL += '&redirect_uri=www.google.com' 
            ACCESS_TOKEN_URL += '&client_id='+API_KEY 
            ACCESS_TOKEN_URL += '&client_secret='+APP_SECRET 

            data = requests.get(ACCESS_TOKEN_URL, verify=False).text
            for obj in Data.objects.all():
                obj.delete()
            d = Data(**json.loads(data))
            d.save()


    c['form'] = form
    return render_to_response('auth.html', c)