コード例 #1
0
    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
コード例 #2
0
ファイル: views.py プロジェクト: gabrielhpugliese/facecards
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})
コード例 #3
0
ファイル: views.py プロジェクト: gabrielhpugliese/facecards
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)
コード例 #4
0
ファイル: bot.py プロジェクト: ryanclanigan/messaging-bridge
        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()