<commit_before>from flask import render_template, request, Markup, redirect, url_for, abort
from flask.ext.login import current_user

from models import Task, Minute

from viaduct.blueprints.group.models import Group
from viaduct.blueprints.user.models import User

from viaduct import db, application


import datetime
import re


DATE_FORMAT = application.config['DATE_FORMAT']

class PimpyAPI:


	@staticmethod
	def commit_minute_to_db(content, date, group_id, parse_tasks):
		"""
		Returns succes (boolean), message (string). Message is irrelevant if
		success is true, otherwise it contains what exactly went wrong.

		In case of succes the minute is entered into the database
		"""

		try:
			date = datetime.datetime.strptime(date, DATE_FORMAT)
		except:
			if date != "":
				return False, "Could not parse the date"
			date = None

		minute = Minute(content, group_id, date)
		db.session.add(minute)
		db.session.commit()

		if parse_tasks:
			PimpyAPI.parse_minute(content, group_id, minute.id)

		return True, "jaja"


	@staticmethod
	def commit_task_to_db(name, content, deadline, group_id,
		filled_in_users, line, minute_id, status):
		"""
		Returns succes (boolean), message (string). Message is irrelevant if
		success is true, otherwise it contains what exactly went wrong.

		In case of succes the task is entered into the database
		"""

		if group_id == 'all':
			return False, "Group can not be 'all'"
		group = Group.query.filter(Group.id==group_id).first()
		if group == None:
			return False, "Could not distinguish group."

		users, message = PimpyAPI.get_list_of_users_from_string(group,
			filled_in_users)
		if not users:
			return False, message

		try:
			deadline = datetime.datetime.strptime(deadline, DATE_FORMAT)
		except:
			if deadline != "":
				return False, "Could not parse the deadline"
			deadline = None

		print "MINUTE ID OF NEWLY CREATED PIMPY TASK: ", minute_id
		if minute_id <= 0:
			minute_id = 999
		print "MINUTE ID OF NEWLY CREATED PIMPY TASK: ", minute_id

		task = Task(name, content, deadline, group_id,
				users, line, minute_id, status)
		db.session.add(task)
		db.session.commit()
		return True, "jaja"

	@staticmethod
	def parse_minute(content, group_id, minute_id):
		"""
		Parses the specified minutes for tasks and adds them to the database.

		syntax within the content:
		ACTIE <name_1>, <name_2>, name_n>: <title of task>
		or
		TODO <name_1>, <name_2>, name_n>: <title of task>

		Returns succes (boolean), message (string). Message is irrelevant if
		success is true, otherwise it contains what exactly went wrong.
		"""

		regex = re.compile("\s*(?:ACTIE|TODO) ([^\n\r]*)")<commit_msg>I have to test this on an sql-db, for the very last time?<commit_after>from flask import render_template, request, Markup, redirect, url_for, abort
from flask.ext.login import current_user

from models import Task, Minute

from viaduct.blueprints.group.models import Group
from viaduct.blueprints.user.models import User

from viaduct import db, application


import datetime
import re


DATE_FORMAT = application.config['DATE_FORMAT']

class PimpyAPI:


	@staticmethod
	def commit_minute_to_db(content, date, group_id, parse_tasks):
		"""
		Returns succes (boolean), message (string). Message is irrelevant if
		success is true, otherwise it contains what exactly went wrong.

		In case of succes the minute is entered into the database
		"""

		try:
			date = datetime.datetime.strptime(date, DATE_FORMAT)
		except:
			if date != "":
				return False, "Could not parse the date"
			date = None

		minute = Minute(content, group_id, date)
		db.session.add(minute)
		db.session.commit()

		if parse_tasks:
			PimpyAPI.parse_minute(content, group_id, minute.id)

		return True, "jaja"


	@staticmethod
	def commit_task_to_db(name, content, deadline, group_id,
		filled_in_users, line, minute_id, status):
		"""
		Returns succes (boolean), message (string). Message is irrelevant if
		success is true, otherwise it contains what exactly went wrong.

		In case of succes the task is entered into the database
		"""

		if group_id == 'all':
			return False, "Group can not be 'all'"
		group = Group.query.filter(Group.id==group_id).first()
		if group == None:
			return False, "Could not distinguish group."

		users, message = PimpyAPI.get_list_of_users_from_string(group,
			filled_in_users)
		if not users:
			return False, message

		try:
			deadline = datetime.datetime.strptime(deadline, DATE_FORMAT)
		except:
			if deadline != "":
				return False, "Could not parse the deadline"
			deadline = None

		print "MINUTE ID OF NEWLY CREATED PIMPY TASK: ", minute_id
		if minute_id <= 0:
			minute_id = 1
		print "MINUTE ID OF NEWLY CREATED PIMPY TASK: ", minute_id

		task = Task(name, content, deadline, group_id,
				users, minute_id, line, status)
		db.session.add(task)
		db.session.commit()
		return True, "jaja"

	@staticmethod
	def parse_minute(content, group_id, minute_id):
		"""
		Parses the specified minutes for tasks and adds them to the database.

		syntax within the content:
		ACTIE <name_1>, <name_2>, name_n>: <title of task>
		or
		TODO <name_1>, <name_2>, name_n>: <title of task>

		Returns succes (boolean), message (string). Message is irrelevant if
		success is true, otherwise it contains what exactly went wrong.
		"""

		regex = re.compile("\s*(?:ACTIE|TODO) ([^\n\r]*)")
{'fraction_non_alphanumeric': 0.09772047832585949, 'fraction_numerical': 0.002615844544095665, 'mean_word_length': 4.107824427480916, 'pattern_counts': {'":': 4, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, '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': '905024', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1684, 'n_words': 585}