<commit_before>#-------------------------------------------------------------------------------
# Name:        badges
# Purpose:     Islandora Badges Application
#
# Author:      <NAME>
#
# Created:     16/09/2014
# Copyright:   (c) <NAME>, Colorado College, Islandora Foundation 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------
__author__ = "<NAME>"
__version_info__ = ('0', '0', '1')
__version__ = '.'.join(__version_info__)

import argparse
import json
import os
import urllib.request

from flask import abort, Flask, g, jsonify, redirect, render_template, request
from flask_negotiate import produces

badge_app = Flask(__name__)
project_root = os.path.abspath(os.path.dirname(__file__))

@badge_app.route("/badges/<badge_type>/<name>/<uid>")
@badge_app.route("/badges/<badge_type>/<name>/<uid>.json")
@produces('application/json')
def badge_assertion(badge_type, name, uid):
    """Route returns individual badge assertation json or 404 error if not
    found on disk.

    Args:
        badge_type: Badge Type (Camp, Projects, Institutions, etc.)
        name: Name of Badge
        uid: Unique ID of the Badge

    Returns:
        Assertion JSON of issued badge
    """
    badge_path = os.path.join(
        project_root,
        "badges",
        badge_type,
        name,
        "{}.json".format(uid))
    if not os.path.exists(badge_class_path):
        abort(404)
    badge = json.load(open(badge_path))
    return jsonify(badge)


@badge_app.route("/badges/<badge_type>/<name>")
@badge_app.route("/badges/<badge_type>/<name>.json")
@produces('application/json')
def badge_class(badge_type, name):
    """Route generates a JSON BadgeClass
    <https://github.com/mozilla/openbadges-specification/> for each Islandora
    badge.

    Args:
        badge_type: Badge Type (Camp, Projects, Institutions, etc.)
        name: Name of Badge

    Returns:
        Badge Class JSON
    """
    badge_class_path = os.path.join(
        project_root,
        "badges",
        badge_type,
        "{}.json".format(name))
    if not os.path.exists(badge_class_path):
        abort(404)
    badge_class = json.load(open(badge_class_path))
    return jsonify(badge_class)

@badge_app.route("/")
def index():
    return """<a href="http://islandora.ca/">Islandora</a>
<a href="http://openbadges.org/">Open Badge</a> issuer endpo"""

def main(host, port, debug=True):
    """Function runs the development application based on arguments passed in
    from the command-line.

    Args:
        host: Host name or IP address
        port: Port number
<commit_msg>still working on demo<commit_after>#-------------------------------------------------------------------------------
# Name:        badges
# Purpose:     Islandora Badges Application
#
# Author:      <NAME>
#
# Created:     16/09/2014
# Copyright:   (c) <NAME>, Colorado College, Islandora Foundation 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------
__author__ = "<NAME>"
__version_info__ = ('0', '0', '1')
__version__ = '.'.join(__version_info__)

import argparse
import json
import os
import urllib.request

from flask import abort, Flask, g, jsonify, redirect, render_template, request
from flask_negotiate import produces

badge_app = Flask(__name__)
project_root = os.path.abspath(os.path.dirname(__file__))

@badge_app.route("/badges/<badge_type>/<name>/<uid>")
@badge_app.route("/badges/<badge_type>/<name>/<uid>.json")
@produces('application/json')
def badge_assertion(badge_type, name, uid):
    """Route returns individual badge assertation json or 404 error if not
    found on disk.

    Args:
        badge_type: Badge Type (Camp, Projects, Institutions, etc.)
        name: Name of Badge
        uid: Unique ID of the Badge

    Returns:
        Assertion JSON of issued badge
    """
    badge_path = os.path.join(
        project_root,
        "badges",
        badge_type,
        name,
        "{}.json".format(uid))
    if not os.path.exists(badge_class_path):
        abort(404)
    badge = json.load(open(badge_path))
    return jsonify(badge)


@badge_app.route("/badges/<badge_type>/<name>")
@badge_app.route("/badges/<badge_type>/<name>.json")
@produces('application/json')
def badge_class(badge_type, name):
    """Route generates a JSON BadgeClass
    <https://github.com/mozilla/openbadges-specification/> for each Islandora
    badge.

    Args:
        badge_type: Badge Type (Camp, Projects, Institutions, etc.)
        name: Name of Badge

    Returns:
        Badge Class JSON
    """
    badge_class_path = os.path.join(
        project_root,
        "badges",
        badge_type,
        "{}.json".format(name))
    if not os.path.exists(badge_class_path):
        abort(404)
    badge_class = json.load(open(badge_class_path))
    return jsonify(badge_class)

@badge_app.route("/")
def index():
    return """<a href="http://islandora.ca/"><img src="http://islandora.ca/sites/default/files/Islandora.png"
alt="Islandora"></a>
<h1><a href="http://openbadges.org/">Open Badge</a> issuer endpoint</h1>"""

def main(host, port, debug=True):
    """Function runs the development application based on arguments passed in
    from the command-line.

    Args:
        host: Host name or IP address
        port: Port number

{'fraction_non_alphanumeric': 0.18375748502994013, 'fraction_numerical': 0.0093562874251497, 'mean_word_length': 2.580040187541862, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6999382', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1670, 'n_words': 405}