Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c51a332560 | ||
|
a73d2feed6 | ||
|
6929193e9d | ||
|
fea4ad9e89 | ||
|
68099049d4 | ||
|
44cf08bdfd | ||
|
9e32cf17a4 | ||
|
0661367ebb | ||
|
3c07e42ba2 | ||
|
2cd6376818 | ||
|
2a223ec6db | ||
|
637319ec2c |
@@ -17,7 +17,7 @@ from .client import *
|
|||||||
|
|
||||||
|
|
||||||
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
||||||
__version__ = '1.0.15'
|
__version__ = '1.0.19'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
||||||
__email__ = 'carpedm20@gmail.com'
|
__email__ = 'carpedm20@gmail.com'
|
||||||
|
@@ -740,9 +740,10 @@ class Client(object):
|
|||||||
if k['thread_type'] == 1:
|
if k['thread_type'] == 1:
|
||||||
if k['other_user_fbid'] not in participants:
|
if k['other_user_fbid'] not in participants:
|
||||||
raise Exception('A thread was not in participants: {}'.format(j['payload']))
|
raise Exception('A thread was not in participants: {}'.format(j['payload']))
|
||||||
|
participants[k['other_user_fbid']].message_count = k['message_count']
|
||||||
entries.append(participants[k['other_user_fbid']])
|
entries.append(participants[k['other_user_fbid']])
|
||||||
elif k['thread_type'] == 2:
|
elif k['thread_type'] == 2:
|
||||||
entries.append(Group(k['thread_fbid'], participants=set([p.strip('fbid:') for p in k['participants']]), photo=k['image_src'], name=k['name']))
|
entries.append(Group(k['thread_fbid'], participants=set([p.strip('fbid:') for p in k['participants']]), photo=k['image_src'], name=k['name'], message_count=k['message_count']))
|
||||||
else:
|
else:
|
||||||
raise Exception('A thread had an unknown thread type: {}'.format(k))
|
raise Exception('A thread had an unknown thread type: {}'.format(k))
|
||||||
|
|
||||||
@@ -831,6 +832,13 @@ class Client(object):
|
|||||||
except (KeyError, IndexError) as e:
|
except (KeyError, IndexError) as e:
|
||||||
raise Exception('Error when sending message: No message IDs could be found: {}'.format(j))
|
raise Exception('Error when sending message: No message IDs could be found: {}'.format(j))
|
||||||
|
|
||||||
|
# update JS token if receive from response
|
||||||
|
if ('jsmods' in j) and ('require' in j['jsmods']):
|
||||||
|
try:
|
||||||
|
self.payloadDefault['fb_dtsg'] = j['jsmods']['require'][0][3][0]
|
||||||
|
except (KeyError, IndexError) as e:
|
||||||
|
log.warning("Error when update fb_dtsg. Facebook might have changed protocol.")
|
||||||
|
|
||||||
return message_id
|
return message_id
|
||||||
|
|
||||||
def sendMessage(self, message, thread_id=None, thread_type=ThreadType.USER):
|
def sendMessage(self, message, thread_id=None, thread_type=ThreadType.USER):
|
||||||
@@ -943,7 +951,7 @@ class Client(object):
|
|||||||
"""
|
"""
|
||||||
Sends a local image to a thread
|
Sends a local image to a thread
|
||||||
|
|
||||||
:param image_path: URL of an image to upload and send
|
:param image_path: Path of an image to upload and send
|
||||||
:param message: Additional message
|
:param message: Additional message
|
||||||
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
|
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
|
||||||
:param thread_type: See :ref:`intro_threads`
|
:param thread_type: See :ref:`intro_threads`
|
||||||
|
@@ -47,17 +47,18 @@ def get_customization_info(thread):
|
|||||||
for k in info.get('participant_customizations', []):
|
for k in info.get('participant_customizations', []):
|
||||||
rtn['nicknames'][k['participant_id']] = k.get('nickname')
|
rtn['nicknames'][k['participant_id']] = k.get('nickname')
|
||||||
elif info.get('participant_customizations'):
|
elif info.get('participant_customizations'):
|
||||||
_id = thread.get('thread_key', {}).get('other_user_id') or thread.get('id')
|
uid = thread.get('thread_key', {}).get('other_user_id') or thread.get('id')
|
||||||
if info['participant_customizations'][0]['participant_id'] == _id:
|
pc = info['participant_customizations']
|
||||||
rtn['nickname'] = info['participant_customizations'][0]
|
if len(pc) > 0:
|
||||||
if len(info['participant_customizations']) > 1:
|
if pc[0].get('participant_id') == uid:
|
||||||
rtn['own_nickname'] = info['participant_customizations'][1]
|
rtn['nickname'] = pc[0].get('nickname')
|
||||||
elif info['participant_customizations'][1]['participant_id'] == _id:
|
else:
|
||||||
rtn['nickname'] = info['participant_customizations'][1]
|
rtn['own_nickname'] = pc[0].get('nickname')
|
||||||
if len(info['participant_customizations']) > 1:
|
if len(pc) > 1:
|
||||||
rtn['own_nickname'] = info['participant_customizations'][0]
|
if pc[1].get('participant_id') == uid:
|
||||||
else:
|
rtn['nickname'] = pc[1].get('nickname')
|
||||||
raise Exception('No participant matching the user {} found: {}'.format(_id, info['participant_customizations']))
|
else:
|
||||||
|
rtn['own_nickname'] = pc[1].get('nickname')
|
||||||
return rtn
|
return rtn
|
||||||
|
|
||||||
def graphql_to_message(message):
|
def graphql_to_message(message):
|
||||||
@@ -98,7 +99,8 @@ def graphql_to_user(user):
|
|||||||
emoji=c_info.get('emoji'),
|
emoji=c_info.get('emoji'),
|
||||||
own_nickname=c_info.get('own_nickname'),
|
own_nickname=c_info.get('own_nickname'),
|
||||||
photo=user['profile_picture'].get('uri'),
|
photo=user['profile_picture'].get('uri'),
|
||||||
name=user.get('name')
|
name=user.get('name'),
|
||||||
|
message_count=user.get('messages_count')
|
||||||
)
|
)
|
||||||
|
|
||||||
def graphql_to_group(group):
|
def graphql_to_group(group):
|
||||||
@@ -112,7 +114,8 @@ def graphql_to_group(group):
|
|||||||
color=c_info.get('color'),
|
color=c_info.get('color'),
|
||||||
emoji=c_info.get('emoji'),
|
emoji=c_info.get('emoji'),
|
||||||
photo=group['image'].get('uri'),
|
photo=group['image'].get('uri'),
|
||||||
name=group.get('name')
|
name=group.get('name'),
|
||||||
|
message_count=group.get('messages_count')
|
||||||
)
|
)
|
||||||
|
|
||||||
def graphql_to_page(page):
|
def graphql_to_page(page):
|
||||||
@@ -126,7 +129,8 @@ def graphql_to_page(page):
|
|||||||
city=page.get('city').get('name'),
|
city=page.get('city').get('name'),
|
||||||
category=page.get('category_type'),
|
category=page.get('category_type'),
|
||||||
photo=page['profile_picture'].get('uri'),
|
photo=page['profile_picture'].get('uri'),
|
||||||
name=page.get('name')
|
name=page.get('name'),
|
||||||
|
message_count=page.get('messages_count')
|
||||||
)
|
)
|
||||||
|
|
||||||
def graphql_queries_to_json(*queries):
|
def graphql_queries_to_json(*queries):
|
||||||
|
@@ -15,14 +15,16 @@ class Thread(object):
|
|||||||
name = str
|
name = str
|
||||||
#: Timestamp of last message
|
#: Timestamp of last message
|
||||||
last_message_timestamp = str
|
last_message_timestamp = str
|
||||||
|
#: Number of messages in the thread
|
||||||
def __init__(self, _type, uid, photo=None, name=None, last_message_timestamp=None):
|
message_count = int
|
||||||
|
def __init__(self, _type, uid, photo=None, name=None, last_message_timestamp=None, message_count=None):
|
||||||
"""Represents a Facebook thread"""
|
"""Represents a Facebook thread"""
|
||||||
self.uid = str(uid)
|
self.uid = str(uid)
|
||||||
self.type = _type
|
self.type = _type
|
||||||
self.photo = photo
|
self.photo = photo
|
||||||
self.name = name
|
self.name = name
|
||||||
self.last_message_timestamp = last_message_timestamp
|
self.last_message_timestamp = last_message_timestamp
|
||||||
|
self.message_count = message_count
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__unicode__()
|
return self.__unicode__()
|
||||||
|
@@ -48,7 +48,7 @@ GENDERS = {
|
|||||||
11: 'unknown_plural',
|
11: 'unknown_plural',
|
||||||
|
|
||||||
# For graphql requests
|
# For graphql requests
|
||||||
#'': 'unknown',
|
'UNKNOWN': 'unknown',
|
||||||
'FEMALE': 'female_singular',
|
'FEMALE': 'female_singular',
|
||||||
'MALE': 'male_singular',
|
'MALE': 'male_singular',
|
||||||
#'': 'female_singular_guess',
|
#'': 'female_singular_guess',
|
||||||
|
Reference in New Issue
Block a user