def verify(): if 'email' not in session: return redirect(url_for('login')) useremail = session['email'] flow = createflow(useremail) authorizeURL = authorize(flow) codeform = GooglecodeForm() if request.method == 'POST': if codeform.validate() == False: return render_template('verify.html', form=codeform) else: # get the google code form the from google_code = codeform.google_code.data # generate the credentials credentials = generate_credentials(flow, google_code) return redirect(url_for('extract')) elif request.method == 'GET': return render_template("verify.html", authorizeURL=authorizeURL, form=codeform)
def get_friends_helper(request): user = authorize(request) if not user: return {"message":"Not authorized!"}, 401 user_entry = db.find_one({"username":user})#["friends"] return {"friends":user_entry["friends"],"friend_requests":user_entry["friend_requests"]}, 200
def _login( ): # The login button (also called for auto-login if user was logged in last time) global username global spoofy global logged_in global playlists username_submit.state(["disabled"]) if logged_in: # Logged in logging out print("logging out") username = None playlist_list.delete(0, playlist_list.size() - 1) playlists = [] os.remove("lastuser") logged_in = False else: # Logged out loggin in spoofy = Spotify(auth=authorize(username)) user_id = spoofy.me()["id"] # Get who we are logged in as if username != user_id: username = user_id with open("lastuser", "w") as f: f.write(username) logged_in = True set_login_state() username_submit.state(["!disabled"])
def handle_query(): userName = authenticate.authenticate(request) if userName is None: print 'this request is not authenticated' return build_response_not_authenticated(request) authorized, error = authorize.authorize(request, userName) if not authorized: print 'this action is not authorized for %s' % userName return build_response_not_authorized(request, error) return forward_and_resign(request)
def handle_query(): userName = authenticate.authenticate(request) if userName is None: print 'this request is not authenticated' return build_response_not_authenticated(request) authorized, error = authorize.authorize(request,userName) if not authorized: print 'this action is not authorized for %s' % userName return build_response_not_authorized(request, error) return forward_and_resign(request)
def add_track_helper(request): user = authorize(request) if not user: return {"message": "Not authorized!"}, 401 body = loads(request.data) track_id = body["track_url"] try: track_id = track_id.split("track/")[1] except Exception: print("excepted something") print(track_id) try: track = sp.track(track_id) entry = {} entry["note"] = body["note"] entry["title"] = track["name"] entry["artist"] = ', '.join( [artist["name"] for artist in track["artists"]]) entry["album"] = track["album"]["name"] #entry["release_date"] #entry["duration"] entry["id"] = track["id"] #entry["noteworthy_timestamp"] entry["date_added"] = datetime.datetime.utcnow() # update friend's list of received songs db.update_one( { "username": body["friend_username"], "friends.username": user }, {"$push": { "friends.$.songsReceived": entry }}) # update user's list of sent songs db.update_one( { "username": user, "friends.username": body["friend_username"] }, {"$push": { "friends.$.songsSent": entry }}) return {"message": "Song added!"}, 200 except Exception as e: print(e) return {"message": "Something went wrong"}, 500
def accept_friend_request_helper(request): # check access token user = authorize(request) if not user: return {"message": "Not authorized!"}, 401 body = loads(request.data) friend_username = body["friend_username"] if not db.find_one({"username": user, "friend_requests": friend_username}): return { "message": "Friend not found in pending friend requests. Weird" }, 404 # add accepted friend to user's friend list friends = db.find_one({"username": user})["friends"] new_friend = { "username": friend_username, "songsReceived": [], "songsSent": [] } friends.append(new_friend) db.update_one({"username": user}, {"$set": {"friends": friends}}) # clear new friend from requests db.update_one({"username": user}, {"$pull": { "friend_requests": friend_username }}) # add user to the accepted friend's friend list other_friends = db.find_one({"username": friend_username})["friends"] other_friends.append({ "username": user, "songsReceived": [], "songsSent": [] }) db.update_one({"username": friend_username}, {"$set": { "friends": other_friends }}) return {"message": "friend added!"}, 200
def main(): """ Main function """ parser = make_parser() arguments = parser.parse_args(sys.argv[1:]) arguments = vars(arguments) command = arguments.pop('command') auth = authorize.authorize() if command == 'timeline': response = requests.get(TIMELINE_URL, auth=auth) print response.json() if command == 'friends': response = requests.get(FRIENDS_URL, auth=auth) #print response.json() for c in response.json()['users']: print c['name'] if command == 'followers': response = requests.get(FOLLOWERS_URL, auth=auth) #print response.json() for c in response.json()['users']: print c['name']
import os import pickle from pprint import pprint as pp import sys import xml.dom.minidom import xmltodict from goodreads import client from authorize import authorize CONSUMER_KEY = os.environ.get('GR_KEY') CONSUMER_SECRET = os.environ.get('GR_SECRET') SESSION = 'session' try: session = pickle.load(open(SESSION, "rb")) except FileNotFoundError: session = authorize() ACCESS_TOKEN = session.access_token ACCESS_TOKEN_SECRET = session.access_token_secret gc = client.GoodreadsClient(CONSUMER_KEY, CONSUMER_SECRET) gc.authenticate(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) resp = session.get("/updates/friends.xml") #xml_out = xml.dom.minidom.parseString(resp.content) d = xmltodict.parse(resp.content) pp(d)
#-*- coding: utf-8 -*- import xlrd from xlwt import Workbook import time #import pytz import datetime, shutil, os, sys import authorize base_dir = '' if __name__ == '__main__': authorize.authorize() #打开excel src_fname = base_dir + 'order-item-info.xls' if not os.path.exists(src_fname): print u"\n\t文件: order-item-info.xls 不存在\n" os.system("pause") sys.exit(0) src_excel = xlrd.open_workbook(src_fname) #注意这里的workbook首字母是小写 fname = base_dir + 'amazon/' + time.strftime(u"%Y-%m-%d %H.%M", time.localtime()) + '.txt' track_num_file = open(fname, 'w') table = src_excel.sheets()[0] lines = [u'order-id\torder-item-id\tquantity\tship-date\tcarrier-code\tcarrier-name\ttracking-number\tship-method\n'] ship_date = (datetime.datetime.now() - datetime.timedelta(hours=15)).strftime('%Y-%m-%d')
# SunTweet # This script will tweet about the sun import time import twitter from Sun import * from authorize import authorize #Start up a twitter API api=authorize() #Create a new data point to monitor solarDataPoint=datum("/home/andy/Dropbox/Projects/Python/SunTweet/test.txt") #Update the data point every 15 minutes lastTime=time.time() lastSolarTime=solarDataPoint.GetDateTime() while True: currTime=time.time() #Check current time if (currTime>=lastTime+15*60): solarDataPoint.Update() solarTime=solarDataPoint.GetDateTime() solarValue=solarDataPoint.GetValue() if (solarTime!=lastSolarTime): #Make sure log is being updated if (solarValue>10): #Based on the value of the data point, tweet about it api.PostUpdate("The sun is currently shining at "+solarValue+" watts") lastSolarTime=solarTime else: print "Log dupe"
def test_login_success(): user_email = "*****@*****.**" passwd = "love" usr_dict = {'email': user_email, 'password': passwd} auth = authorize.authorize(usr_dict, None) assert has_token_for(user_email, auth)
def test_bad_password(): user_email = "*****@*****.**" passwd = "arghf" usr_dict = {'email': user_email, 'password': passwd} auth = authorize.authorize(usr_dict, None) assert check_by_schema(schema_for_http(403, {"type": "string", "const": "invalid email,hash combo"}), auth)
# Show a more descriptive message if the file doesn't exist. if not os.path.exists(path): logger.error("Couldn't find an account file at {}.".format(path)) logger.error("Are you in the right directory? Did you register yet?") logger.error("Run 'manuale -h' for instructions.") raise ManualeError() try: with open(path, 'rb') as f: return deserialize_account(f.read()) except (ValueError, IOError) as e: logger.error("Couldn't read account file. Aborting.") raise ManualeError(e) account = load_account('account.json') print(account.key) # sys.exit() acme = Acme(LETS_ENCRYPT_PRODUCTION, account) print(acme.url) authorize.authorize(LETS_ENCRYPT_PRODUCTION, account, ['quydxtu11.tk'], 'dns') time.sleep(60) # rds = redis.StrictRedis(host=REDIS_SERVER, port=REDIS_PORT, db=REDIS_DB) # authz = rds.hget('xx12', 'authz') # authorize.verify_auth(account.key, authz)
def main(args): API_KEY=au.FLAGS['API_KEY'] gp_api=a.authorize(API_KEY)