Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if len(q) == 0:
return 0
url = "https://www.googleapis.com/youtube/v3/search?q=" + \
urllib.urlencode(
q) + "&part=snippet&maxResults=15&type=channel&key=AIzaSyA2cu1skGcRjDfIpG2I1ri_MWeObrZGS30"
feed1 = urllib.urlopen(url)
feed1 = feed1.read()
feed_json1 = json.loads(feed1)
ids = []
for item in feed_json1["items"]:
ids.append({"channel_id": item["snippet"]["channelId"],
"title": item["snippet"]["title"],
"description": item["snippet"]["description"],
"thumbnails": item["snippet"]["thumbnails"]["default"]["url"]})
resp = Response(
response=json.dumps(ids), status=200, mimetype="text/plain")
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
def view_func(self):
"""the view_func passed to Flask.add_url_rule"""
if request.method == 'OPTIONS':
resp = Response('', 200)
resp.headers['Access-Control-Allow-Origin'] = '*'
resp.headers['Access-Control-Allow-Headers'] = \
'Content-Type, Origin, Accept'
return resp
rst = self.api_implementation()
assert isinstance(rst, dict), \
"ret value {0} is not a dict".format(str(rst))
callback = request.values.get('callback')
if callback and VALID_CALLBACK_RE.match(callback) is not None:
rst = '{}({})'.format(callback, json.dumps(rst))
else:
rst = json.dumps(rst, indent=4)
resp = Response(rst, 200, mimetype='application/json')
resp.headers['Access-Control-Allow-Origin'] = '*'
resp.headers['Access-Control-Allow-Headers'] = \
'Content-Type, Origin, Accept'
def response_error(msg):
error = json.dumps({'error': msg})
return Response(error, status=400, mimetype='application/json')
@csrf_protect.exempt
@app.route('/generic_callback', methods=['POST', 'GET'])
def get_generic_callback():
"""
Method to handle generic callbacks from arbitrary puppyscripts.
Expects
Method: POST
Data: payload, puppyscript_name, data
Optional Data: referrer, url
"""
response = Response()
if request.method == 'POST':
try:
app.logger.info("request.form.get('payload', 0): {}".format(
request.form.get('payload', 0)))
puppyscript_name = urllib.unquote(
unicode(request.form.get('puppyscript_name', '')))
# If they don't set a url or referrer, ignore it
url = urllib.unquote(unicode(request.form.get('uri', '')))
referrer = urllib.unquote(
unicode(request.form.get('referrer', '')))
try:
if app.config.get('ALLOWED_DOMAINS'):
def get_song_mp3(song_id):
"""Retrieve the MP3 for a given ID."""
song_url = music.get_stream_url(song_id, app.config['GACCOUNT_DEVICE_ID'])
if app.config['GMP_SONG_FILTERS']:
response = requests.get(song_url)
data = BytesIO(response.content)
for song_filter in app.config['GMP_SONG_FILTERS']:
if callable(song_filter):
data = song_filter(song_id, data)
else:
data = globals()[song_filter](song_id, data)
return mp3ify(Response(data.getvalue()))
else:
response = requests.get(song_url, stream=True)
return mp3ify(Response(response.iter_content(chunk_size=HALF_MB)))
def checkModule(moduleName):
if moduleName not in extraModules['modules']:
return Response("", 404)
def downloaded_repos():
drs = server.transform(augur_db.downloaded_repos)
return Response(response=drs,
status=200,
mimetype="application/json")
where_clause += ' AND degree = ' + str(degree)
#if signature_r is not None:
# where_clause += ' AND signature_r = ' + str(signature_r)
if start is None:
end = float(end)
query = 'SELECT * FROM (SELECT * FROM zeros {} ORDER BY zero DESC LIMIT {}) ORDER BY zero ASC'.format(where_clause, limit)
#query = 'SELECT * FROM zeros WHERE zero < {} ORDER BY zero DESC LIMIT {}'.format(end, limit)
else:
query = 'SELECT * FROM zeros {} ORDER BY zero LIMIT {}'.format(where_clause, limit)
print query
c.execute(query)
response = flask.Response( (" ".join([str(x) for x in row]) + "\n" for row in c) )
response.headers['content-type'] = 'text/plain'
if download == "yes":
response.headers['content-disposition'] = 'attachment; filename=zetazeros'
#response = flask.Response( ("1 %s\n" % (str(row[0]),) for row in c) )
return response
except NameError:
pass # Python 3 strings are already Unicode
if qformat == 'json':
return jsonify(result)
elif qformat == 'csv':
csvfeed = '"'
csvfeed += '","'.join(result[0].keys())
for line in result:
csvfeed += '"\n"'
csvfeed += '","'.join(line.values())
csvfeed += '"'
return Response(csvfeed)
xmlfeed = dicttoxml(result, custom_root='channel', attr_type=False)
xmlfeed = parseString(xmlfeed).toprettyxml()
return Response(xmlfeed, mimetype='application/xml')
except Exception as e:
print(e)
return jsonify(errorObj)
def no_authentication(self):
"""
Sends a 401 response that enables basic auth.
"""
return Response(
'User identity could not be verified.\n'
'Please login with proper credentials', 401,
{
'WWW-Authenticate': 'Basic realm="Login Required"'
})