def post(self): """Creates an Upload resource. Returns ------- """ f = request.files['file'] filename = secure_filename(path.split(f.filename)[1]) upload_dir = UPLOAD_DIR if filename in listdir(upload_dir): return make_response( jsonify('Resource of that name filename already exists.'), 400) elif not filename.endswith('csv'): return make_response( jsonify('Resource must consist of comma-separated values.'), 400) else: s = session() p = path.join(upload_dir, filename) u = Upload(p) f.save(p) s.add(u) s.commit() return make_response(jsonify('Resource created successfully.'), 201)
def goal_step_extractor(): """Decompose goal instances into goal-steps. """ s = session() goals = Goal.query.all() for goal in goals: print(goal.old_numbered, type(goal.old_numbered)) for each in goal.old_numbered: gs = GoalStep(each, goal.id) s.add(gs) s.commit()
def post(self): """Creates a User. Returns ------- """ data = request.get_json() if not User.validate_post_data(data): return abort(400) s = session() email = data.get('email') pw = data.get('password') u = User(email=email, password=pw) s.add(u) try: s.commit() except IntegrityError: return abort(500) return make_response(jsonify({'email': email}), 201)
def delete(self, _id): """Detroys an Upload resource. Parameters ---------- _id Returns ------- """ if Upload.validate_delete_data(request.get_json()): s = session() data = request.get_json() else: return abort(400) if id_validator(_id, s, Upload): upload = s.query(Upload).filter_by(id=_id).first() else: return abort(404) s.delete(upload) s.commit() return make_response(jsonify('Resource deleted successfully'), 202)
def delete(self, _id): """ Parameters ---------- _id Returns ------- """ data = request.get_json() if not User.validate_delete_data(data): return abort(400) s = session() if not id_validator(_id, s, User): return abort(404) user = s.query(User).filter_by(id=_id).first() pw = data.get('password') if not user.authenticate(pw): return abort(401) s.delete(user) s.commit() return make_response(jsonify('Resource deleted successfully.'), 202)
# -*- coding: utf-8 -*- import nltk from tcas.config import ENGLISH_PICKLE from tcas.db import database_session as session from tcas.abstract.model.goal_step import GoalStep from tcas.abstract.model.goal import Goal s = session() detector = nltk.data.load(ENGLISH_PICKLE) def process(data, cls, source): """ Parameters ---------- cls : sqlalchemy.ext.declarative.api.DeclarativeMeta data : str source : str Returns ------- """ goal_sentences = detector.tokenize(data) for sentence in goal_sentences: instance = cls(sentence, source) s.add(instance) s.commit() def goal_abstractor(goal_series): """Abstract goals from pandas.Series objects.