예제 #1
0
 def get_visitors(cls, sid_orig: str) -> List[Dict]:
     """获得访客列表"""
     db = get_mongodb()
     result = db[cls.collection_name].find({
         "host": sid_orig
     }).sort("last_time", -1).limit(50)
     visitor_list = []
     for people in result:
         stu_cache = RedisCacheDAO.get_student(people["visitor"])
         if stu_cache:
             visitor_list.append({
                 "name": stu_cache.name,
                 "sid": stu_cache.sid,
                 "visit_time": people["last_time"]
             })
         else:
             # query api-server
             with elasticapm.capture_span('rpc_search'):
                 rpc_result = HttpRpc.call(
                     method="GET",
                     url='{}/v1/search/{}'.format(
                         current_app.config['API_SERVER_BASE_URL'],
                         people["visitor"]),
                     retry=True)
             visitor_list.append({
                 "name": rpc_result["student"][0]["name"],
                 "sid": rpc_result["student"][0]["sid"],
                 "visit_time": people["last_time"]
             })
             RedisCacheDAO.set_student(
                 Student(sid_orig=people["visitor"],
                         name=rpc_result["student"][0]["name"],
                         sid=rpc_result["student"][0]["sid"]))
     return visitor_list
예제 #2
0
 def get_android_download_link():
     """
     It's not possible to make a HTTP request during `create_app` since the urllib2 is patched by gevent
     and the gevent engine is not started yet (controlled by uWSGI). So we can only do the initialization
     here.
     """
     from everyclass.server.utils.rpc import HttpRpc
     android_manifest = HttpRpc.call(method="GET",
                                     url="https://everyclass.cdn.admirable.pro/android/manifest.json",
                                     retry=True)
     android_ver = android_manifest['latestVersions']['mainstream']['versionCode']
     __app.config['ANDROID_CLIENT_URL'] = android_manifest['releases'][android_ver]['url']