|
1 | 1 | import os
|
| 2 | +import pytz |
2 | 3 | import signal
|
3 | 4 | import sys
|
4 | 5 | import time
|
| 6 | +from datetime import datetime |
5 | 7 | from functools import partial
|
6 | 8 | from platform import platform
|
7 | 9 | from typing import Any, List, Optional
|
@@ -120,9 +122,64 @@ def show_stream_info(self, color: str, name: str, desc: str) -> None:
|
120 | 122 | show_stream_view = StreamInfoView(self, color, name, desc)
|
121 | 123 | self.show_pop_up(show_stream_view, "# {}".format(name))
|
122 | 124 |
|
123 |
| - def show_user_info(self, user_id:int) -> None: |
124 |
| - show_userinfo_view = UserInfoView(self, user_id) |
125 |
| - self.show_pop_up(show_userinfo_view, "{}".format(user_id)) |
| 125 | + def show_user_info(self, user_id:int) -> None: |
| 126 | + url = 'users/' + str(user_id) |
| 127 | + response = self.client.call_endpoint( |
| 128 | + url=url, |
| 129 | + method='GET', |
| 130 | + request={'include_custom_profile_fields': True} |
| 131 | + ) |
| 132 | + |
| 133 | + index = { |
| 134 | + '17': 'Github username', |
| 135 | + '18': 'Twitter', |
| 136 | + '3': 'Country', |
| 137 | + '5': 'Zulip expertise', |
| 138 | + '7': 'About me', |
| 139 | + '13': { |
| 140 | + '0': 'emacs', |
| 141 | + '1': 'vim', |
| 142 | + '2': 'vscode', |
| 143 | + '3': 'sublime', |
| 144 | + '4': 'atom', |
| 145 | + '5': 'Other', |
| 146 | + }, |
| 147 | + '16': 'Favourite date', |
| 148 | + } |
| 149 | + |
| 150 | + display_data = {} |
| 151 | + res_data = response['members'][0] |
| 152 | + |
| 153 | + for key, value in res_data['profile_data'].items(): |
| 154 | + if key == '13': |
| 155 | + display_data['Favourite editor'] = index['13'][str(res_data['profile_data']['13']['value'])] |
| 156 | + else: display_data[str(index[key])] = value['value'] |
| 157 | + |
| 158 | + display_data['Email'] = res_data['email'] |
| 159 | + display_data['Date joined'] = res_data['date_joined'][:10] |
| 160 | + display_data['Timezone'] = res_data['timezone'] |
| 161 | + |
| 162 | + try: |
| 163 | + display_data['Local time'] = datetime.now(pytz.timezone(str(res_data['timezone']))).strftime("%H:%M") |
| 164 | + except: |
| 165 | + display_data['Local time'] = "Unknown timezone" |
| 166 | + |
| 167 | + presence = self.client.get_user_presence(str(res_data['email'])) |
| 168 | + if presence['presence']['aggregated']['status'] == 'active': |
| 169 | + display_data['Last active'] = "Currently online" |
| 170 | + else: |
| 171 | + display_data['Last active'] = str(datetime.fromtimestamp(presence['presence']['aggregated']['timestamp'])) |
| 172 | + |
| 173 | + if res_data['is_admin']: |
| 174 | + display_data['Role'] = "Admin" |
| 175 | + elif res_data['is_guest']: |
| 176 | + display_data['Role'] = "Guest" |
| 177 | + else: |
| 178 | + display_data['Role'] = "Member" |
| 179 | + |
| 180 | + show_userinfo_view = UserInfoView(self, display_data) |
| 181 | + self.show_pop_up(show_userinfo_view, "{}".format(res_data['full_name'])) |
| 182 | + return response['result'] == 'success' |
126 | 183 |
|
127 | 184 | def search_messages(self, text: str) -> None:
|
128 | 185 | # Search for a text in messages
|
|
0 commit comments