Advertisement
mrzecki

Untitled

Mar 28th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. from data import getUsers, getChannels
  2. from error import InputError
  3. import re
  4.  
  5. def users_all(token):
  6. """
  7. Returns a list of all users and their associated details
  8. :param token: token for authentication purpose
  9. :return: users with their associated details
  10. """
  11.  
  12. if token is None or not isinstance(token, str):
  13. raise InputError("Token should be a string")
  14.  
  15. return getUsers()
  16.  
  17.  
  18. def search(token, query_str):
  19. """
  20. Given a query string, return a collection of messages in all of the channels that
  21. the user has joined that match the query
  22. :param token: token for authentication purpose
  23. :param query_str: query string key used for searching
  24. :return: messages that match the query
  25. """
  26.  
  27. if token is None or not isinstance(token, str):
  28. raise InputError("Token should be a string")
  29.  
  30. if query_str is None or not isinstance(token, str):
  31. raise InputError("Query string should be a string")
  32.  
  33. channels = getChannels()
  34. messages = []
  35. for channel_id, channel in channels.items():
  36. members = channel['all_members']
  37. for member_id, member in members.items():
  38. if member['token'] == token:
  39. message = getChannelMessage(channel, member)
  40. if re.findall(query_str, message):
  41. messages.append(message)
  42. return messages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement