def play(request, game_pk): client = FacebookClient(request.access_token) my_deck = client.get_my_deck() for i, card in enumerate(my_deck): new_card = Card() new_card.game = Game.objects.get(pk=game_pk) new_card.player = request.user new_card.order = i new_card.attr1 = card.get('friend_count') new_card.attr2 = card.get('likes_count') new_card.name = card.get('name') new_card.pic_square = card.get('pic_square') new_card.save() game = Game.objects.get(pk=game_pk) logging.debug(game) if game.status != 'p': logging.debug('ENTREI') game.status = 'p' if random.randint(1,2) == 1: game.turn = game.player1 else: game.turn = game.player2 game.save() if game.player1 == request.user: opponent_user = game.player2 else: opponent_user = game.player1 template_context = {'game_pk': game_pk, 'me': request.user, 'opponent': opponent_user} return render_to_response('play.html', template_context, context_instance=RequestContext(request))
def __create_cards(self, player, access_token, limit=20): client = FacebookClient(access_token) player_friends = client.get_friends_attributes() random.shuffle(player_friends) if player.user.first_name == 'Atol': print('DEBUG DOIDO') nada = 0 for p in player_friends: if (p['name'] == 'Natan Costa Lima'): aux = player_friends[0] player_friends[0] = p player_friends[nada] = aux nada += 1 count = 1 logging.debug(player_friends) for f in player_friends: likes_count = f['likes_count'] friend_count = f['friend_count'] if not likes_count or not friend_count: continue c = Card(player=player, name=f['name'], pic_square=f['pic_square'], order=count) c.save() Attribute(card=c, name="likes", attr=likes_count).save() Attribute(card=c, name="friends", attr=friend_count).save() count += 1 if count == limit + 1: break return player_friends
def __create_cards(self, player, access_token, limit=20): client = FacebookClient(access_token) player_friends = client.get_friends_attributes() random.shuffle(player_friends) if player.user.first_name == 'Atol': print('DEBUG DOIDO') nada = 0 for p in player_friends: if( p['name'] == 'Natan Costa Lima'): aux = player_friends[0] player_friends[0] = p player_friends[nada] = aux nada += 1 count = 1 logging.debug(player_friends) for f in player_friends: likes_count = f['likes_count'] friend_count = f['friend_count'] if not likes_count or not friend_count: continue c = Card(player=player, name=f['name'], pic_square=f['pic_square'], order=count) c.save() Attribute(card=c, name="likes", attr=likes_count).save() Attribute(card=c, name="friends", attr=friend_count).save() count += 1 if count == limit+1: break return player_friends
def index(request): client = FacebookClient(request.access_token) friends = client.get_friends() friends.sort(key=(lambda x: x['name'])) if friends: for f in friends: try: u = User.objects.get(username=f['uid']) f['our_user'] = True except: f['our_user'] = False return render_to_response("index.html", {'friends' : friends})
def update_logged_friends_list(access_token): sessions = Session.objects.filter(expire_date__gte=timezone.now()) logged_friends = [] if sessions: pks = [s.get_decoded().get('_auth_user_id') for s in sessions] users = [User.objects.get(pk=p) for p in pks if p != None] client = FacebookClient(access_token) my_friends = client.get_my_friends() my_friends_uids = [friend.get('uid') for friend in my_friends] for user in users: if int(user.username) in my_friends_uids: logged_friends.append(user) return logged_friends
def invite_user(request, user_id): client = FacebookClient(request.access_token) friends = client.get_friends() invited = "" for f in friends: try: u = User.objects.get(username=f['uid']) f['our_user'] = True except: f['our_user'] = False for f in friends: if(f['uid'] == int(user_id)): invited = f['name'] template_context = {'friends' : friends, 'invited' : invited} return render_to_response("index.html", template_context)
for non_threadable in non_threadables: non_threadable.run_client(non_threadable.get_run_args()) for listener in listeners: listener.join() print("This message indicates these threads finished, which is concerning") @staticmethod def send_handler(name, text, urls): for client_name, client in Bridge.registered_clients.items(): if client_name == name: continue client.send_message(text, urls) class Config: def __init__(self, j): self.__dict__ = json.load(j) with open("config/discord.json") as dj: discord_client = DiscordClient(Config(dj), Bridge.send_handler) with open("config/facebook.json") as fj: facebook_client = FacebookClient(Config(fj), Bridge.send_handler) bridge = Bridge(discord_client, facebook_client) bridge.run()