<commit_before>from nycaddress import parse
from flask import Flask, request, jsonify
from flask_swagger import swagger

# from flask.ext.cors import CORS
# CORS(app, resources=r'/*', allow_headers='Content-Type')

app = Flask(__name__)


@app.after_request
def after_request(response):
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers',
                         "Authorization, Content-Type")
    response.headers.add('Access-Control-Expose-Headers', "Authorization")
# "GET, POST, PUT, DELETE, OPTIONS")
    response.headers.add('Access-Control-Allow-Methods',
                         "GET, POST")
    response.headers.add('Access-Control-Allow-Credentials', "true")
    response.headers.add('Access-Control-Max-Age', 60 * 60 * 24 * 20)
    return response


def parseAddresses(text):
    return jsonify({'addresses':
                    [{"text": loc} for loc in parse(text)]})


@app.route('/', methods=['GET'])
def index():
    return "BetaNYC 5 Borough's address finder"


@app.route('/api/parseaddresses', methods=['POST'])
def parseaddresses():
    """
    Parse Addresses
    The only endpoint used to submit a string to be parsed.
    ---
    responses:
        '200':
            description: list of addresses.
            schema:
                id: StreetAddress
                required:
                    - text
                properties:
                    text:
                        type: string
                        description: Fulltext US street address
        default:
            description: Unexpected error
            schema:
                id: Error
                required:
                    - code
                    - message
                properties:
                    code:
                        type: integer
                        format: int32
                    message:
                        type: string
                        description: Error message

    parameters:
        - in: body
          name: source
          schema:
              required:
                  - source
              id: Input
              properties:
                  source:
                      type: string
                      description: String to parse
    """
    if request.method == 'GET':
        return 'So, instructions would be printed here...'

    data = request.json
    data = data['source']
    print 'data is %s' % data
    return parseAddresses(data)


@app.route('/spec')
def spec():
    swag = swagger(app)
    swag['info']['version'] = '0.1'
    swag['info']['title'] = "BetaNYC 5 Borough's address finder"
    return jsonify(swag)<commit_msg>add schema example<commit_after># -*- coding: utf-8 -*-
from nycaddress import parse
from flask import Flask, request, jsonify
from flask_swagger import swagger

# from flask.ext.cors import CORS
# CORS(app, resources=r'/*', allow_headers='Content-Type')

app = Flask(__name__)


@app.after_request
def after_request(response):
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers',
                         "Authorization, Content-Type")
    response.headers.add('Access-Control-Expose-Headers', "Authorization")
# "GET, POST, PUT, DELETE, OPTIONS")
    response.headers.add('Access-Control-Allow-Methods',
                         "GET, POST")
    response.headers.add('Access-Control-Allow-Credentials', "true")
    response.headers.add('Access-Control-Max-Age', 60 * 60 * 24 * 20)
    return response


def parseAddresses(text):
    return jsonify({'addresses':
                    [{"text": loc} for loc in parse(text)]})


@app.route('/', methods=['GET'])
def index():
    return "BetaNYC 5 Borough's address finder"


@app.route('/api/parseaddresses', methods=['POST'])
def parseaddresses():
    """
    Parse Addresses
    The only endpoint used to submit a string to be parsed.
    ---
    responses:
        '200':
            description: list of addresses.
            schema:
                id: StreetAddress
                required:
                    - text
                properties:
                    text:
                        type: string
                        description: Fulltext US street address
        default:
            description: Unexpected error
            schema:
                id: Error
                required:
                    - code
                    - message
                properties:
                    code:
                        type: integer
                        format: int32
                    message:
                        type: string
                        description: Error message

    parameters:
        - in: body
          name: source
          schema:
              required:
                  - source
              id: Input
              properties:
                  source:
                      type: string
                      description: String to parse
                      example: >
                                 NOTICE IS HEREBY GIVEN, pursuant to law, that
                                 the New York City Department of Consumer
                                 Affairs will hold a Public Hearing on
                                 Wednesday, January 28, 2015, at 2:00 P.M., at
                                 66 John Street, 11th Floor, in the Borough of
                                 Manhattan, on the following petitions for
                                 sidewalk café revocable consent: 1. 132
                                 Mulberry Inc. 132 Mulberry Street in the
                                 Borough of Manhattan
    """
    if request.method == 'GET':
        return 'So, instructions would be printed here...'

    data = request.json
    data = data['source']
    print 'data is %s' % data
    return parseAddresses(data)


@app.route('/spec')
def spec():
    swag = swagger(app)
    swag['info']['version'] = '0.1'
    swag['info']['title'] = "BetaNYC 5 Borough's address finder"
    return jsonify(swag)
{'fraction_non_alphanumeric': 0.09753694581280788, 'fraction_numerical': 0.0090311986863711, 'mean_word_length': 1.479039479039479, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5585772', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1461, 'n_words': 430}