Example #1
0
import os
from flask import Flask
from hashids import Hashids
from flask_sqlalchemy import SQLAlchemy

basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config["DEBUG"] = True
app.config["SECRET_KEY"] = "secret"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(os.getcwd(), 'onsmash.db')
app.config["UPLOAD_FOLDER"] = os.path.join(os.getcwd(), "THUMBNAILS")
app.config["ALLOWED_EXTENSIONS"] = ['png', 'jpg', 'jpeg', 'gif']

db = SQLAlchemy(app)
hashids = Hashids(salt=app.config["SECRET_KEY"])

import views
import models
Example #2
0
'''

import os

from flask import Flask, jsonify, abort, make_response, render_template
from flask_httpauth import HTTPBasicAuth

app = Flask(__name__, static_url_path="")   # pylint: disable=invalid-name
app.config.from_object("config")
app.debug = True
auth = HTTPBasicAuth()  # pylint: disable=invalid-name

# This is the path to the upload directory
app.config["UPLOAD_FOLDER"] = "uploads"
# These are the extension that we are accepting to be uploaded
app.config["ALLOWED_EXTENSIONS"] = set(["txt", "pdf", "png", "jpg", "jpeg", "gif", "py"])
# create upload folder if not exist
if not os.path.exists(app.config["UPLOAD_FOLDER"]):
    os.makedirs(app.config["UPLOAD_FOLDER"])

# redefine jinja start/end string to avoid conflict with AngularJS
app.jinja_env.variable_start_string = "{[{ "
app.jinja_env.variable_end_string = " }]}"

# use different static/templates folder with different mode
if not app.debug:
    app.template_folder = "build/templates"
    app.static_folder = "build/static"
else:
    app.template_folder = "src/templates"
    app.static_folder = "src/static"
Example #3
0
from flask import Flask

app = Flask(__name__)
app.config.from_object("config")
app.config["UPLOAD_FOLDER"] = "uploads/"
app.config["ALLOWED_EXTENSIONS"] = set(["csv"])

from app import views
Example #4
0
from pyqrcode import create as create_qrcode
from os import listdir, makedirs, remove
from os.path import isdir, isfile, join
from json import dumps, loads
from random import randint
from re import sub
from config import host_address as host, host_port as port, public_ip as ip
from config import admin_credentials
from sys import argv

argv.pop(0)

app = Flask(__name__)

app.config["UPLOAD_FOLDER"] = "uploads/"
app.config["ALLOWED_EXTENSIONS"] = ["pdf"]


@app.route("/")
def homepage():
    AUTHORS = []
    CATEGORIES = []
    LANGUAGES = []
    NUM_BOOKS = len(listdir("books"))
    for book in listdir("books"):
        book_data = loads(open("books/%s/data.json" % book, "r").read())
        for author in book_data["authors"]:
            author = author.title()
            if author not in AUTHORS:
                AUTHORS.append(author)
        for category in book_data["categories"]:
Example #5
0
# using the request object from flask. Redirect and url_for
# will be used to redirect the user once the upload is done
# and send_from_directory will help us to send/show on the
# browser the file that the user just uploaded
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug.utils import secure_filename

# Initialize the Flask application
app = Flask(__name__)

# script_dir = os.path.dirname(__file__)
# This is the path to the upload directory
app.config["UPLOAD_FOLDER"] = "uploads/"
app.config["OUTPUT_FOLDER"] = "output/"
# These are the extension that we are accepting to be uploaded
app.config["ALLOWED_EXTENSIONS"] = set(["txt", "pdf"])

# For a given file, return whether it's an allowed type or not
def allowed_file(filename):
    return "." in filename and filename.rsplit(".", 1)[1] in app.config["ALLOWED_EXTENSIONS"]


# This route will show a form to perform an AJAX request
# jQuery is loaded to execute the request and update the
# value of the operation
@app.route("/")
def index():
    return render_template("index.html")


@app.errorhandler(500)
from flask.views import MethodView
from flask.ext.restful import Api
from flask.ext.httpauth import HTTPBasicAuth
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
api = Api(app)
auth = HTTPBasicAuth()

try:
    import config

    app.config.from_object(config.Development)
except ImportError:
    app.config["ALLOWED_EXTENSIONS"] = {"txt", "mp4", "png", "jpg", "jpeg", "gif", "blend", "zip"}
    app.config["STORAGE_BUNDLES"] = "/tmp/bam_storage_bundles"


db = SQLAlchemy(app)
log = logging.getLogger("webservice")

from application.modules.resources import DirectoryAPI
from application.modules.resources import FileAPI

if os.environ.get("BAM_VERBOSE"):
    logging.basicConfig(level=logging.DEBUG)


@auth.get_password
def get_password(username):
Example #7
0
from flask import Flask, render_template, request, redirect, url_for
from lxml import html
import requests
import re
import xlwt
import os
from werkzeug import secure_filename
import route_parser

app = Flask(__name__)

# Upload path for the xlsx files
app.config["UPLOAD_FOLDER"] = os.path.abspath(os.curdir) + "/uploads"

# We will be accpeting files with a xlsx extension
app.config["ALLOWED_EXTENSIONS"] = set(["xlsx"])


@app.route("/webscrape", methods=["POST"])
def webscrape():
    url = request.form["url"]

    # We check if this is a valid url before doing anything more
    regex = getregex()
    if regex.match(url):
        # Web scraping guide here - http://docs.python-guide.org/en/latest/scenarios/scrape/
        page = requests.get(url)
        tag = request.form["tag"]

        try:
            tree = html.fromstring(page.content)
Example #8
0
import os

# We'll render HTML templates and access data sent by POST
# using the request object from flask. Redirect and url_for
# will be used to redirect the user once the upload is done
# and send_from_directory will help us to send/show on the
# browser the file that the user just uploaded
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, session
from werkzeug import secure_filename

app = Flask(__name__)

# This is the path to the upload directory
app.config["UPLOAD_FOLDER"] = "uploads/"
# These are the extension that we are accepting to be uploaded
app.config["ALLOWED_EXTENSIONS"] = set(["jpg"])

# For a given file, return whether it's an allowed type or not
def allowed_file(filename):
    return "." in filename and filename.rsplit(".", 1)[1] in app.config["ALLOWED_EXTENSIONS"]


# This route will show a form to perform an AJAX request
# jQuery is loaded to execute the request and update the
# value of the operation
@app.route("/uploader")
def uploader():
    return render_template("index.html")


# Route that will process the file upload
    try:
        query = cv2.imread(filename)
    except TypeError:
        query = cv2.imdecode(filename)
    features = COLOR_DESC.describe(query)
    results = searcher.search(features)
    return results


# Initialize the Flask application
app = Flask(__name__)

# This is the path to the upload directory
app.config["UPLOAD_FOLDER"] = "uploads"
# These are the extension that we are accepting to be uploaded
app.config["ALLOWED_EXTENSIONS"] = set(["png", "jpg", "jpeg", "gif"])

# For a given file, return whether it's an allowed type or not
def allowed_file(filename):
    return "." in filename and filename.rsplit(".", 1)[1] in app.config["ALLOWED_EXTENSIONS"]


# This route will show a form to perform an AJAX request
# jQuery is loaded to execute the request and update the
# value of the operation
@app.route("/")
def index():
    return render_template("index.html")


# Route that will process the file upload