import os import sys import flask_api import pugsql from flask import request, jsonify, Response from flask_api import status, exceptions from flask_cors import CORS, cross_origin from werkzeug.security import generate_password_hash, check_password_hash import paramiko from scp import SCPClient app = flask_api.FlaskAPI(__name__) cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) def crawl(pwd='/'): crawl_cmd = 'du -a -h --time --max-depth=1 ' + pwd + ' 2>/dev/null' directory_list = [] directory = os.popen(crawl_cmd).read().split('\n') for i in range(0, len(directory) - 2): size, time, path = directory[i].split('\t') split_path = path.split('/') name = split_path[len(split_path) - 1] path = pwd + name if os.path.isfile(path): file_type = 0 elif os.path.isdir(path): file_type = 1 else: file_type = 2 directory_list.append([name, size, file_type, time, path]) return directory_list
import sys import flask_api import pugsql from flask import request, jsonify, Response from flask_api import status, exceptions from cassandra.cluster import Cluster cluster = Cluster(['172.17.0.2']) session = cluster.connect() session.set_keyspace('music') app = flask_api.FlaskAPI(__name__, static_url_path='') app.config.from_envvar('APP_CONFIG') #used to check if POST request header is application/json def validContentType(request, type='application/json'): if request.headers.has_key('Content-Type'): if request.headers['Content-Type'] == type: return True return { 'Error': 'Unsupported Media Type', 'Support-Content-Type': type }, status.HTTP_415_UNSUPPORTED_MEDIA_TYPE #route home @app.route('/', methods=['GET']) def home(): return '''<h1>description-SERVICE</h1>'''
import flask_api import requests from playlists import get_playlist from flask import render_template, make_response from flask_api import status app = flask_api.FlaskAPI(__name__, template_folder='') app.config.from_envvar('APP_CONFIG') # currently only gets the playlist with specific id @app.route('/playlist/<int:id>.xspf') def playlist(id): # concatenate the string so that we can put a get request for the right id getPlaylist = "http://localhost:8000/playlists/" + str(id) # remove .json() and uncomment bottom block for alternate way if this doesn't work playlists = requests.get(getPlaylist).json() playlists2 = requests.get(getPlaylist) # parses out the track section in the response print(playlists2.status_code) if playlists2.status_code == 200: track_ids = playlists['track'] get_track = [] for track_id in track_ids: # get each individual track object from calling a get request on tracks + the track id # requires get request on tracks endpoint to work while passing in the track_id track = requests.get("http://localhost:8000/tracks/" + str(track_id)).json() # get track description and make it another entry in the dictionary so we can parse it out later track['description'] = requests.get("http://localhost:8000/descriptions/" + str(track_id)).json() get_track.append(track)
import flask_ini import flask_migrate import flask_sqlalchemy import os import os.path import pkg_resources import sys try: import secrets except ImportError: # Import the small module hackily copied from the Python 3.6 library, since # no one seems to have backported it on PyPI yet. import hapcat.compat.secrets as secrets app = flask_api.FlaskAPI('hapcat', ) with app.app_context(): app.iniconfig = flask_ini.FlaskIni( delimiters=('=', ), comment_prefixes=('#', ), inline_comment_prefixes=None, strict=True, interpolation=configparser.ExtendedInterpolation()) app.iniconfig.read( pkg_resources.resource_filename('hapcat', 'data/hapcatd-defaults.conf')) envconf = os.environ.get('HAPCAT_FLASK_CONFIG', None)