Ejemplo n.º 1
0
def handle_drop_disc(json_data):
    game, player_id = authenticate(session)
    if not game:
        print('Invalid connection. Disconnecting!')
        return disconnect()

    # Play disc
    data = json.loads(json_data)
    column_index = data.get('column_index')
    game_id = game["game_id"]
    try:
        game = GameStore.play_turn(game_id, player_id, column_index)
        json_data = json_game_state(game)
        emit('game_state', json_data, room=game_id)
    except OutOfTurnError:
        print("Player %d out of turn" % game["player_positions"][player_id])
        data = dict(message="It's not your turn!")
        emit("alert", json.dumps(data))
    except GridColumnFullError:
        print("Column %d is full" % column_index)
        data = dict(message="This column is full. Please pick another column.")
        emit("alert", json.dumps(data))
    except GameOverError:
        print("The game has ended")
        data = dict(message="The game is over!")
        emit("alert", json.dumps(data))
Ejemplo n.º 2
0
def run(username, source_playlist, output_playlist):
    try:
        oauth_manager, sp, user = authenticate(username)

        # create archive playlist
        archive = find_or_create_archive(sp,
                                         user_id=user['id'],
                                         output_playlist=output_playlist)

        output_playlist_track_uris = get_track_uris_by_playlist_name(
            sp=sp, user_id=user['id'], playlist_name=output_playlist)
        source_playlist_track_uris = get_track_uris_by_playlist_name(
            sp=sp, user_id=user['id'], playlist_name=source_playlist)

        # remove track uris which exist in archive already
        source_playlist_track_uris = list(
            set(source_playlist_track_uris) - set(output_playlist_track_uris))

        if source_playlist_track_uris:
            sp.user_playlist_add_tracks(user=user['id'],
                                        playlist_id=archive['id'],
                                        tracks=source_playlist_track_uris)

        logging.info('Added {} songs to {} playlist'.format(
            len(source_playlist_track_uris), output_playlist))
    except Exception as e:
        logging.error('Error', e)
Ejemplo n.º 3
0
def handle_restart():
    game, player_id = authenticate(session)
    if not game:
        print('Invalid connection. Disconnecting!')
        return disconnect()

    game_id = game["game_id"]
    game = GameStore.restart(game_id)
    json_data = json_game_state(game)
    emit('game_state', json_data, room=game_id)
Ejemplo n.º 4
0
def handle_connect():
    game, player_id = authenticate(session)
    players = game["player_positions"]
    if not game:
        print('Invalid connection. Disconnecting!')
        return disconnect()

    game_id = game["game_id"]
    print("Player %d connected to game %s" % (players[player_id], game_id))
    if game_id not in rooms():
        join_room(game_id)

    json_data = json_game_state(game)
    emit('game_state', json_data, room=game_id)
Ejemplo n.º 5
0
def login(request):
	if request.method == 'POST': # If the form has been submitted...
		form = LoginForm(request.POST) # A form bound to the POST data
		if form.is_valid(): # All validation rules pass
			username = form.cleaned_data['username']
			password = form.cleaned_data['password']
			host = form.cleaned_data['host']
			if helpers.authenticate(host,username, password):
				request.session['username'] = username
				request.session['host'] = host
				request.session['password'] = password
				return HttpResponseRedirect('listjobsTorque') # Redirect after POST
			else:
				return render_to_response('login.html', {'form':form,'error_message': 'Invalid authentication'},context_instance=RequestContext(request) )
	else:
		return render_to_response('login.html', {'form':LoginForm()},context_instance=RequestContext(request) )
Ejemplo n.º 6
0
def handle_disconnect():
    game, player_id = authenticate(session)
    game_id = game["game_id"]
    players = game["player_positions"]

    if game and player_id in players:
        connections = GameStore.get_open_connections(game_id, player_id)
        position = game["player_positions"][player_id]
        if connections > 1:
            connections = GameStore.remove_player_connection(game_id, player_id)
            print("Player %d closed a window for game %s. %d windows left." % (position, game_id, connections)
            )
        else:
            GameStore.remove_player(game_id, player_id)
            leave_room(room=game_id)
            print("Player %s left game %s" % (position, game_id))

        emit('game_state', json.dumps(game), room=game_id)
Ejemplo n.º 7
0
    def __init__(self, host, username, password, tenant=None):
        """
		Creates a connection to the vRA REST API using the provided
		username and password.
		Parameters:
	                host = vRA Appliance fqdn
        	        user = user account with access to the vRA portal
                	passowrd = valid password for above user
	                tenant = tenant for user. if this is NONE it will default to "vsphere.local"
		"""

        if tenant is None:
            tenant = "vsphere.local"

        self.host = host
        self.username = username
        self.password = password
        self.tenant = tenant
        self.token = authenticate(host, username, password, tenant)
Ejemplo n.º 8
0
    def __init__(self, host, username, password, tenant=None):
        """
        Creates a connection to the vRA REST API using the provided
        username and password.
        Parameters:
            host = vRA Appliance fqdn
            user = user account with access to the vRA portal
            passowrd = valid password for above user
            tenant = tenant for user. if this is NONE it will default to "vsphere.local"
        """

        if tenant is None:
            tenant = "vsphere.local"

        self.host = host
        self.username = username
        self.password = password
        self.tenant = tenant
        self.token = authenticate(host, username, password, tenant)
