示例#1
0
文件: view.py 项目: 00/wikihouse
 def get(self):
     """Set cache headers, get the contributors from the db and render
       the template.
     """
     
     endpoint = "https://proto.espra.com/_api/joins.list/wikihouse"
     default_espra_signups = [[
         "Alice Fung", 
         "alice00", 
         1368806444, 
         "4d82538cb98da96b7524810b8c641e5c"
       ], [
         "James Arthur", 
         "thruflo", 
         1368806590, 
         "dbfaa69ec6b06acc923908ba2be549b3"
       ]
     ]
     # Get the avatars.
     KEY_NAME = 'v1'
     items = []
     avatars = model.Avatars.get_by_key_name(KEY_NAME)
     if avatars is not None:
         urls = avatars.twitter_followers[:]
         random.shuffle(urls)
         for item in urls[:66]:
             parts = item.split('.')
             parts[-2] = u"%s_normal" % parts[-2]
             items.append('.'.join(parts))
     
     # Do the cache fandango to keep Tav happy.
     set_edge_cache_headers(self.request, self.response)
     
     # Get the community signup activity from proto espra.
     try:
         espra_signups = decode_json(urlfetch(endpoint).content)
     except Exception as err:
         logging.info("Error fetching espra signups")
         logging.info(err, exc_info=True)
         espra_signups = default_espra_signups
     
     contributors = model.User.get_all()
     return self.render('community.tmpl', contributors=contributors, avatars=items,
             espra_signups=espra_signups)
示例#2
0
    def get(self):
        """Set cache headers, get the contributors from the db and render
          the template.
        """

        endpoint = "https://proto.espra.com/_api/joins.list/wikihouse"
        default_espra_signups = [[
            "Alice Fung", "alice00", 1368806444,
            "4d82538cb98da96b7524810b8c641e5c"
        ],
                                 [
                                     "James Arthur", "thruflo", 1368806590,
                                     "dbfaa69ec6b06acc923908ba2be549b3"
                                 ]]
        # Get the avatars.
        KEY_NAME = 'v1'
        items = []
        avatars = model.Avatars.get_by_key_name(KEY_NAME)
        if avatars is not None:
            urls = avatars.twitter_followers[:]
            random.shuffle(urls)
            for item in urls[:66]:
                parts = item.split('.')
                parts[-2] = u"%s_normal" % parts[-2]
                items.append('.'.join(parts))

        # Do the cache fandango to keep Tav happy.
        set_edge_cache_headers(self.request, self.response)

        # Get the community signup activity from proto espra.
        try:
            espra_signups = decode_json(urlfetch(endpoint).content)
        except Exception as err:
            logging.info("Error fetching espra signups")
            logging.info(err, exc_info=True)
            espra_signups = default_espra_signups

        contributors = model.User.get_all()
        return self.render('community.tmpl',
                           contributors=contributors,
                           avatars=items,
                           espra_signups=espra_signups)
 def _request(path, headers=None, params=None, method="get"):
     url = path
     resp = urlfetch(url, headers=headers)
     return RequestsShim(resp, url)
 def _request(path, headers=None, params=None, method="get"):
     url = path
     resp = urlfetch(url, headers=headers)
     return RequestsShim(resp, url)