def authorized(): """get openid""" code = request.args.get("code") if not code: return "ERR_INVALID_CODE", 400 wl = wechat_login(app.config['APP_ID'], app.config['APP_SECRET']) data = wl.access_token(code) app.logger.info(data) openid = data['openid'] access_token = data['access_token'] wechat_user = wl.user_info(access_token, openid) app.logger.info(wechat_user) account = User.query.filter_by(openid=wechat_user['openid']).first() if account: app.logger.info('----user is in our database---') else: unionid = '' if 'unionid' in wechat_user: unionid = wechat_user['unionid'] account = User(unionid=unionid, openid=wechat_user['openid'], nick_name=str(wechat_user['nickname']), head_img_url=wechat_user['headimgurl'], sex=wechat_user['sex'], is_del=0, is_errands_man=0).save() token = str.replace(str(uuid.uuid1()), '-', '') redis.set("account:wechat_login:" + token, json.dumps(account.to_json()), 72000) if account.phone: return jsonify({'token': token, 'type': 1}) return jsonify({'token': token, 'type': 0})
def test_Should_CreateCorrectDirectoriesAndJSONFiles(self): # parse menu menus = self.studentenwerk_menu_parser.get_menus( self.menu_html_garching, "mensa-garching") # get weeks weeks = Week.to_weeks(menus) # create temp dir for testing with tempfile.TemporaryDirectory() as temp_dir: # store output in the tempdir # location can be an empty string because combination won't get tested (combine_dishes is False) here main.jsonify(weeks, temp_dir, "", False) # check if two directories are created (one for 2016 and 2017) created_dirs = [ name for name in os.listdir(temp_dir) if os.path.isdir(os.path.join(temp_dir, name)) ] created_dirs.sort() self.assertEqual(1, len(created_dirs)) self.assertEqual("2017", created_dirs[0]) # check if the created directories contain the JSON files dir_2017 = "%s/2017" % temp_dir files_in_2017 = [ name for name in os.listdir(dir_2017) if os.path.isfile(os.path.join(dir_2017, name)) ] files_in_2017.sort() self.assertEqual( ["13.json", "14.json", "15.json", "16.json", "17.json"], files_in_2017)
def test_genFile(self): # parse the menu menus = self.mediziner_mensa_parser.get_menus( self.menu_kw_47_2018_txt, self.menu_kw_47_2018_year, self.menu_kw_47_2018_week_number) weeks = Week.to_weeks(menus) main.jsonify(weeks, "/tmp/eat-api_test_output", "mediziner-mensa", True)
def signup(): data = request.json user = User.query.filter_by(username=data["username"]).first() if user is None: return jsonify({"error": "el usuario no existe"}), 404 if sha256.verify(data["password"], user.password): tocken = create_access_token(identity=data["username"]) refresh = create_refresh_token(identity=data["username"]) return jsonify({"token": tocken, "refresh": refresh}), 200 return jsonify({"error": "la contraseña no es valida"}), 404
def user(): access_token = request.args.get('token') userid = request.args.get('userid') info_res = requests.get( "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + userid) return jsonify(info_res.json())
def user_id(): access_token = request.args.get('token') code = request.args.get('code') info_res = requests.get( "https://oapi.dingtalk.com/user/getuserinfo?access_token=" + access_token + "&code=" + code) return jsonify(info_res.json())
def revoked_token_callback(): return ( jsonify({ "description": "that token has been revoked", "error": "revoked_token" }), 401, )
def needs_refresh_token(): return ( jsonify({ "description": "that request needs a fresh token", "error": "refresh_token_required", }), 401, )
def invalid_token_callback(error): return ( jsonify({ "message": "signature verification has failed", "errror": "invalid_token" }), 401, )
def pic(): uid = uuid.uuid1() fs = request.files.getlist('file') pic_list = [] for f in fs: name = str.replace(str(uid), '-', '') bucket.put_object(name, f) pic_list.append(pic_url + "/" + name + "?x-oss-process=image/resize,h_100") return jsonify(pic_list)
def test_Studentenwerk_Mensa_Garching_New(self): # parse the menu menus = self.studentenwerk_menu_parser.get_menus( self.menu_html_mensa_garching_new, "mensa-garching") weeks = Week.to_weeks(menus) # create temp dir for testing with tempfile.TemporaryDirectory() as temp_dir: # store output in the tempdir main.jsonify(weeks, temp_dir, "mensa-garching", True) # open the generated file with open(os.path.join(temp_dir, "combined", "combined.json"), "r") as generated: # open the reference file with open( "src/test/assets/studentenwerk/out/speiseplan_mensa_garching_new.json", "r") as reference: self.assertEqual(json.load(generated), json.load(reference))
def authorized(): code = request.args.get("code") if not code: return "ERR_INVALID_CODE", 400 wl = wechat_login(app.config['APP_ID'], app.config['APP_SECRET']) data = wl.access_token(code) openid = data.openid access_token = data.access_token user = wl.user_info(access_token, openid) return jsonify(user)
def test_Ipp_Bistro_Kw_22_2019_closed_thursday(self): # parse the menu menus = self.ipp_parser.get_menus(self.menu_kw_22_2019_txt, self.menu_kw_22_2019_year, self.menu_kw_22_2019_week_number) weeks = Week.to_weeks(menus) # create temp dir for testing with tempfile.TemporaryDirectory() as temp_dir: # store output in the tempdir main.jsonify(weeks, temp_dir, "ipp-bistro", True) # open the generated file with open(os.path.join(temp_dir, "combined", "combined.json"), "r") as generated: # open the reference file with open("src/test/assets/ipp/out/menu_kw_22_2019.json", "r") as reference: self.assertEqual(json.load(generated), json.load(reference))
def pic(): app.logger.info('----------pic upload start-----------') fs = request.files.getlist('file') pic_list = [] for f in fs: uid = uuid.uuid1() name = str.replace(str(uid), '-', '') bucket.put_object(name, f) pic_list.append(pic_url + "/" + name + "?x-oss-process=image/resize,h_100") app.logger.info('----------pic upload success-----------') return jsonify(pic_list)
def test_Mediziner_Mensa_Kw_47_2018(self): # parse the menu menus = self.mediziner_mensa_parser.get_menus( self.menu_kw_47_2018_txt, self.menu_kw_47_2018_year, self.menu_kw_47_2018_week_number) weeks = Week.to_weeks(menus) # create temp dir for testing with tempfile.TemporaryDirectory() as temp_dir: # store output in the tempdir main.jsonify(weeks, temp_dir, "mediziner-mensa", True) # open the generated file with open(os.path.join(temp_dir, "combined", "combined.json"), "r") as generated: # open the reference file with open( "src/test/assets/mediziner-mensa/out/menu_kw_47_2018.json", "r") as reference: self.assertEqual(json.load(generated), json.load(reference))
def test_genFile(self): # parse the menu menus = self.studentenwerk_menu_parser.get_menus( self.menu_html_mensa_garching_old, "mensa-garching") weeks = Week.to_weeks(menus) main.jsonify(weeks, "mensa-garching.json", "mensa-garching", True)
def token_expiry_callback(): return jsonify({ "message": "the token has expired", "errror": "token_expired" }), 401
def missing_token_callback(error): return jsonify({ "message": "that request requires an access token", "errror": "authorization_required", })
def NotFound(error): return jsonify({"message": "the resource you requested is not availabe"})
def Unauthorized(error): return jsonify({"message": "You are not authorized"})
def BadRequest(error): return jsonify({"message": "that was a bad request"})
def token(): info_res = requests.get( "https://oapi.dingtalk.com/gettoken?appkey=dingtcftqzrv7cicm6rw&appsecret=w1" "-ixtw_3u38YsYwvPYQu2SkCX0gY9MY4NHe97UqtMgCOwlJhhZDzFsWtcMEq_Gp") return jsonify(info_res.json())