forked from mirror/django-mailbox
Minor cleanup & a Python 3k fix.
This commit is contained in:
parent
e50408e365
commit
05c8d3ece8
2 changed files with 16 additions and 4 deletions
|
|
@ -111,10 +111,14 @@ def fetch_user_info(email):
|
||||||
def fetch_google_contacts(email, limit=10000):
|
def fetch_google_contacts(email, limit=10000):
|
||||||
result = google_api_get(
|
result = google_api_get(
|
||||||
email,
|
email,
|
||||||
"https://www.google.com/m8/feeds/contacts/default/full?v=3.0&alt=json&max-results=%s" % limit
|
"https://www.google.com/m8/feeds/contacts/default/full"
|
||||||
|
"?v=3.0&alt=json&max-results=%s" % limit
|
||||||
)
|
)
|
||||||
entries = result['feed']['entry']
|
entries = result['feed']['entry']
|
||||||
valid_entries = [x for x in entries if u'gd$email' in x.keys() and u'gd$name' in x.keys()]
|
valid_entries = [
|
||||||
|
x for x in entries
|
||||||
|
if u'gd$email' in x.keys() and u'gd$name' in x.keys()
|
||||||
|
]
|
||||||
contacts = []
|
contacts = []
|
||||||
for each in valid_entries:
|
for each in valid_entries:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from django_mailbox.transports.imap import ImapTransport
|
from django_mailbox.transports.imap import ImapTransport
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GmailImapTransport(ImapTransport):
|
class GmailImapTransport(ImapTransport):
|
||||||
|
|
||||||
def connect(self, username, password):
|
def connect(self, username, password):
|
||||||
|
|
@ -7,7 +13,7 @@ class GmailImapTransport(ImapTransport):
|
||||||
try:
|
try:
|
||||||
self._connect_oauth(username)
|
self._connect_oauth(username)
|
||||||
except (TypeError, ValueError) as e:
|
except (TypeError, ValueError) as e:
|
||||||
print " Couldn't do oauth2 because %s" % e
|
logger.warning("Couldn't do oauth2 because %s" % e)
|
||||||
self.server = self.transport(self.hostname, self.port)
|
self.server = self.transport(self.hostname, self.port)
|
||||||
typ, msg = self.server.login(username, password)
|
typ, msg = self.server.login(username, password)
|
||||||
self.server.select()
|
self.server.select()
|
||||||
|
|
@ -37,7 +43,9 @@ class GmailImapTransport(ImapTransport):
|
||||||
pass
|
pass
|
||||||
except AccessTokenNotFound:
|
except AccessTokenNotFound:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"No Token available in python-social-auth for %s" % username
|
"No Token available in python-social-auth for %s" % (
|
||||||
|
username
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
auth_string = 'user=%s\1auth=Bearer %s\1\1' % (
|
auth_string = 'user=%s\1auth=Bearer %s\1\1' % (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue