Exemple #1
0
 def load_profile_avatar(self, url, profile):
     bytes_in_cache = self.store.cache.avatar.get(url)
     if bytes_in_cache:
         profile.avatar = bytes_in_cache
         return
     with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
         bytes = yield from loop.run_in_executor(executor, requests.get, url)
         file = tempfile.NamedTemporaryFile(delete=False)
         file.write(bytes.content)
         file.close()
         avatar = Image(file.name, width=35)
         self.store.cache.avatar[url] = avatar
         profile.avatar = avatar
Exemple #2
0
 def load_picture_async(self, url, width, message_widget, auth=True):
     width = min(width, 800)
     bytes_in_cache = self.store.cache.picture.get(url)
     if bytes_in_cache:
         message_widget.file = bytes_in_cache
         return
     with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
         headers = {}
         if auth:
             headers = {'Authorization': 'Bearer {}'.format(self.store.slack_token)}
         bytes = yield from loop.run_in_executor(
             executor,
             functools.partial(requests.get, url, headers=headers)
         )
         file = tempfile.NamedTemporaryFile(delete=False)
         file.write(bytes.content)
         file.close()
         picture = Image(file.name, width=(width / 10))
         message_widget.file = picture