<commit_before>#!/usr/bin/python
#
# Photolandia JSON API server.
#

from flask import Flask, request, render_template, redirect, flash, jsonify, send_from_directory
from werkzeug import secure_filename

import json
import shutil
import os

from os import listdir

app = Flask(__name__)


@app.route("/")
def index():
    """Send a directories files."""
    #files = listdir("/Users/adam/Pictures")
    pics_dir = "/Users/adam/Pictures/"
    files = [] 
    for filename in os.listdir(pics_dir):
        if (filename[0] != '.' and not os.path.isdir(pics_dir + filename)):
            info = os.stat(pics_dir + filename)
            files.append({"file_name": filename, "mtime": info.st_mtime, "size": info.st_size})

    return jsonify({"files": files})


if __name__ == "__main__":
    app.debug = True
    app.run(host='0.0.0.0', port=5000)<commit_msg>Can upload JPG files to a fixed directory.<commit_after>#!/usr/bin/python
#
# Photolandia JSON API server.
#

from flask import Flask, request, render_template, redirect, flash, jsonify, send_from_directory
from werkzeug import secure_filename

import json
import shutil
import os

from os import listdir

app = Flask(__name__)

ALLOWED_EXTENSIONS = set(['jpg', 'JPG', 'png'])

@app.route("/", methods=['GET', 'POST'])
def index():
    """Send a directories files."""

    if request.method == 'GET':
        #files = listdir("/Users/adam/Pictures")
        pics_dir = "/Users/adam/Pictures/"
        files = [] 
        for filename in os.listdir(pics_dir):
            if (filename[0] != '.' and not os.path.isdir(pics_dir + filename)):
                info = os.stat(pics_dir + filename)
                files.append({"file_name": filename, "mtime": info.st_mtime, "size": info.st_size})

        #return jsonify({"files": files})
        return app.response_class(json.dumps(files), mimetype='application/json')
    else:
        #print "files:", request.files
        #print "data:", request.data
        #print "form:", request.form
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file_path = os.path.join('/Users/adam/Pictures', filename)
            file.save(file_path)

        return jsonify({"status": True})


def allowed_file(filename):
    """Only allow certain files to be uploaded."""
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


if __name__ == "__main__":
    app.debug = True
    app.run(host='0.0.0.0', port=5000)
{'fraction_non_alphanumeric': 0.14438291139240506, 'fraction_numerical': 0.007911392405063292, 'mean_word_length': 3.1663920922570017, 'pattern_counts': {'":': 11, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1391052', 'n_tokens_mistral': 838, 'n_tokens_neox': 801, 'n_words': 204}