Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from data import getUsers, getChannels
- from error import InputError
- import re
- def users_all(token):
- """
- Returns a list of all users and their associated details
- :param token: token for authentication purpose
- :return: users with their associated details
- """
- if token is None or not isinstance(token, str):
- raise InputError("Token should be a string")
- return getUsers()
- def search(token, query_str):
- """
- Given a query string, return a collection of messages in all of the channels that
- the user has joined that match the query
- :param token: token for authentication purpose
- :param query_str: query string key used for searching
- :return: messages that match the query
- """
- if token is None or not isinstance(token, str):
- raise InputError("Token should be a string")
- if query_str is None or not isinstance(token, str):
- raise InputError("Query string should be a string")
- channels = getChannels()
- messages = []
- for channel_id, channel in channels.items():
- members = channel['all_members']
- for member_id, member in members.items():
- if member['token'] == token:
- message = getChannelMessage(channel, member)
- if re.findall(query_str, message):
- messages.append(message)
- return messages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement