signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
def _grep_status(self, status_type):
|
args = ("<STR_LIT>" % self.id).split()<EOL>res, _ = call(args)<EOL>exit_status = [line for line in res.split('<STR_LIT:\n>')<EOL>if '<STR_LIT>' in line]<EOL>try:<EOL><INDENT>_, __, code = exit_status[<NUM_LIT:0>].split()<EOL><DEDENT>except IndexError:<EOL><INDENT>code = None<EOL><DEDENT>if status_type == '<STR_LIT>' and code == '<STR_LIT:0>':<EOL><INDENT>return True<EOL><DEDENT>elif status_type == '<STR_LIT:error>' and code != '<STR_LIT:0>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>
|
Greps through the job's current status to see if
it returned with the requested status.
status_type: complete, error
|
f8691:c0:m8
|
def main():
|
parser = argparse.ArgumentParser(<EOL>description='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT:input>', nargs='<STR_LIT:?>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>'<EOL>'<STR_LIT>',<EOL>default=sys.stdout)<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', default='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>'<EOL>'<STR_LIT>',<EOL>default='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>',<EOL>action='<STR_LIT:store_true>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>',<EOL>default='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(JOB_TYPES.keys()),<EOL>default='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>'<EOL>'<STR_LIT>',<EOL>default=None)<EOL>parser.add_argument('<STR_LIT>',<EOL>help='<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(QUEUE_TYPES.keys()),<EOL>default='<STR_LIT:text>')<EOL>parser.add_argument('<STR_LIT>','<STR_LIT>',<EOL>help='<STR_LIT>',<EOL>action='<STR_LIT:store_true>')<EOL>args = parser.parse_args()<EOL>if args.version:<EOL><INDENT>print('<STR_LIT>'.format(__version__))<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>with open(args.input) as f:<EOL><INDENT>config = f.read()<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>print('<STR_LIT>')<EOL>return -<NUM_LIT:1><EOL><DEDENT>run(config, args.max_jobs, args.output, args.job_type, args.report_type,<EOL>args.shell, args.temp, args.run)<EOL>
|
Parses the command-line args, and calls run.
|
f8695:m0
|
def run(config, max_jobs, output=sys.stdout, job_type='<STR_LIT>',<EOL>report_type='<STR_LIT:text>', shell='<STR_LIT>', temp='<STR_LIT>', run_now=False):
|
if max_jobs == None:<EOL><INDENT>max_jobs = cpu_count()<EOL><DEDENT>parser = Parser(config)<EOL>try:<EOL><INDENT>command_templates = parser.consume()<EOL><DEDENT>except ValueError as e:<EOL><INDENT>raise SyntaxError('<STR_LIT>' % e)<EOL><DEDENT>options = '<STR_LIT:\n>'.join(parser.global_options)<EOL>queue_type = QUEUE_TYPES[report_type]<EOL>pipeline = Runtime(command_templates,queue_type,JOB_TYPES,job_type,max_jobs)<EOL>template = env.get_template('<STR_LIT>')<EOL>with open(temp, '<STR_LIT:wb>') as f:<EOL><INDENT>pickle.dump(pipeline, f, <NUM_LIT:2>)<EOL>script = template.render(shell=shell,<EOL>temp=os.path.abspath(temp), options=options)<EOL><DEDENT>if run_now:<EOL><INDENT>output = output if output != sys.stdout else PIPELINE_ALIAS<EOL>submit_job = make_submit_job(shell, output, job_type)<EOL>submit_job.submit()<EOL><DEDENT>try:<EOL><INDENT>f = open(output, '<STR_LIT:w>')<EOL>output = f<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT>output.write(script)<EOL>f.close()<EOL>
|
Create the metapipe based on the provided input.
|
f8695:m1
|
def make_submit_job(shell, output, job_type):
|
run_cmd = [shell, output]<EOL>submit_command = Command(alias=PIPELINE_ALIAS, cmds=run_cmd)<EOL>submit_job = get_job(submit_command, job_type)<EOL>submit_job.make()<EOL>return submit_job<EOL>
|
Preps the metapipe main job to be submitted.
|
f8695:m2
|
@classmethod<EOL><INDENT>def formatMentions(cls, text, *args, **kwargs):<DEDENT>
|
result = "<STR_LIT>"<EOL>mentions = list()<EOL>offset = <NUM_LIT:0><EOL>f = Formatter()<EOL>field_names = [field_name[<NUM_LIT:1>] for field_name in f.parse(text)]<EOL>automatic = "<STR_LIT>" in field_names<EOL>i = <NUM_LIT:0><EOL>for (literal_text, field_name, format_spec, conversion) in f.parse(text):<EOL><INDENT>offset += len(literal_text)<EOL>result += literal_text<EOL>if field_name is None:<EOL><INDENT>continue<EOL><DEDENT>if field_name == "<STR_LIT>":<EOL><INDENT>field_name = str(i)<EOL>i += <NUM_LIT:1><EOL><DEDENT>elif automatic and field_name.isdigit():<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>thread_id, name = f.get_field(field_name, args, kwargs)[<NUM_LIT:0>]<EOL>if format_spec:<EOL><INDENT>name = f.format_field(name, format_spec)<EOL><DEDENT>if conversion:<EOL><INDENT>name = f.convert_field(name, conversion)<EOL><DEDENT>result += name<EOL>mentions.append(<EOL>Mention(thread_id=thread_id, offset=offset, length=len(name))<EOL>)<EOL>offset += len(name)<EOL><DEDENT>message = cls(text=result, mentions=mentions)<EOL>return message<EOL>
|
Like `str.format`, but takes tuples with a thread id and text instead.
Returns a `Message` object, with the formatted string and relevant mentions.
```
>>> Message.formatMentions("Hey {!r}! My name is {}", ("1234", "Peter"), ("4321", "Michael"))
<Message (None): "Hey 'Peter'! My name is Michael", mentions=[<Mention 1234: offset=4 length=7>, <Mention 4321: offset=24 length=7>] emoji_size=None attachments=[]>
>>> Message.formatMentions("Hey {p}! My name is {}", ("1234", "Michael"), p=("4321", "Peter"))
<Message (None): 'Hey Peter! My name is Michael', mentions=[<Mention 4321: offset=4 length=5>, <Mention 1234: offset=22 length=7>] emoji_size=None attachments=[]>
```
|
f8714:c3:m0
|
@property<EOL><INDENT>def going(self):<DEDENT>
|
return [<EOL>id_<EOL>for id_, status in (self.guests or {}).items()<EOL>if status is GuestStatus.GOING<EOL>]<EOL>
|
List of the `User` IDs who will take part in the plan.
|
f8718:c1:m0
|
@property<EOL><INDENT>def declined(self):<DEDENT>
|
return [<EOL>id_<EOL>for id_, status in (self.guests or {}).items()<EOL>if status is GuestStatus.DECLINED<EOL>]<EOL>
|
List of the `User` IDs who won't take part in the plan.
|
f8718:c1:m1
|
@property<EOL><INDENT>def invited(self):<DEDENT>
|
return [<EOL>id_<EOL>for id_, status in (self.guests or {}).items()<EOL>if status is GuestStatus.INVITED<EOL>]<EOL>
|
List of the `User` IDs who are invited to the plan.
|
f8718:c1:m2
|
@property<EOL><INDENT>def uid(self):<DEDENT>
|
return self._uid<EOL>
|
The ID of the client.
Can be used as `thread_id`. See :ref:`intro_threads` for more info.
|
f8726:c0:m0
|
def __init__(<EOL>self,<EOL>email,<EOL>password,<EOL>user_agent=None,<EOL>max_tries=<NUM_LIT:5>,<EOL>session_cookies=None,<EOL>logging_level=logging.INFO,<EOL>):
|
self._sticky, self._pool = (None, None)<EOL>self._session = requests.session()<EOL>self._req_counter = <NUM_LIT:1><EOL>self._seq = "<STR_LIT:0>"<EOL>self._payload_default = OrderedDict()<EOL>self._default_thread_id = None<EOL>self._default_thread_type = None<EOL>self.req_url = ReqUrl()<EOL>self._markAlive = True<EOL>self._buddylist = dict()<EOL>if not user_agent:<EOL><INDENT>user_agent = choice(USER_AGENTS)<EOL><DEDENT>self._header = {<EOL>"<STR_LIT:Content-Type>": "<STR_LIT>",<EOL>"<STR_LIT>": self.req_url.BASE,<EOL>"<STR_LIT>": self.req_url.BASE,<EOL>"<STR_LIT>": user_agent,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>}<EOL>handler.setLevel(logging_level)<EOL>if (<EOL>not session_cookies<EOL>or not self.setSession(session_cookies)<EOL>or not self.isLoggedIn()<EOL>):<EOL><INDENT>self.login(email, password, max_tries)<EOL><DEDENT>
|
Initializes and logs in the client
:param email: Facebook `email`, `id` or `phone number`
:param password: Facebook account password
:param user_agent: Custom user agent to use when sending requests. If `None`, user agent will be chosen from a premade list (see :any:`utils.USER_AGENTS`)
:param max_tries: Maximum number of times to try logging in
:param session_cookies: Cookies from a previous session (Will default to login if these are invalid)
:param logging_level: Configures the `logging level <https://docs.python.org/3/library/logging.html#logging-levels>`_. Defaults to `INFO`
:type max_tries: int
:type session_cookies: dict
:type logging_level: int
:raises: FBchatException on failed login
|
f8726:c0:m1
|
def _generatePayload(self, query):
|
payload = self._payload_default.copy()<EOL>if query:<EOL><INDENT>payload.update(query)<EOL><DEDENT>payload["<STR_LIT>"] = str_base(self._req_counter, <NUM_LIT>)<EOL>payload["<STR_LIT>"] = self._seq<EOL>self._req_counter += <NUM_LIT:1><EOL>return payload<EOL>
|
Adds the following defaults to the payload:
__rev, __user, __a, ttstamp, fb_dtsg, __req
|
f8726:c0:m2
|
def _fix_fb_errors(self, error_code):
|
if error_code == "<STR_LIT>":<EOL><INDENT>log.warning("<STR_LIT>")<EOL>self._postLogin()<EOL>return True<EOL><DEDENT>return False<EOL>
|
This fixes "Please try closing and re-opening your browser window" errors (1357004)
This error usually happens after 1-2 days of inactivity
It may be a bad idea to do this in an exception handler, if you have a better method, please suggest it!
|
f8726:c0:m3
|
def graphql_requests(self, *queries):
|
data = {<EOL>"<STR_LIT>": "<STR_LIT:GET>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": graphql_queries_to_json(*queries),<EOL>}<EOL>return tuple(<EOL>self._post(self.req_url.GRAPHQL, data, fix_request=True, as_graphql=True)<EOL>)<EOL>
|
:param queries: Zero or more GraphQL objects
:type queries: GraphQL
:raises: FBchatException if request failed
:return: A tuple containing json graphql queries
:rtype: tuple
|
f8726:c0:m9
|
def graphql_request(self, query):
|
return self.graphql_requests(query)[<NUM_LIT:0>]<EOL>
|
Shorthand for `graphql_requests(query)[0]`
:raises: FBchatException if request failed
|
f8726:c0:m10
|
def isLoggedIn(self):
|
<EOL>r = self._cleanGet(self.req_url.LOGIN, allow_redirects=False)<EOL>return "<STR_LIT>" in r.headers and "<STR_LIT>" in r.headers["<STR_LIT>"]<EOL>
|
Sends a request to Facebook to check the login status
:return: True if the client is still logged in
:rtype: bool
|
f8726:c0:m15
|
def getSession(self):
|
return self._session.cookies.get_dict()<EOL>
|
Retrieves session cookies
:return: A dictionay containing session cookies
:rtype: dict
|
f8726:c0:m16
|
def setSession(self, session_cookies):
|
<EOL>if not session_cookies or "<STR_LIT>" not in session_cookies:<EOL><INDENT>return False<EOL><DEDENT>try:<EOL><INDENT>self._session.cookies = requests.cookies.merge_cookies(<EOL>self._session.cookies, session_cookies<EOL>)<EOL>self._postLogin()<EOL><DEDENT>except Exception as e:<EOL><INDENT>log.exception("<STR_LIT>")<EOL>self._resetValues()<EOL>return False<EOL><DEDENT>return True<EOL>
|
Loads session cookies
:param session_cookies: A dictionay containing session cookies
:type session_cookies: dict
:return: False if `session_cookies` does not contain proper cookies
:rtype: bool
|
f8726:c0:m17
|
def login(self, email, password, max_tries=<NUM_LIT:5>):
|
self.onLoggingIn(email=email)<EOL>if max_tries < <NUM_LIT:1>:<EOL><INDENT>raise FBchatUserError("<STR_LIT>")<EOL><DEDENT>if not (email and password):<EOL><INDENT>raise FBchatUserError("<STR_LIT>")<EOL><DEDENT>for i in range(<NUM_LIT:1>, max_tries + <NUM_LIT:1>):<EOL><INDENT>login_successful, login_url = self._login(email, password)<EOL>if not login_successful:<EOL><INDENT>log.warning(<EOL>"<STR_LIT>".format(<EOL>i, {True: "<STR_LIT>"}.get(i < max_tries, "<STR_LIT>")<EOL>)<EOL>)<EOL>time.sleep(<NUM_LIT:1>)<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>self.onLoggedIn(email=email)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise FBchatUserError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(login_url)<EOL>)<EOL><DEDENT>
|
Uses `email` and `password` to login the user (If the user is already logged in, this will do a re-login)
:param email: Facebook `email` or `id` or `phone number`
:param password: Facebook account password
:param max_tries: Maximum number of times to try logging in
:type max_tries: int
:raises: FBchatException on failed login
|
f8726:c0:m18
|
def logout(self):
|
if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>h_r = self._post(self.req_url.MODERN_SETTINGS_MENU, {"<STR_LIT>": "<STR_LIT:4>"})<EOL>self._fb_h = re.search(r'<STR_LIT>', h_r.text).group(<NUM_LIT:1>)<EOL><DEDENT>data = {"<STR_LIT>": "<STR_LIT>", "<STR_LIT:h>": self._fb_h}<EOL>r = self._get(self.req_url.LOGOUT, data)<EOL>self._resetValues()<EOL>return r.ok<EOL>
|
Safely logs out the client
:param timeout: See `requests timeout <http://docs.python-requests.org/en/master/user/advanced/#timeouts>`_
:return: True if the action was successful
:rtype: bool
|
f8726:c0:m19
|
def _getThread(self, given_thread_id=None, given_thread_type=None):
|
if given_thread_id is None:<EOL><INDENT>if self._default_thread_id is not None:<EOL><INDENT>return self._default_thread_id, self._default_thread_type<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return given_thread_id, given_thread_type<EOL><DEDENT>
|
Checks if thread ID is given, checks if default is set and returns correct values
:raises ValueError: If thread ID is not given and there is no default
:return: Thread ID and thread type
:rtype: tuple
|
f8726:c0:m20
|
def setDefaultThread(self, thread_id, thread_type):
|
self._default_thread_id = thread_id<EOL>self._default_thread_type = thread_type<EOL>
|
Sets default thread to send messages to
:param thread_id: User/Group ID to default to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
|
f8726:c0:m21
|
def resetDefaultThread(self):
|
self.setDefaultThread(None, None)<EOL>
|
Resets default thread
|
f8726:c0:m22
|
def fetchThreads(self, thread_location, before=None, after=None, limit=None):
|
threads = []<EOL>last_thread_timestamp = None<EOL>while True:<EOL><INDENT>if limit and len(threads) >= limit:<EOL><INDENT>break<EOL><DEDENT>candidates = self.fetchThreadList(<EOL>before=last_thread_timestamp, thread_location=thread_location<EOL>)<EOL>if len(candidates) > <NUM_LIT:1>:<EOL><INDENT>threads += candidates[<NUM_LIT:1>:]<EOL><DEDENT>else: <EOL><INDENT>break<EOL><DEDENT>last_thread_timestamp = threads[-<NUM_LIT:1>].last_message_timestamp<EOL>if (before is not None and int(last_thread_timestamp) > before) or (<EOL>after is not None and int(last_thread_timestamp) < after<EOL>):<EOL><INDENT>break<EOL><DEDENT><DEDENT>if before is not None or after is not None:<EOL><INDENT>for t in threads:<EOL><INDENT>last_message_timestamp = int(t.last_message_timestamp)<EOL>if (before is not None and last_message_timestamp > before) or (<EOL>after is not None and last_message_timestamp < after<EOL>):<EOL><INDENT>threads.remove(t)<EOL><DEDENT><DEDENT><DEDENT>if limit and len(threads) > limit:<EOL><INDENT>return threads[:limit]<EOL><DEDENT>return threads<EOL>
|
Get all threads in thread_location.
Threads will be sorted from newest to oldest.
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param before: Fetch only thread before this epoch (in ms) (default all threads)
:param after: Fetch only thread after this epoch (in ms) (default all threads)
:param limit: The max. amount of threads to fetch (default all threads)
:return: :class:`models.Thread` objects
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m24
|
def fetchAllUsersFromThreads(self, threads):
|
users = []<EOL>users_to_fetch = [] <EOL>for thread in threads:<EOL><INDENT>if thread.type == ThreadType.USER:<EOL><INDENT>if thread.uid not in [user.uid for user in users]:<EOL><INDENT>users.append(thread)<EOL><DEDENT><DEDENT>elif thread.type == ThreadType.GROUP:<EOL><INDENT>for user_id in thread.participants:<EOL><INDENT>if (<EOL>user_id not in [user.uid for user in users]<EOL>and user_id not in users_to_fetch<EOL>):<EOL><INDENT>users_to_fetch.append(user_id)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>for user_id, user in self.fetchUserInfo(*users_to_fetch).items():<EOL><INDENT>users.append(user)<EOL><DEDENT>return users<EOL>
|
Get all users involved in threads.
:param threads: models.Thread: List of threads to check for users
:return: :class:`models.User` objects
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m25
|
def fetchAllUsers(self):
|
data = {"<STR_LIT>": self._uid}<EOL>j = self._post(<EOL>self.req_url.ALL_USERS, query=data, fix_request=True, as_json=True<EOL>)<EOL>if j.get("<STR_LIT>") is None:<EOL><INDENT>raise FBchatException("<STR_LIT>".format(j))<EOL><DEDENT>users = []<EOL>for data in j["<STR_LIT>"].values():<EOL><INDENT>if data["<STR_LIT:type>"] in ["<STR_LIT:user>", "<STR_LIT>"]:<EOL><INDENT>if data["<STR_LIT:id>"] in ["<STR_LIT:0>", <NUM_LIT:0>]:<EOL><INDENT>continue<EOL><DEDENT>users.append(User._from_all_fetch(data))<EOL><DEDENT><DEDENT>return users<EOL>
|
Gets all users the client is currently chatting with
:return: :class:`models.User` objects
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m26
|
def searchForUsers(self, name, limit=<NUM_LIT:10>):
|
params = {"<STR_LIT>": name, "<STR_LIT>": limit}<EOL>j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_USER, params=params))<EOL>return [User._from_graphql(node) for node in j[name]["<STR_LIT>"]["<STR_LIT>"]]<EOL>
|
Find and get user by his/her name
:param name: Name of the user
:param limit: The max. amount of users to fetch
:return: :class:`models.User` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m27
|
def searchForPages(self, name, limit=<NUM_LIT:10>):
|
params = {"<STR_LIT>": name, "<STR_LIT>": limit}<EOL>j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_PAGE, params=params))<EOL>return [Page._from_graphql(node) for node in j[name]["<STR_LIT>"]["<STR_LIT>"]]<EOL>
|
Find and get page by its name
:param name: Name of the page
:return: :class:`models.Page` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m28
|
def searchForGroups(self, name, limit=<NUM_LIT:10>):
|
params = {"<STR_LIT>": name, "<STR_LIT>": limit}<EOL>j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_GROUP, params=params))<EOL>return [Group._from_graphql(node) for node in j["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]]<EOL>
|
Find and get group thread by its name
:param name: Name of the group thread
:param limit: The max. amount of groups to fetch
:return: :class:`models.Group` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m29
|
def searchForThreads(self, name, limit=<NUM_LIT:10>):
|
params = {"<STR_LIT>": name, "<STR_LIT>": limit}<EOL>j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_THREAD, params=params))<EOL>rtn = []<EOL>for node in j[name]["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>if node["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>rtn.append(User._from_graphql(node))<EOL><DEDENT>elif node["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>rtn.append(Group._from_graphql(node))<EOL><DEDENT>elif node["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>rtn.append(Page._from_graphql(node))<EOL><DEDENT>elif node["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>log.warning(<EOL>"<STR_LIT>".format(repr(node["<STR_LIT>"]), node)<EOL>)<EOL><DEDENT><DEDENT>return rtn<EOL>
|
Find and get a thread by its name
:param name: Name of the thread
:param limit: The max. amount of groups to fetch
:return: :class:`models.User`, :class:`models.Group` and :class:`models.Page` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m30
|
def searchForMessageIDs(self, query, offset=<NUM_LIT:0>, limit=<NUM_LIT:5>, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {<EOL>"<STR_LIT>": query,<EOL>"<STR_LIT>": offset,<EOL>"<STR_LIT>": limit,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": thread_id,<EOL>}<EOL>j = self._post(<EOL>self.req_url.SEARCH_MESSAGES, data, fix_request=True, as_json=True<EOL>)<EOL>result = j["<STR_LIT>"]["<STR_LIT>"][query]<EOL>snippets = result[thread_id]["<STR_LIT>"] if result.get(thread_id) else []<EOL>for snippet in snippets:<EOL><INDENT>yield snippet["<STR_LIT>"]<EOL><DEDENT>
|
Find and get message IDs by query
:param query: Text to search for
:param offset: Number of messages to skip
:param limit: Max. number of messages to retrieve
:param thread_id: User/Group ID to search in. See :ref:`intro_threads`
:type offset: int
:type limit: int
:return: Found Message IDs
:rtype: generator
:raises: FBchatException if request failed
|
f8726:c0:m31
|
def searchForMessages(self, query, offset=<NUM_LIT:0>, limit=<NUM_LIT:5>, thread_id=None):
|
message_ids = self.searchForMessageIDs(<EOL>query, offset=offset, limit=limit, thread_id=thread_id<EOL>)<EOL>for mid in message_ids:<EOL><INDENT>yield self.fetchMessageInfo(mid, thread_id)<EOL><DEDENT>
|
Find and get :class:`models.Message` objects by query
.. warning::
This method sends request for every found message ID.
:param query: Text to search for
:param offset: Number of messages to skip
:param limit: Max. number of messages to retrieve
:param thread_id: User/Group ID to search in. See :ref:`intro_threads`
:type offset: int
:type limit: int
:return: Found :class:`models.Message` objects
:rtype: generator
:raises: FBchatException if request failed
|
f8726:c0:m32
|
def search(self, query, fetch_messages=False, thread_limit=<NUM_LIT:5>, message_limit=<NUM_LIT:5>):
|
data = {"<STR_LIT>": query, "<STR_LIT>": thread_limit}<EOL>j = self._post(<EOL>self.req_url.SEARCH_MESSAGES, data, fix_request=True, as_json=True<EOL>)<EOL>result = j["<STR_LIT>"]["<STR_LIT>"][query]<EOL>if fetch_messages:<EOL><INDENT>search_method = self.searchForMessages<EOL><DEDENT>else:<EOL><INDENT>search_method = self.searchForMessageIDs<EOL><DEDENT>return {<EOL>thread_id: search_method(query, limit=message_limit, thread_id=thread_id)<EOL>for thread_id in result<EOL>}<EOL>
|
Searches for messages in all threads
:param query: Text to search for
:param fetch_messages: Whether to fetch :class:`models.Message` objects or IDs only
:param thread_limit: Max. number of threads to retrieve
:param message_limit: Max. number of messages to retrieve
:type thread_limit: int
:type message_limit: int
:return: Dictionary with thread IDs as keys and generators to get messages as values
:rtype: generator
:raises: FBchatException if request failed
|
f8726:c0:m33
|
def fetchUserInfo(self, *user_ids):
|
threads = self.fetchThreadInfo(*user_ids)<EOL>users = {}<EOL>for id_, thread in threads.items():<EOL><INDENT>if thread.type == ThreadType.USER:<EOL><INDENT>users[id_] = thread<EOL><DEDENT>else:<EOL><INDENT>raise FBchatUserError("<STR_LIT>".format(thread))<EOL><DEDENT><DEDENT>return users<EOL>
|
Get users' info from IDs, unordered
.. warning::
Sends two requests, to fetch all available info!
:param user_ids: One or more user ID(s) to query
:return: :class:`models.User` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
|
f8726:c0:m35
|
def fetchPageInfo(self, *page_ids):
|
threads = self.fetchThreadInfo(*page_ids)<EOL>pages = {}<EOL>for id_, thread in threads.items():<EOL><INDENT>if thread.type == ThreadType.PAGE:<EOL><INDENT>pages[id_] = thread<EOL><DEDENT>else:<EOL><INDENT>raise FBchatUserError("<STR_LIT>".format(thread))<EOL><DEDENT><DEDENT>return pages<EOL>
|
Get pages' info from IDs, unordered
.. warning::
Sends two requests, to fetch all available info!
:param page_ids: One or more page ID(s) to query
:return: :class:`models.Page` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
|
f8726:c0:m36
|
def fetchGroupInfo(self, *group_ids):
|
threads = self.fetchThreadInfo(*group_ids)<EOL>groups = {}<EOL>for id_, thread in threads.items():<EOL><INDENT>if thread.type == ThreadType.GROUP:<EOL><INDENT>groups[id_] = thread<EOL><DEDENT>else:<EOL><INDENT>raise FBchatUserError("<STR_LIT>".format(thread))<EOL><DEDENT><DEDENT>return groups<EOL>
|
Get groups' info from IDs, unordered
:param group_ids: One or more group ID(s) to query
:return: :class:`models.Group` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
|
f8726:c0:m37
|
def fetchThreadInfo(self, *thread_ids):
|
queries = []<EOL>for thread_id in thread_ids:<EOL><INDENT>params = {<EOL>"<STR_LIT:id>": thread_id,<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": False,<EOL>"<STR_LIT>": False,<EOL>"<STR_LIT>": None,<EOL>}<EOL>queries.append(GraphQL(doc_id="<STR_LIT>", params=params))<EOL><DEDENT>j = self.graphql_requests(*queries)<EOL>for i, entry in enumerate(j):<EOL><INDENT>if entry.get("<STR_LIT>") is None:<EOL><INDENT>j[i]["<STR_LIT>"] = {<EOL>"<STR_LIT>": {"<STR_LIT>": thread_ids[i]},<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>}<EOL><DEDENT><DEDENT>pages_and_user_ids = [<EOL>k["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>for k in j<EOL>if k["<STR_LIT>"].get("<STR_LIT>") == "<STR_LIT>"<EOL>]<EOL>pages_and_users = {}<EOL>if len(pages_and_user_ids) != <NUM_LIT:0>:<EOL><INDENT>pages_and_users = self._fetchInfo(*pages_and_user_ids)<EOL><DEDENT>rtn = {}<EOL>for i, entry in enumerate(j):<EOL><INDENT>entry = entry["<STR_LIT>"]<EOL>if entry.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>_id = entry["<STR_LIT>"]["<STR_LIT>"]<EOL>rtn[_id] = Group._from_graphql(entry)<EOL><DEDENT>elif entry.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>_id = entry["<STR_LIT>"]["<STR_LIT>"]<EOL>if pages_and_users.get(_id) is None:<EOL><INDENT>raise FBchatException("<STR_LIT>".format(_id))<EOL><DEDENT>entry.update(pages_and_users[_id])<EOL>if entry["<STR_LIT:type>"] == ThreadType.USER:<EOL><INDENT>rtn[_id] = User._from_graphql(entry)<EOL><DEDENT>else:<EOL><INDENT>rtn[_id] = Page._from_graphql(entry)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise FBchatException(<EOL>"<STR_LIT>".format(thread_ids[i], entry)<EOL>)<EOL><DEDENT><DEDENT>return rtn<EOL>
|
Get threads' info from IDs, unordered
.. warning::
Sends two requests if users or pages are present, to fetch all available info!
:param thread_ids: One or more thread ID(s) to query
:return: :class:`models.Thread` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
|
f8726:c0:m38
|
def fetchThreadMessages(self, thread_id=None, limit=<NUM_LIT:20>, before=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>params = {<EOL>"<STR_LIT:id>": thread_id,<EOL>"<STR_LIT>": limit,<EOL>"<STR_LIT>": True,<EOL>"<STR_LIT>": True,<EOL>"<STR_LIT>": before,<EOL>}<EOL>j = self.graphql_request(GraphQL(doc_id="<STR_LIT>", params=params))<EOL>if j.get("<STR_LIT>") is None:<EOL><INDENT>raise FBchatException("<STR_LIT>".format(thread_id, j))<EOL><DEDENT>messages = [<EOL>Message._from_graphql(message)<EOL>for message in j["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>]<EOL>messages.reverse()<EOL>read_receipts = j["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>for message in messages:<EOL><INDENT>for receipt in read_receipts:<EOL><INDENT>if int(receipt["<STR_LIT>"]) >= int(message.timestamp):<EOL><INDENT>message.read_by.append(receipt["<STR_LIT>"]["<STR_LIT:id>"])<EOL><DEDENT><DEDENT><DEDENT>return messages<EOL>
|
Get the last messages in a thread
:param thread_id: User/Group ID to get messages from. See :ref:`intro_threads`
:param limit: Max. number of messages to retrieve
:param before: A timestamp, indicating from which point to retrieve messages
:type limit: int
:type before: int
:return: :class:`models.Message` objects
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m39
|
def fetchThreadList(<EOL>self, offset=None, limit=<NUM_LIT:20>, thread_location=ThreadLocation.INBOX, before=None<EOL>):
|
if offset is not None:<EOL><INDENT>log.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if limit > <NUM_LIT:20> or limit < <NUM_LIT:1>:<EOL><INDENT>raise FBchatUserError("<STR_LIT>")<EOL><DEDENT>if thread_location in ThreadLocation:<EOL><INDENT>loc_str = thread_location.value<EOL><DEDENT>else:<EOL><INDENT>raise FBchatUserError('<STR_LIT>')<EOL><DEDENT>params = {<EOL>"<STR_LIT>": limit,<EOL>"<STR_LIT>": [loc_str],<EOL>"<STR_LIT>": before,<EOL>"<STR_LIT>": True,<EOL>"<STR_LIT>": False,<EOL>}<EOL>j = self.graphql_request(GraphQL(doc_id="<STR_LIT>", params=params))<EOL>rtn = []<EOL>for node in j["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>_type = node.get("<STR_LIT>")<EOL>if _type == "<STR_LIT>":<EOL><INDENT>rtn.append(Group._from_graphql(node))<EOL><DEDENT>elif _type == "<STR_LIT>":<EOL><INDENT>rtn.append(User._from_thread_fetch(node))<EOL><DEDENT>else:<EOL><INDENT>raise FBchatException(<EOL>"<STR_LIT>".format(_type, node)<EOL>)<EOL><DEDENT><DEDENT>return rtn<EOL>
|
Get thread list of your facebook account
:param offset: Deprecated. Do not use!
:param limit: Max. number of threads to retrieve. Capped at 20
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param before: A timestamp (in milliseconds), indicating from which point to retrieve threads
:type limit: int
:type before: int
:return: :class:`models.Thread` objects
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m40
|
def fetchUnread(self):
|
form = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": now() - <NUM_LIT> * <NUM_LIT:1000><EOL>}<EOL>j = self._post(<EOL>self.req_url.UNREAD_THREADS, form, fix_request=True, as_json=True<EOL>)<EOL>payload = j["<STR_LIT>"]["<STR_LIT>"][<NUM_LIT:0>]<EOL>return payload["<STR_LIT>"] + payload["<STR_LIT>"]<EOL>
|
Get the unread thread list
:return: List of unread thread ids
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m41
|
def fetchUnseen(self):
|
j = self._post(<EOL>self.req_url.UNSEEN_THREADS, None, fix_request=True, as_json=True<EOL>)<EOL>payload = j["<STR_LIT>"]["<STR_LIT>"][<NUM_LIT:0>]<EOL>return payload["<STR_LIT>"] + payload["<STR_LIT>"]<EOL>
|
Get the unseen (new) thread list
:return: List of unseen thread ids
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m42
|
def fetchImageUrl(self, image_id):
|
image_id = str(image_id)<EOL>data = {"<STR_LIT>": str(image_id)}<EOL>j = self._get(<EOL>ReqUrl.ATTACHMENT_PHOTO, query=data, fix_request=True, as_json=True<EOL>)<EOL>url = get_jsmods_require(j, <NUM_LIT:3>)<EOL>if url is None:<EOL><INDENT>raise FBchatException("<STR_LIT>".format(j))<EOL><DEDENT>return url<EOL>
|
Fetches the url to the original image from an image attachment ID
:param image_id: The image you want to fethc
:type image_id: str
:return: An url where you can download the original image
:rtype: str
:raises: FBchatException if request failed
|
f8726:c0:m43
|
def fetchMessageInfo(self, mid, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>message_info = self._forcedFetch(thread_id, mid).get("<STR_LIT:message>")<EOL>return Message._from_graphql(message_info)<EOL>
|
Fetches :class:`models.Message` object from the message id
:param mid: Message ID to fetch from
:param thread_id: User/Group ID to get message info from. See :ref:`intro_threads`
:return: :class:`models.Message` object
:rtype: models.Message
:raises: FBchatException if request failed
|
f8726:c0:m44
|
def fetchPollOptions(self, poll_id):
|
data = {"<STR_LIT>": poll_id}<EOL>j = self._post(<EOL>self.req_url.GET_POLL_OPTIONS, data, fix_request=True, as_json=True<EOL>)<EOL>return [PollOption._from_graphql(m) for m in j["<STR_LIT>"]]<EOL>
|
Fetches list of :class:`models.PollOption` objects from the poll id
:param poll_id: Poll ID to fetch from
:rtype: list
:raises: FBchatException if request failed
|
f8726:c0:m45
|
def fetchPlanInfo(self, plan_id):
|
data = {"<STR_LIT>": plan_id}<EOL>j = self._post(self.req_url.PLAN_INFO, data, fix_request=True, as_json=True)<EOL>return Plan._from_fetch(j["<STR_LIT>"])<EOL>
|
Fetches a :class:`models.Plan` object from the plan id
:param plan_id: Plan ID to fetch from
:return: :class:`models.Plan` object
:rtype: models.Plan
:raises: FBchatException if request failed
|
f8726:c0:m46
|
def getPhoneNumbers(self):
|
data = self._getPrivateData()<EOL>return [<EOL>j["<STR_LIT>"]["<STR_LIT>"] for j in data["<STR_LIT:user>"]["<STR_LIT>"]<EOL>]<EOL>
|
Fetches a list of user phone numbers.
:return: List of phone numbers
:rtype: list
|
f8726:c0:m48
|
def getEmails(self):
|
data = self._getPrivateData()<EOL>return [j["<STR_LIT>"] for j in data["<STR_LIT>"]]<EOL>
|
Fetches a list of user emails.
:return: List of emails
:rtype: list
|
f8726:c0:m49
|
def getUserActiveStatus(self, user_id):
|
return self._buddylist.get(str(user_id))<EOL>
|
Gets friend active status as an :class:`models.ActiveStatus` object.
Returns `None` if status isn't known.
.. warning::
Only works when listening.
:param user_id: ID of the user
:return: Given user active status
:rtype: models.ActiveStatus
|
f8726:c0:m50
|
def _getSendData(self, message=None, thread_id=None, thread_type=ThreadType.USER):
|
messageAndOTID = generateOfflineThreadingID()<EOL>timestamp = now()<EOL>data = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>".format(self._uid),<EOL>"<STR_LIT>": timestamp,<EOL>"<STR_LIT:source>": "<STR_LIT>",<EOL>"<STR_LIT>": messageAndOTID,<EOL>"<STR_LIT>": messageAndOTID,<EOL>"<STR_LIT>": generateMessageID(self._client_id),<EOL>"<STR_LIT>": "<STR_LIT:0>",<EOL>}<EOL>if thread_type in [ThreadType.USER, ThreadType.PAGE]:<EOL><INDENT>data["<STR_LIT>"] = thread_id<EOL><DEDENT>elif thread_type == ThreadType.GROUP:<EOL><INDENT>data["<STR_LIT>"] = thread_id<EOL><DEDENT>if message is None:<EOL><INDENT>message = Message()<EOL><DEDENT>if message.text or message.sticker or message.emoji_size:<EOL><INDENT>data["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT>if message.text:<EOL><INDENT>data["<STR_LIT:body>"] = message.text<EOL><DEDENT>for i, mention in enumerate(message.mentions):<EOL><INDENT>data["<STR_LIT>".format(i)] = mention.thread_id<EOL>data["<STR_LIT>".format(i)] = mention.offset<EOL>data["<STR_LIT>".format(i)] = mention.length<EOL>data["<STR_LIT>".format(i)] = "<STR_LIT:p>"<EOL><DEDENT>if message.emoji_size:<EOL><INDENT>if message.text:<EOL><INDENT>data["<STR_LIT>"] = "<STR_LIT>" + message.emoji_size.name.lower()<EOL><DEDENT>else:<EOL><INDENT>data["<STR_LIT>"] = message.emoji_size.value<EOL><DEDENT><DEDENT>if message.sticker:<EOL><INDENT>data["<STR_LIT>"] = message.sticker.uid<EOL><DEDENT>if message.quick_replies:<EOL><INDENT>xmd = {"<STR_LIT>": []}<EOL>for quick_reply in message.quick_replies:<EOL><INDENT>q = dict()<EOL>q["<STR_LIT>"] = quick_reply._type<EOL>q["<STR_LIT>"] = quick_reply.payload<EOL>q["<STR_LIT>"] = quick_reply.external_payload<EOL>q["<STR_LIT:data>"] = quick_reply.data<EOL>if quick_reply.is_response:<EOL><INDENT>q["<STR_LIT>"] = False<EOL><DEDENT>if isinstance(quick_reply, QuickReplyText):<EOL><INDENT>q["<STR_LIT:title>"] = quick_reply.title<EOL><DEDENT>if not isinstance(quick_reply, QuickReplyLocation):<EOL><INDENT>q["<STR_LIT>"] = quick_reply.image_url<EOL><DEDENT>xmd["<STR_LIT>"].append(q)<EOL><DEDENT>if len(message.quick_replies) == <NUM_LIT:1> and message.quick_replies[<NUM_LIT:0>].is_response:<EOL><INDENT>xmd["<STR_LIT>"] = xmd["<STR_LIT>"][<NUM_LIT:0>]<EOL><DEDENT>data["<STR_LIT>"] = json.dumps(xmd)<EOL><DEDENT>if message.reply_to_id:<EOL><INDENT>data["<STR_LIT>"] = message.reply_to_id<EOL><DEDENT>return data<EOL>
|
Returns the data needed to send a request to `SendURL`
|
f8726:c0:m52
|
def _doSendRequest(self, data, get_thread_id=False):
|
j = self._post(self.req_url.SEND, data, fix_request=True, as_json=True)<EOL>fb_dtsg = get_jsmods_require(j, <NUM_LIT:2>)<EOL>if fb_dtsg is not None:<EOL><INDENT>self._payload_default["<STR_LIT>"] = fb_dtsg<EOL><DEDENT>try:<EOL><INDENT>message_ids = [<EOL>(action["<STR_LIT>"], action["<STR_LIT>"])<EOL>for action in j["<STR_LIT>"]["<STR_LIT>"]<EOL>if "<STR_LIT>" in action<EOL>]<EOL>if len(message_ids) != <NUM_LIT:1>:<EOL><INDENT>log.warning("<STR_LIT>".format(message_ids))<EOL><DEDENT>if get_thread_id:<EOL><INDENT>return message_ids[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return message_ids[<NUM_LIT:0>][<NUM_LIT:0>]<EOL><DEDENT><DEDENT>except (KeyError, IndexError, TypeError) as e:<EOL><INDENT>raise FBchatException(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(j)<EOL>)<EOL><DEDENT>
|
Sends the data to `SendURL`, and returns the message ID or None on failure
|
f8726:c0:m53
|
def send(self, message, thread_id=None, thread_type=ThreadType.USER):
|
thread_id, thread_type = self._getThread(thread_id, thread_type)<EOL>data = self._getSendData(<EOL>message=message, thread_id=thread_id, thread_type=thread_type<EOL>)<EOL>return self._doSendRequest(data)<EOL>
|
Sends a message to a thread
:param message: Message to send
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
|
f8726:c0:m54
|
def sendMessage(self, message, thread_id=None, thread_type=ThreadType.USER):
|
return self.send(<EOL>Message(text=message), thread_id=thread_id, thread_type=thread_type<EOL>)<EOL>
|
Deprecated. Use :func:`fbchat.Client.send` instead
|
f8726:c0:m55
|
def sendEmoji(<EOL>self,<EOL>emoji=None,<EOL>size=EmojiSize.SMALL,<EOL>thread_id=None,<EOL>thread_type=ThreadType.USER,<EOL>):
|
return self.send(<EOL>Message(text=emoji, emoji_size=size),<EOL>thread_id=thread_id,<EOL>thread_type=thread_type,<EOL>)<EOL>
|
Deprecated. Use :func:`fbchat.Client.send` instead
|
f8726:c0:m56
|
def wave(self, wave_first=True, thread_id=None, thread_type=None):
|
thread_id, thread_type = self._getThread(thread_id, thread_type)<EOL>data = self._getSendData(thread_id=thread_id, thread_type=thread_type)<EOL>data["<STR_LIT>"] = "<STR_LIT>"<EOL>data["<STR_LIT>"] = (<EOL>"<STR_LIT>" if wave_first else "<STR_LIT>"<EOL>)<EOL>data["<STR_LIT>"] = "<STR_LIT>"<EOL>if thread_type == ThreadType.USER:<EOL><INDENT>data["<STR_LIT>"] = "<STR_LIT>".format(thread_id)<EOL><DEDENT>return self._doSendRequest(data)<EOL>
|
Says hello with a wave to a thread!
:param wave_first: Whether to wave first or wave back
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
|
f8726:c0:m57
|
def quickReply(self, quick_reply, payload=None, thread_id=None, thread_type=None):
|
quick_reply.is_response = True<EOL>if isinstance(quick_reply, QuickReplyText):<EOL><INDENT>return self.send(<EOL>Message(text=quick_reply.title, quick_replies=[quick_reply])<EOL>)<EOL><DEDENT>elif isinstance(quick_reply, QuickReplyLocation):<EOL><INDENT>if not isinstance(payload, LocationAttachment):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>return self.sendLocation(<EOL>payload, thread_id=thread_id, thread_type=thread_type<EOL>)<EOL><DEDENT>elif isinstance(quick_reply, QuickReplyEmail):<EOL><INDENT>if not payload:<EOL><INDENT>payload = self.getEmails()[<NUM_LIT:0>]<EOL><DEDENT>quick_reply.external_payload = quick_reply.payload<EOL>quick_reply.payload = payload<EOL>return self.send(Message(text=payload, quick_replies=[quick_reply]))<EOL><DEDENT>elif isinstance(quick_reply, QuickReplyPhoneNumber):<EOL><INDENT>if not payload:<EOL><INDENT>payload = self.getPhoneNumbers()[<NUM_LIT:0>]<EOL><DEDENT>quick_reply.external_payload = quick_reply.payload<EOL>quick_reply.payload = payload<EOL>return self.send(Message(text=payload, quick_replies=[quick_reply]))<EOL><DEDENT>
|
Replies to a chosen quick reply
:param quick_reply: Quick reply to reply to
:param payload: Optional answer to the quick reply
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type quick_reply: models.QuickReply
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
|
f8726:c0:m58
|
def unsend(self, mid):
|
data = {"<STR_LIT>": mid}<EOL>r = self._post(self.req_url.UNSEND, data)<EOL>r.raise_for_status()<EOL>
|
Unsends a message (removes for everyone)
:param mid: :ref:`Message ID <intro_message_ids>` of the message to unsend
|
f8726:c0:m59
|
def sendLocation(self, location, message=None, thread_id=None, thread_type=None):
|
self._sendLocation(<EOL>location=location,<EOL>current=True,<EOL>message=message,<EOL>thread_id=thread_id,<EOL>thread_type=thread_type,<EOL>)<EOL>
|
Sends a given location to a thread as the user's current location
:param location: Location to send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type location: models.LocationAttachment
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
|
f8726:c0:m61
|
def sendPinnedLocation(<EOL>self, location, message=None, thread_id=None, thread_type=None<EOL>):
|
self._sendLocation(<EOL>location=location,<EOL>current=False,<EOL>message=message,<EOL>thread_id=thread_id,<EOL>thread_type=thread_type,<EOL>)<EOL>
|
Sends a given location to a thread as a pinned location
:param location: Location to send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type location: models.LocationAttachment
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
|
f8726:c0:m62
|
def _upload(self, files, voice_clip=False):
|
file_dict = {"<STR_LIT>".format(i): f for i, f in enumerate(files)}<EOL>data = {"<STR_LIT>": voice_clip}<EOL>j = self._postFile(<EOL>self.req_url.UPLOAD,<EOL>files=file_dict,<EOL>query=data,<EOL>fix_request=True,<EOL>as_json=True,<EOL>)<EOL>if len(j["<STR_LIT>"]["<STR_LIT>"]) != len(files):<EOL><INDENT>raise FBchatException(<EOL>"<STR_LIT>".format(j, files)<EOL>)<EOL><DEDENT>return [<EOL>(data[mimetype_to_key(data["<STR_LIT>"])], data["<STR_LIT>"])<EOL>for data in j["<STR_LIT>"]["<STR_LIT>"]<EOL>]<EOL>
|
Uploads files to Facebook
`files` should be a list of files that requests can upload, see:
http://docs.python-requests.org/en/master/api/#requests.request
Returns a list of tuples with a file's ID and mimetype
|
f8726:c0:m63
|
def _sendFiles(<EOL>self, files, message=None, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
thread_id, thread_type = self._getThread(thread_id, thread_type)<EOL>data = self._getSendData(<EOL>message=self._oldMessage(message),<EOL>thread_id=thread_id,<EOL>thread_type=thread_type,<EOL>)<EOL>data["<STR_LIT>"] = "<STR_LIT>"<EOL>data["<STR_LIT>"] = True<EOL>for i, (file_id, mimetype) in enumerate(files):<EOL><INDENT>data["<STR_LIT>".format(mimetype_to_key(mimetype), i)] = file_id<EOL><DEDENT>return self._doSendRequest(data)<EOL>
|
Sends files from file IDs to a thread
`files` should be a list of tuples, with a file's ID and mimetype
|
f8726:c0:m64
|
def sendRemoteFiles(<EOL>self, file_urls, message=None, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
file_urls = require_list(file_urls)<EOL>files = self._upload(get_files_from_urls(file_urls))<EOL>return self._sendFiles(<EOL>files=files, message=message, thread_id=thread_id, thread_type=thread_type<EOL>)<EOL>
|
Sends files from URLs to a thread
:param file_urls: URLs of files to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
|
f8726:c0:m65
|
def sendLocalFiles(<EOL>self, file_paths, message=None, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
file_paths = require_list(file_paths)<EOL>with get_files_from_paths(file_paths) as x:<EOL><INDENT>files = self._upload(x)<EOL><DEDENT>return self._sendFiles(<EOL>files=files, message=message, thread_id=thread_id, thread_type=thread_type<EOL>)<EOL>
|
Sends local files to a thread
:param file_paths: Paths of files to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
|
f8726:c0:m66
|
def sendRemoteVoiceClips(<EOL>self, clip_urls, message=None, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
clip_urls = require_list(clip_urls)<EOL>files = self._upload(get_files_from_urls(clip_urls), voice_clip=True)<EOL>return self._sendFiles(<EOL>files=files, message=message, thread_id=thread_id, thread_type=thread_type<EOL>)<EOL>
|
Sends voice clips from URLs to a thread
:param clip_urls: URLs of clips to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
|
f8726:c0:m67
|
def sendLocalVoiceClips(<EOL>self, clip_paths, message=None, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
clip_paths = require_list(clip_paths)<EOL>with get_files_from_paths(clip_paths) as x:<EOL><INDENT>files = self._upload(x, voice_clip=True)<EOL><DEDENT>return self._sendFiles(<EOL>files=files, message=message, thread_id=thread_id, thread_type=thread_type<EOL>)<EOL>
|
Sends local voice clips to a thread
:param clip_paths: Paths of clips to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
|
f8726:c0:m68
|
def sendImage(<EOL>self,<EOL>image_id,<EOL>message=None,<EOL>thread_id=None,<EOL>thread_type=ThreadType.USER,<EOL>is_gif=False,<EOL>):
|
if is_gif:<EOL><INDENT>mimetype = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>mimetype = "<STR_LIT>"<EOL><DEDENT>return self._sendFiles(<EOL>files=[(image_id, mimetype)],<EOL>message=message,<EOL>thread_id=thread_id,<EOL>thread_type=thread_type,<EOL>)<EOL>
|
Deprecated. Use :func:`fbchat.Client._sendFiles` instead
|
f8726:c0:m69
|
def sendRemoteImage(<EOL>self, image_url, message=None, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
return self.sendRemoteFiles(<EOL>file_urls=[image_url],<EOL>message=message,<EOL>thread_id=thread_id,<EOL>thread_type=thread_type,<EOL>)<EOL>
|
Deprecated. Use :func:`fbchat.Client.sendRemoteFiles` instead
|
f8726:c0:m70
|
def sendLocalImage(<EOL>self, image_path, message=None, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
return self.sendLocalFiles(<EOL>file_paths=[image_path],<EOL>message=message,<EOL>thread_id=thread_id,<EOL>thread_type=thread_type,<EOL>)<EOL>
|
Deprecated. Use :func:`fbchat.Client.sendLocalFiles` instead
|
f8726:c0:m71
|
def forwardAttachment(self, attachment_id, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {<EOL>"<STR_LIT>": attachment_id,<EOL>"<STR_LIT>".format(generateOfflineThreadingID()): thread_id,<EOL>}<EOL>j = self._post(<EOL>self.req_url.FORWARD_ATTACHMENT, data, fix_request=True, as_json=True<EOL>)<EOL>
|
Forwards an attachment
:param attachment_id: Attachment ID to forward
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m72
|
def createGroup(self, message, user_ids):
|
data = self._getSendData(message=self._oldMessage(message))<EOL>if len(user_ids) < <NUM_LIT:2>:<EOL><INDENT>raise FBchatUserError("<STR_LIT>")<EOL><DEDENT>for i, user_id in enumerate(user_ids + [self._uid]):<EOL><INDENT>data["<STR_LIT>".format(i)] = "<STR_LIT>".format(user_id)<EOL><DEDENT>message_id, thread_id = self._doSendRequest(data, get_thread_id=True)<EOL>if not thread_id:<EOL><INDENT>raise FBchatException(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>return thread_id<EOL>
|
Creates a group with the given ids
:param message: The initial message
:param user_ids: A list of users to create the group with.
:return: ID of the new group
:raises: FBchatException if request failed
|
f8726:c0:m73
|
def addUsersToGroup(self, user_ids, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = self._getSendData(thread_id=thread_id, thread_type=ThreadType.GROUP)<EOL>data["<STR_LIT>"] = "<STR_LIT>"<EOL>data["<STR_LIT>"] = "<STR_LIT>"<EOL>user_ids = require_list(user_ids)<EOL>for i, user_id in enumerate(user_ids):<EOL><INDENT>if user_id == self._uid:<EOL><INDENT>raise FBchatUserError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>else:<EOL><INDENT>data[<EOL>"<STR_LIT>".format(i)<EOL>] = "<STR_LIT>".format(user_id)<EOL><DEDENT><DEDENT>return self._doSendRequest(data)<EOL>
|
Adds users to a group.
:param user_ids: One or more user IDs to add
:param thread_id: Group ID to add people to. See :ref:`intro_threads`
:type user_ids: list
:raises: FBchatException if request failed
|
f8726:c0:m74
|
def removeUserFromGroup(self, user_id, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {"<STR_LIT>": user_id, "<STR_LIT>": thread_id}<EOL>j = self._post(self.req_url.REMOVE_USER, data, fix_request=True, as_json=True)<EOL>
|
Removes users from a group.
:param user_id: User ID to remove
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m75
|
def addGroupAdmins(self, admin_ids, thread_id=None):
|
self._adminStatus(admin_ids, True, thread_id)<EOL>
|
Sets specifed users as group admins.
:param admin_ids: One or more user IDs to set admin
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m77
|
def removeGroupAdmins(self, admin_ids, thread_id=None):
|
self._adminStatus(admin_ids, False, thread_id)<EOL>
|
Removes admin status from specifed users.
:param admin_ids: One or more user IDs to remove admin
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m78
|
def changeGroupApprovalMode(self, require_admin_approval, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {"<STR_LIT>": int(require_admin_approval), "<STR_LIT>": thread_id}<EOL>j = self._post(self.req_url.APPROVAL_MODE, data, fix_request=True, as_json=True)<EOL>
|
Changes group's approval mode
:param require_admin_approval: True or False
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m79
|
def acceptUsersToGroup(self, user_ids, thread_id=None):
|
self._usersApproval(user_ids, True, thread_id)<EOL>
|
Accepts users to the group from the group's approval
:param user_ids: One or more user IDs to accept
:param thread_id: Group ID to accept users to. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m81
|
def denyUsersFromGroup(self, user_ids, thread_id=None):
|
self._usersApproval(user_ids, False, thread_id)<EOL>
|
Denies users from the group's approval
:param user_ids: One or more user IDs to deny
:param thread_id: Group ID to deny users from. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m82
|
def _changeGroupImage(self, image_id, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {"<STR_LIT>": image_id, "<STR_LIT>": thread_id}<EOL>j = self._post(self.req_url.THREAD_IMAGE, data, fix_request=True, as_json=True)<EOL>return image_id<EOL>
|
Changes a thread image from an image id
:param image_id: ID of uploaded image
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m83
|
def changeGroupImageRemote(self, image_url, thread_id=None):
|
(image_id, mimetype), = self._upload(get_files_from_urls([image_url]))<EOL>return self._changeGroupImage(image_id, thread_id)<EOL>
|
Changes a thread image from a URL
:param image_url: URL of an image to upload and change
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m84
|
def changeGroupImageLocal(self, image_path, thread_id=None):
|
with get_files_from_paths([image_path]) as files:<EOL><INDENT>(image_id, mimetype), = self._upload(files)<EOL><DEDENT>return self._changeGroupImage(image_id, thread_id)<EOL>
|
Changes a thread image from a local path
:param image_path: Path of an image to upload and change
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m85
|
def changeThreadTitle(self, title, thread_id=None, thread_type=ThreadType.USER):
|
thread_id, thread_type = self._getThread(thread_id, thread_type)<EOL>if thread_type == ThreadType.USER:<EOL><INDENT>return self.changeNickname(<EOL>title, thread_id, thread_id=thread_id, thread_type=thread_type<EOL>)<EOL><DEDENT>data = {"<STR_LIT>": title, "<STR_LIT>": thread_id}<EOL>j = self._post(self.req_url.THREAD_NAME, data, fix_request=True, as_json=True)<EOL>
|
Changes title of a thread.
If this is executed on a user thread, this will change the nickname of that user, effectively changing the title
:param title: New group thread title
:param thread_id: Group ID to change title of. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
|
f8726:c0:m86
|
def changeNickname(<EOL>self, nickname, user_id, thread_id=None, thread_type=ThreadType.USER<EOL>):
|
thread_id, thread_type = self._getThread(thread_id, thread_type)<EOL>data = {<EOL>"<STR_LIT>": nickname,<EOL>"<STR_LIT>": user_id,<EOL>"<STR_LIT>": thread_id,<EOL>}<EOL>j = self._post(<EOL>self.req_url.THREAD_NICKNAME, data, fix_request=True, as_json=True<EOL>)<EOL>
|
Changes the nickname of a user in a thread
:param nickname: New nickname
:param user_id: User that will have their nickname changed
:param thread_id: User/Group ID to change color of. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
|
f8726:c0:m87
|
def changeThreadColor(self, color, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {<EOL>"<STR_LIT>": color.value if color != ThreadColor.MESSENGER_BLUE else "<STR_LIT>",<EOL>"<STR_LIT>": thread_id,<EOL>}<EOL>j = self._post(self.req_url.THREAD_COLOR, data, fix_request=True, as_json=True)<EOL>
|
Changes thread color
:param color: New thread color
:param thread_id: User/Group ID to change color of. See :ref:`intro_threads`
:type color: models.ThreadColor
:raises: FBchatException if request failed
|
f8726:c0:m88
|
def changeThreadEmoji(self, emoji, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {"<STR_LIT>": emoji, "<STR_LIT>": thread_id}<EOL>j = self._post(self.req_url.THREAD_EMOJI, data, fix_request=True, as_json=True)<EOL>
|
Changes thread color
Trivia: While changing the emoji, the Facebook web client actually sends multiple different requests, though only this one is required to make the change
:param color: New thread emoji
:param thread_id: User/Group ID to change emoji of. See :ref:`intro_threads`
:raises: FBchatException if request failed
|
f8726:c0:m89
|
def reactToMessage(self, message_id, reaction):
|
data = {<EOL>"<STR_LIT:action>": "<STR_LIT>" if reaction else "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:1>",<EOL>"<STR_LIT>": self._uid,<EOL>"<STR_LIT>": str(message_id),<EOL>"<STR_LIT>": reaction.value if reaction else None,<EOL>}<EOL>data = {"<STR_LIT>": <NUM_LIT>, "<STR_LIT>": json.dumps({"<STR_LIT:data>": data})}<EOL>self._post(self.req_url.MESSAGE_REACTION, data, fix_request=True, as_json=True)<EOL>
|
Reacts to a message, or removes reaction
:param message_id: :ref:`Message ID <intro_message_ids>` to react to
:param reaction: Reaction emoji to use, if None removes reaction
:type reaction: models.MessageReaction or None
:raises: FBchatException if request failed
|
f8726:c0:m90
|
def createPlan(self, plan, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": plan.time,<EOL>"<STR_LIT:title>": plan.title,<EOL>"<STR_LIT>": thread_id,<EOL>"<STR_LIT>": plan.location_id or "<STR_LIT>",<EOL>"<STR_LIT>": plan.location or "<STR_LIT>",<EOL>"<STR_LIT>": ACONTEXT,<EOL>}<EOL>j = self._post(self.req_url.PLAN_CREATE, data, fix_request=True, as_json=True)<EOL>
|
Sets a plan
:param plan: Plan to set
:param thread_id: User/Group ID to send plan to. See :ref:`intro_threads`
:type plan: models.Plan
:raises: FBchatException if request failed
|
f8726:c0:m91
|
def editPlan(self, plan, new_plan):
|
data = {<EOL>"<STR_LIT>": plan.uid,<EOL>"<STR_LIT>": "<STR_LIT:false>",<EOL>"<STR_LIT:date>": new_plan.time,<EOL>"<STR_LIT>": new_plan.location or "<STR_LIT>",<EOL>"<STR_LIT>": new_plan.location_id or "<STR_LIT>",<EOL>"<STR_LIT:title>": new_plan.title,<EOL>"<STR_LIT>": ACONTEXT,<EOL>}<EOL>j = self._post(self.req_url.PLAN_CHANGE, data, fix_request=True, as_json=True)<EOL>
|
Edits a plan
:param plan: Plan to edit
:param new_plan: New plan
:type plan: models.Plan
:raises: FBchatException if request failed
|
f8726:c0:m92
|
def deletePlan(self, plan):
|
data = {"<STR_LIT>": plan.uid, "<STR_LIT>": "<STR_LIT:true>", "<STR_LIT>": ACONTEXT}<EOL>j = self._post(self.req_url.PLAN_CHANGE, data, fix_request=True, as_json=True)<EOL>
|
Deletes a plan
:param plan: Plan to delete
:raises: FBchatException if request failed
|
f8726:c0:m93
|
def changePlanParticipation(self, plan, take_part=True):
|
data = {<EOL>"<STR_LIT>": plan.uid,<EOL>"<STR_LIT>": "<STR_LIT>" if take_part else "<STR_LIT>",<EOL>"<STR_LIT>": ACONTEXT,<EOL>}<EOL>j = self._post(<EOL>self.req_url.PLAN_PARTICIPATION, data, fix_request=True, as_json=True<EOL>)<EOL>
|
Changes participation in a plan
:param plan: Plan to take part in or not
:param take_part: Whether to take part in the plan
:raises: FBchatException if request failed
|
f8726:c0:m94
|
def eventReminder(self, thread_id, time, title, location="<STR_LIT>", location_id="<STR_LIT>"):
|
plan = Plan(time=time, title=title, location=location, location_id=location_id)<EOL>self.createPlan(plan=plan, thread_id=thread_id)<EOL>
|
Deprecated. Use :func:`fbchat.Client.createPlan` instead
|
f8726:c0:m95
|
def createPoll(self, poll, thread_id=None):
|
thread_id, thread_type = self._getThread(thread_id, None)<EOL>data = OrderedDict([("<STR_LIT>", poll.title), ("<STR_LIT>", thread_id)])<EOL>for i, option in enumerate(poll.options):<EOL><INDENT>data["<STR_LIT>".format(i)] = option.text<EOL>data["<STR_LIT>".format(i)] = str(int(option.vote))<EOL><DEDENT>j = self._post(self.req_url.CREATE_POLL, data, fix_request=True, as_json=True)<EOL>
|
Creates poll in a group thread
:param poll: Poll to create
:param thread_id: User/Group ID to create poll in. See :ref:`intro_threads`
:type poll: models.Poll
:raises: FBchatException if request failed
|
f8726:c0:m96
|
def updatePollVote(self, poll_id, option_ids=[], new_options=[]):
|
data = {"<STR_LIT>": poll_id}<EOL>for i, option_id in enumerate(option_ids):<EOL><INDENT>data["<STR_LIT>".format(i)] = option_id<EOL><DEDENT>for i, option_text in enumerate(new_options):<EOL><INDENT>data["<STR_LIT>".format(i)] = option_text<EOL><DEDENT>j = self._post(self.req_url.UPDATE_VOTE, data, fix_request=True, as_json=True)<EOL>
|
Updates a poll vote
:param poll_id: ID of the poll to update vote
:param option_ids: List of the option IDs to vote
:param new_options: List of the new option names
:param thread_id: User/Group ID to change status in. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
|
f8726:c0:m97
|
def setTypingStatus(self, status, thread_id=None, thread_type=None):
|
thread_id, thread_type = self._getThread(thread_id, thread_type)<EOL>data = {<EOL>"<STR_LIT>": status.value,<EOL>"<STR_LIT>": thread_id,<EOL>"<STR_LIT:to>": thread_id if thread_type == ThreadType.USER else "<STR_LIT>",<EOL>"<STR_LIT:source>": "<STR_LIT>",<EOL>}<EOL>j = self._post(self.req_url.TYPING, data, fix_request=True, as_json=True)<EOL>
|
Sets users typing status in a thread
:param status: Specify the typing status
:param thread_id: User/Group ID to change status in. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type status: models.TypingStatus
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
|
f8726:c0:m98
|
def markAsDelivered(self, thread_id, message_id):
|
data = {<EOL>"<STR_LIT>": message_id,<EOL>"<STR_LIT>" % thread_id: message_id,<EOL>}<EOL>r = self._post(self.req_url.DELIVERED, data)<EOL>return r.ok<EOL>
|
Mark a message as delivered
:param thread_id: User/Group ID to which the message belongs. See :ref:`intro_threads`
:param message_id: Message ID to set as delivered. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed
|
f8726:c0:m99
|
def markAsRead(self, thread_ids=None):
|
self._readStatus(True, thread_ids)<EOL>
|
Mark threads as read
All messages inside the threads will be marked as read
:param thread_ids: User/Group IDs to set as read. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed
|
f8726:c0:m101
|
def markAsUnread(self, thread_ids=None):
|
self._readStatus(False, thread_ids)<EOL>
|
Mark threads as unread
All messages inside the threads will be marked as unread
:param thread_ids: User/Group IDs to set as unread. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed
|
f8726:c0:m102
|
def markAsSeen(self):
|
r = self._post(self.req_url.MARK_SEEN, {"<STR_LIT>": now()})<EOL>return r.ok<EOL>
|
.. todo::
Documenting this
|
f8726:c0:m103
|
def friendConnect(self, friend_id):
|
data = {"<STR_LIT>": friend_id, "<STR_LIT:action>": "<STR_LIT>"}<EOL>r = self._post(self.req_url.CONNECT, data)<EOL>return r.ok<EOL>
|
.. todo::
Documenting this
|
f8726:c0:m104
|
def removeFriend(self, friend_id=None):
|
payload = {"<STR_LIT>": friend_id, "<STR_LIT>": "<STR_LIT:none>", "<STR_LIT>": "<STR_LIT>"}<EOL>r = self._post(self.req_url.REMOVE_FRIEND, payload)<EOL>query = parse_qs(urlparse(r.url).query)<EOL>if "<STR_LIT>" not in query:<EOL><INDENT>log.debug("<STR_LIT>")<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>log.warning("<STR_LIT>")<EOL>return False<EOL><DEDENT>
|
Removes a specifed friend from your friend list
:param friend_id: The ID of the friend that you want to remove
:return: Returns error if the removing was unsuccessful, returns True when successful.
|
f8726:c0:m105
|
def blockUser(self, user_id):
|
data = {"<STR_LIT>": user_id}<EOL>r = self._post(self.req_url.BLOCK_USER, data)<EOL>return r.ok<EOL>
|
Blocks messages from a specifed user
:param user_id: The ID of the user that you want to block
:return: Whether the request was successful
:raises: FBchatException if request failed
|
f8726:c0:m106
|
def unblockUser(self, user_id):
|
data = {"<STR_LIT>": user_id}<EOL>r = self._post(self.req_url.UNBLOCK_USER, data)<EOL>return r.ok<EOL>
|
Unblocks messages from a blocked user
:param user_id: The ID of the user that you want to unblock
:return: Whether the request was successful
:raises: FBchatException if request failed
|
f8726:c0:m107
|
def moveThreads(self, location, thread_ids):
|
thread_ids = require_list(thread_ids)<EOL>if location == ThreadLocation.PENDING:<EOL><INDENT>location = ThreadLocation.OTHER<EOL><DEDENT>if location == ThreadLocation.ARCHIVED:<EOL><INDENT>data_archive = dict()<EOL>data_unpin = dict()<EOL>for thread_id in thread_ids:<EOL><INDENT>data_archive["<STR_LIT>".format(thread_id)] = "<STR_LIT:true>"<EOL>data_unpin["<STR_LIT>".format(thread_id)] = "<STR_LIT:false>"<EOL><DEDENT>r_archive = self._post(self.req_url.ARCHIVED_STATUS, data_archive)<EOL>r_unpin = self._post(self.req_url.PINNED_STATUS, data_unpin)<EOL>return r_archive.ok and r_unpin.ok<EOL><DEDENT>else:<EOL><INDENT>data = dict()<EOL>for i, thread_id in enumerate(thread_ids):<EOL><INDENT>data["<STR_LIT>".format(location.name.lower(), i)] = thread_id<EOL><DEDENT>r = self._post(self.req_url.MOVE_THREAD, data)<EOL>return r.ok<EOL><DEDENT>
|
Moves threads to specifed location
:param location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param thread_ids: Thread IDs to move. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed
|
f8726:c0:m108
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.