Ejemplo n.º 9
0
def home():

    #data to be passed in to the front
    data = {}
    #authentification 
    user_info = helpers.authenticate(db,request)
    user = user_info[0][0]
    #if there were no users found, display error messageS
    if user == None:
        return "<h1>Error:Failed To Authenticate<h1>"
    
    data['user_info'] = user_info[0]
    # list of (isbn,ratings,title,author,year) book info
    data['browse'] = helpers.getBooks(db,limit = 5)
    
    #reading list 
    data['reading_list'] = helpers.getReadingList(db,user)
    #book reviewed
    data['book_reviewed'] = []
    
    session['user_id'] = user
    return render_template("dashboard.html",data=data)
Ejemplo n.º 10
0
from helpers import authenticate

import logging
import os

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    from trakt import Trakt

    # Configure
    Trakt.configuration.defaults.client(id=os.environ.get('CLIENT_ID'),
                                        secret=os.environ.get('CLIENT_SECRET'))

    # Authenticate
    Trakt.configuration.defaults.oauth.from_response(authenticate())

    for liked_list in Trakt['users'].likes('lists'):
        print liked_list

        for item in liked_list.items():
            print '\t', item
Ejemplo n.º 11
0
from pprint import pprint
from trakt import Trakt
import logging
import os
import time

logging.basicConfig(level=logging.DEBUG)


if __name__ == "__main__":
    # Configure
    Trakt.configuration.defaults.client(id=os.environ.get("CLIENT_ID"), secret=os.environ.get("CLIENT_SECRET"))

    # Authenticate
    Trakt.configuration.defaults.oauth.from_response(authenticate())

    # movie = {
    #     'title': 'Guardians of the Galaxy',
    #     'year': 2014,
    #     'ids': {
    #         'trakt': 28,
    #         'slug': 'guardians-of-the-galaxy-2014',
    #         'imdb': 'tt2015381',
    #         'tmdb': 118340
    #     }
    # }

    show = {
        "title": "Breaking Bad",
        "year": 2008,
Ejemplo n.º 12
0
import os
import time

logging.basicConfig(level=logging.DEBUG)


if __name__ == '__main__':
    # Configure
    Trakt.configuration.defaults.client(
        id=os.environ.get('CLIENT_ID'),
        secret=os.environ.get('CLIENT_SECRET')
    )

    # Authenticate
    Trakt.configuration.defaults.oauth(
        token=authenticate()
    )

    # movie = {
    #     'title': 'Guardians of the Galaxy',
    #     'year': 2014,
    #     'ids': {
    #         'trakt': 28,
    #         'slug': 'guardians-of-the-galaxy-2014',
    #         'imdb': 'tt2015381',
    #         'tmdb': 118340
    #     }
    # }

    show = {
        "title": "Breaking Bad",
Ejemplo n.º 13
0

if __name__ == '__main__':
    # Configure
    Trakt.configuration.defaults.client(
        id=os.environ.get('CLIENT_ID'),
        secret=os.environ.get('CLIENT_SECRET')
    )

    Trakt.configuration.defaults.http(
        retry=True
    )

    # Authenticate
    Trakt.configuration.defaults.oauth.from_response(
        authenticate()
    )

    # Fetch playback for movies
    playback = Trakt['sync/playback'].movies(exceptions=True)

    for key, item in playback.items():
        print item

        if type(item) is Movie:
            print '\tprogress: %r' % item.progress
            print '\tpaused_at: %r' % item.paused_at

    # Fetch movie library (watched, collection, ratings)
    movies = {}
Ejemplo n.º 14
0
from trakt import Trakt
import logging
import os

logging.basicConfig(level=logging.DEBUG)

if __name__ == '__main__':
    # Configure
    Trakt.configuration.defaults.client(id=os.environ.get('CLIENT_ID'),
                                        secret=os.environ.get('CLIENT_SECRET'))

    Trakt.configuration.defaults.http(retry=True)

    # Authenticate
    Trakt.configuration.defaults.oauth(token=authenticate())

    # Fetch movie library (watched, collection, ratings)
    movies = {}

    # Trakt['sync/watched'].movies(movies)
    # Trakt['sync/collection'].movies(movies)
    #
    # Trakt['sync/ratings'].movies(movies)

    for key, movie in movies.items():
        print movie

        print '\t', 'keys', '\t' * 3, movie.keys
        print '\t', 'rating', '\t' * 3, movie.rating
Ejemplo n.º 15
0
import webbrowser

from helpers import authenticate, get_pin, verify_account, get_username, how_many, start_unfollowing, white_list

#open browser
auth_url = authenticate()
webbrowser.get().open(auth_url)

#ask for pin code
print("Submit the verification PIN you received on twitter:")
pin = get_pin()

#verify account
if not verify_account(pin):
    exit(1)        

#do not unfollow these accounts
whitelist = white_list()

#get username
username = get_username()

#ask how many people to unfollow
print("How many users do you want to unfollow? (400 by default)")
amount = how_many()

#unfollow them
start_unfollowing(username, amount, whitelist)