forked from HKCodeCamp/vocably
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/HKCodeCamp/vocably
- Loading branch information
Showing
4 changed files
with
80 additions
and
20 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,9 +83,17 @@ def store_user_words(email,words): | |
for word in words: | ||
query = 'INSERT INTO Vocab VALUES("' | ||
query += email + '","' + word + '");' | ||
cur.execute(query) | ||
try: | ||
cur.execute(query) | ||
except sqlite3.IntegrityError: | ||
pass | ||
|
||
def wipe_db(): | ||
|
||
if not os.path.isfile("vocably.db"): | ||
print "The database is not there to begin with!" | ||
return | ||
|
||
msg = "Are you 100% sure you want to wipe the database?\n" | ||
msg += "This will remote all data and is irreversible... (yes/no)\n" | ||
input_ = raw_input(msg).strip().lower() | ||
|
@@ -105,6 +113,7 @@ def test(): | |
create_user("[email protected]",0.3726) | ||
set_score("[email protected]",0.9999) | ||
store_user_words("[email protected]",['helicopter','giraffe','heteroskedasticity']) | ||
store_user_words("[email protected]",['computer','giraffe','fantastic']) | ||
print get_list('[email protected]') | ||
print get_score('[email protected]') | ||
print get_score('[email protected]') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Functions for authenticating with OAuth2 on Google's servers | ||
|
||
from oauth2client.client import flow_from_clientsecrets | ||
from oauth2client.file import Storage | ||
|
||
import imaplib, json | ||
from urllib import urlopen, urlencode | ||
|
||
import score | ||
|
||
def initialize_module(): | ||
global flow, storage | ||
flow = flow_from_clientsecrets('config/client_secrets.json', | ||
scope='https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://mail.google.com/', | ||
redirect_uri='http://localhost:8080/oauth2callback') | ||
storage = Storage('config/credentials') | ||
|
||
def authorization_url(): | ||
return flow.step1_get_authorize_url() | ||
|
||
def authorize(code): | ||
credentials = flow.step2_exchange(code) | ||
storage.put(credentials) | ||
print "Stored credentials" | ||
|
||
def fetch_mail(): | ||
print "Getting user profile data and email address" | ||
credentials = storage.get() | ||
params = { 'access_token': credentials.access_token } | ||
data = urlopen('https://www.googleapis.com/oauth2/v1/userinfo?%s' % urlencode(params)).read() | ||
data = json.loads(data) | ||
auth_str = "user=%s\1auth=Bearer %s\1\1" % (data['email'], credentials.access_token) | ||
|
||
print "Authenticating against GMail IMAP servers" | ||
imap_conn = imaplib.IMAP4_SSL('imap.gmail.com') | ||
imap_conn.authenticate('XOAUTH2', lambda x: auth_str) | ||
imap_conn.select('INBOX') #"[Gmail]/Sent Mail" | ||
|
||
# Pull email bodies | ||
resp, data = imap_conn.search(None, 'ALL') | ||
email_text = "" | ||
for num in data[0].split(): | ||
resp, body = imap_conn.fetch(num, '(BODY[TEXT])') | ||
email_text += body | ||
print 'Message %s\n%s\n' % (num, body[0][1]) | ||
return email_text | ||
|
||
def deauthorize(): | ||
if imap_conn: | ||
imap_conn.close() | ||
imap_conn.logout() | ||
|
||
initialize_module() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters