def crawler_cookiejar_cookie_json_add_post(): user_id = current_user.get_id() cookiejar_uuid = request.form.get('cookiejar_uuid') if 'file' in request.files: file = request.files['file'] json_cookies = file.read().decode() if json_cookies: res = crawlers.api_import_cookies_from_json(json_cookies, cookiejar_uuid) return redirect(url_for('crawler_splash.crawler_cookiejar_show', cookiejar_uuid=cookiejar_uuid)) return redirect(url_for('crawler_splash.crawler_cookiejar_cookie_add', cookiejar_uuid=cookiejar_uuid))
def crawler_cookiejar_add_post(): user_id = current_user.get_id() description = request.form.get('description') level = request.form.get('level') if level: level = 1 else: level = 0 if 'file' in request.files: file = request.files['file'] json_cookies = file.read().decode() else: json_cookies = None # Get cookies to add l_manual_cookie = [] l_invalid_cookie = [] for obj_tuple in list(request.form): l_input = request.form.getlist(obj_tuple) if len(l_input) == 2: if l_input[0]: # cookie_name cookie_dict = {'name': l_input[0], 'value': l_input[1]} l_manual_cookie.append(cookie_dict) elif l_input[1]: # cookie_value l_invalid_cookie.append({'name': '', 'value': l_input[1]}) if l_invalid_cookie: return create_json_response( { 'error': 'invalid cookie', 'invalid fileds': l_invalid_cookie }, 400) cookiejar_uuid = crawlers.create_cookiejar(user_id, level=level, description=description) if json_cookies: res = crawlers.api_import_cookies_from_json(json_cookies, cookiejar_uuid) if res: return create_json_response(res[0], res[1]) if l_manual_cookie: crawlers.add_cookies_to_cookiejar(cookiejar_uuid, l_manual_cookie) return redirect( url_for('crawler_splash.crawler_cookiejar_show', cookiejar_uuid=cookiejar_uuid))