Exemple #1
0
    def get_messages_from_user_in_group(self, user_id, group_id):
        messageId = 0
        userMessages = []
        group = fbchat.Group(session=self.session, id=group_id)
        for message in group.fetch_messages(limit=20000):
            if message.author == user_id:
                if message.text and not message.text.startswith("https"):
                    messageId += 1
                    jsonMessage = {"id": messageId, "message": message.text}
                    userMessages.append(jsonMessage)

        self.save_database()

        return userMessages
Exemple #2
0
async def post_message(session, client, id, message, image, location):
    thread = fbchat.Group(session=session, id=id)

    if message is not None:
        await thread.send_text(message)

    if image is not None:
        async with ClientSession() as sess, sess.get(image) as resp:
            image_data = await resp.read()
            files = await client.upload([("image_name.png", image_data,
                                          "image/png")])
            await thread.send_files(files)  # Alternative to .send_text

    if location is not None:
        await thread.send_pinned_location(location["latitude"],
                                          location["longitude"])
Exemple #3
0
def some_job():
    global tab
    args = parser.parse_args()
    token = args.token
    rep = args.repo
    password = args.fb_password
    username = args.fb_username
    fb_group = args.fb_group
    g = Github(token)
    repo = g.get_repo(rep)
    try:
        fileRead = open("./cards.txt")
    except:
        fileRead = open("./cards.txt", "x")

    tmp = []
    for id, i in enumerate(repo.get_projects()[0].get_columns()):
        tmp.append([])
        for card in i.get_cards():
            tmp[id].append(card.note)

    if fileRead.readable():
        for line in fileRead.readlines():
            tab.append(eval(line))

        if not tmp == tab:
            for id in range([len(tmp), len(tab)][len(tmp) > len(tab)]):
                res = set(tab[id]).symmetric_difference(tmp[id])
                print(res)
                if res is not None:
                    session = fbchat.Session.login(username, password)
                    thread = fbchat.Group(session=session, id=fb_group)
                    thread.send_text(str(res))

        else:
            print("Up to date")

    file = open("./cards.txt", "w")
    for cards in tmp:
        file.write(str(cards))
        file.write("\n")
Exemple #4
0
 async def send_text_to_group(self, group_id, message, session):
     group = fbchat.Group(session=session, id=group_id)
     await group.send_text(message)
     print("Message {} has been sent to user: {}".format(message, group_id))
Exemple #5
0
def group(pytestconfig, session):
    group_id = pytestconfig.cache.get("group_id", None)
    if not group_id:
        group_id = input("A group you're chatting with's id: ")
        pytestconfig.cache.set("group_id", group_id)
    return fbchat.Group(session=session, id=group_id)