Compare commits

..

13 Commits

Author SHA1 Message Date
Mads Marquart
c51a332560 Version up, thanks to @PythonNut 2017-08-27 23:03:50 +02:00
Mads Marquart
a73d2feed6 Merge pull request #193 from PythonNut/master
Fix UNKNOWN gender in graphql requests
2017-08-27 23:02:05 +02:00
PythonNut
6929193e9d Fix UNKNOWN gender in graphql requests 2017-08-13 23:10:11 +00:00
Mads Marquart
fea4ad9e89 Version up, Thanks to ritu99 2017-08-10 15:25:38 +02:00
Mads Marquart
68099049d4 Merge pull request #189 from ritu99/master
Added Message Count to thread information
2017-08-10 15:22:22 +02:00
Ritvik Annam
44cf08bdfd fetchThreadInfo now pulls message_count 2017-08-10 01:15:29 -05:00
Ritvik Annam
9e32cf17a4 fetchThreadList now pulls message_count 2017-08-10 00:53:06 -05:00
Mads Marquart
0661367ebb Properly fixed #182 2017-08-02 23:08:34 +02:00
Mads Marquart
3c07e42ba2 Version up, fixed #182 2017-07-26 23:13:19 +02:00
Mads Marquart
2cd6376818 Merge pull request #178 from Bankde/fix-fail-after-running-for-days
Fix issue when running for long time
2017-07-26 23:03:49 +02:00
Mads Marquart
5e7f7750de Fixed enums in python 2.7, thanks to @liamkirsh 2017-07-12 14:52:15 +02:00
Bankde@hotmail.com
2a223ec6db fix array indexing (I don't know why fb do that) 2017-07-10 10:25:23 +07:00
Bankde@hotmail.com
637319ec2c add token update 2017-07-10 00:51:51 +07:00
6 changed files with 36 additions and 21 deletions

View File

@@ -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.13' __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'

View File

@@ -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`

View File

@@ -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:
rtn['nickname'] = info['participant_customizations'][1]
if len(info['participant_customizations']) > 1:
rtn['own_nickname'] = info['participant_customizations'][0]
else: else:
raise Exception('No participant matching the user {} found: {}'.format(_id, info['participant_customizations'])) rtn['own_nickname'] = pc[0].get('nickname')
if len(pc) > 1:
if pc[1].get('participant_id') == uid:
rtn['nickname'] = pc[1].get('nickname')
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):

View File

@@ -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__()

View File

@@ -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',

View File

@@ -1,3 +1,4 @@
requests requests
lxml lxml
beautifulsoup4 beautifulsoup4
enum34