diff --git a/corretor.py b/corretor.py new file mode 100644 index 0000000..e46fd76 --- /dev/null +++ b/corretor.py @@ -0,0 +1,55 @@ +import pbclient +import os +import pyutil + +class Corretor: + + def __init__(self, configuration, template_env): + self.config = configuration + self.env = template_env + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) + pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) + + def __find_project(self, app_short_name): + projects = pbclient.find_project(short_name=app_short_name) + return projects[0] if len(projects) > 0 else None + + def __setup_project(self, project): + self.__create_tasks(project) + self.__update_project_info(project) + + def __create_tasks(self, project): + test_signs = ["ENSINADO", "ENTANTO", "ENTENDIDO"] + for sign in test_signs: + task = dict(sign_name=sign) + pbclient.create_task(project.id, task) + + def __update_project_info(self, project): + template = self.env.get_template('template.html') + project.info['task_presenter'] = template.render(server=self.config['HOST_ENDPOINT']) + project.info['thumbnail'] = self.config['HOST_ENDPOINT'] + "/img/thumbnail.png" + pbclient.update_project(project) + + def create_project(self): + app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] + project = self.__find_project(app_short_name) + result_msg = "" + if (project): + result_msg = "The project " + app_short_name + " was already created." + else: + project = pbclient.create_project(self.config['PYBOSSA_APP_NAME'], app_short_name, self.config['PYBOSSA_APP_DESCRIPTION']) + if (project): + self.__setup_project(project) + result_msg = "The project " + app_short_name + " was created." + else: + result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details." + pyutil.log(result_msg) + return result_msg + + def update_project(self): + app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] + project = self.__find_project(app_short_name) + self.__update_project_info(project) + result_msg = "The project " + app_short_name + " was updated." + pyutil.log(result_msg) + return result_msg \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..a6a47b8 --- /dev/null +++ b/main.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +from flask import Flask, send_from_directory +from jinja2 import Environment, PackageLoader +from corretor import Corretor +import os +import pyutil + +app = Flask(__name__) +controller = None + +@app.route('/') +def send_static_files(path): + root_dir = os.path.abspath(os.path.dirname(__file__)) + file_dir = os.path.join(root_dir, "view") + return send_from_directory(file_dir, path) + +@app.route("/update_project") +def update_project(): + try: + return controller.update_project() + except: + pyutil.print_stack_trace() + raise + +@app.route("/create_project") +def create_project(): + try: + return controller.create_project() + except: + pyutil.print_stack_trace() + raise + +def read_settings(app): + here = os.path.abspath(__file__) + config_path = os.path.join(os.path.dirname(here), 'settings_local.py') + if os.path.exists(config_path): + app.config.from_pyfile(config_path) + app.config['HOST_ENDPOINT'] = "http://" + app.config['SERVER_HOST'] + ":" + str(app.config['SERVER_PORT']) + +def setup_controller(): + global controller + read_settings(app) + env = Environment(loader=PackageLoader('main', 'view')) + controller = Corretor(app.config, env) + +def run(): + setup_controller() + app.run(port=app.config['SERVER_PORT']) + +if __name__ == '__main__': + try: + run() + except: + pyutil.print_stack_trace() + raise \ No newline at end of file diff --git a/pyutil.py b/pyutil.py new file mode 100644 index 0000000..57b08da --- /dev/null +++ b/pyutil.py @@ -0,0 +1,58 @@ +# -*- coding: UTF-8 -*- + +import datetime +import logging +import os +import shutil +import sys + +# @def funcao para obter data e hora atual do sistema +# @param string formato de data e hora +# @return string retorna data e hora do sistema no momento da chamada +def getTimeStamp(date_fmt = "%Y-%m-%d %H:%M:%S.%f"): + if ("%f" in date_fmt): + # [:-3] remove 3 casas decimais dos milisegundos (ms) + return datetime.datetime.now().strftime(date_fmt)[:-3] + else: + return datetime.datetime.now().strftime(date_fmt) + +# @def funcao para gravar log dos eventos em arquivo +# @param string mensagem a ser salva +# @param int indice do tipo de log 0: apenas print, 1: debug, 2: info, 3: warn, 4: error, 5: critical +# @param string caminho completo do arquivo de logs +# @param string formato de tempo utilizado +# @return none +def log(msg = "", log_level = 2, log_file = "events.log"): + dict_level = { + 0: ["Print", None, None], + 1: ["DEBUG", logging.DEBUG, logging.debug], + 2: ["INFO", logging.INFO, logging.info], + 3: ["WARNING", logging.WARN, logging.warn], + 4: ["ERROR", logging.ERROR, logging.error], + 5: ["CRITICAL", logging.CRITICAL, logging.critical] + } + # log_format = "[%(asctime)s.%(msecs).03d] %(levelname)s: : %(message)s" + log_format = "[%(asctime)s.%(msecs).03d] %(levelname)s: %(message)s" + date_fmt = "%Y-%m-%d %H:%M:%S" + logging.basicConfig(filename = log_file, datefmt = date_fmt, format = log_format, level = dict_level[log_level][1]) + logging.Formatter(fmt = "%(asctime)s", datefmt = date_fmt) + log_level %= len(dict_level) + write_mode = dict_level[log_level][2] + print("[%s] %s: %s" % (getTimeStamp(), dict_level[log_level][0], msg)) + if (write_mode != None): + write_mode(msg) + return + +# @def funcao para exibir excecao +# @param string deve ser passado: "__file__" para identificar em qual modulo ocorreu a excecao +# @return int retorna 1 +def print_stack_trace(): + error = "\n File name: %s\n Function name: %s\n Line code: %s\n Type exception: %s\n Message: %s" % ( + os.path.basename(sys.exc_info()[2].tb_frame.f_code.co_filename), + sys.exc_info()[2].tb_frame.f_code.co_name, + sys.exc_info()[2].tb_lineno, + sys.exc_info()[0].__name__, + sys.exc_info()[1] + ) + log(error, 4) + return 1 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0dcf078 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.9 +pybossa-client \ No newline at end of file diff --git a/settings_local.py.tmpl b/settings_local.py.tmpl new file mode 100644 index 0000000..5300c1d --- /dev/null +++ b/settings_local.py.tmpl @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Corretor Server Configuration +SERVER_HOST = "localhost" +SERVER_PORT = 8000 + +# PyBossa Configuration +PYBOSSA_APP_NAME = "Corretor de Sinais" +PYBOSSA_APP_SHORT_NAME = "corretor_sinais" +PYBOSSA_APP_DESCRIPTION = "Esse projeto ajudará a comunidade a melhorar sinais com movimentos complexos." +PYBOSSA_ENDPOINT = "http://localhost:5000" +PYBOSSA_API_KEY = "my-api-key" \ No newline at end of file diff --git a/view/assets/css/main.css b/view/assets/css/main.css new file mode 100644 index 0000000..8448ac2 --- /dev/null +++ b/view/assets/css/main.css @@ -0,0 +1,49 @@ + +header, section, footer, aside, nav, main, article, figure { + display: block; +} + +header { + text-align: center; + margin-bottom: 20px; + border-bottom: 1px solid rgba(230, 230, 230, 1.0);; +} + +h1, h2, h3, h4,h5, h6 { + color: rgba(125, 200, 255, 1.0); + font-family: verdana; +} + +.row { + margin-left: 1%; + margin-right: 1%; +} + +.input-group { + width: 100%; +} + +.btn-info { + width: 100%; +} + +.btn-file { + position: relative; + overflow: hidden; +} + +.btn-file input[type=file] { + position: absolute; + top: 0; + right: 0; + min-width: 100%; + min-height: 100%; + font-size: 100px; + text-align: right; + /* filter: alpha(opacity=0); */ + opacity: 0; + outline: none; + background: white; + cursor: inherit; + display: block; +} diff --git a/view/img/blender.svg b/view/img/blender.svg new file mode 100644 index 0000000..bc1a3a9 --- /dev/null +++ b/view/img/blender.svg @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + diff --git a/view/img/thumbnail.png b/view/img/thumbnail.png new file mode 100644 index 0000000..1d20efe Binary files /dev/null and b/view/img/thumbnail.png differ diff --git a/view/index.html b/view/index.html new file mode 100644 index 0000000..d3662eb --- /dev/null +++ b/view/index.html @@ -0,0 +1,62 @@ + + + Corretor de Sinais + + + + + + +
+
+

Corretor de Sinais

+
+
+

+

+ +
+

+

+

+ +
+

+
+
+

+

+

+

+

+

+
+
+

+

+

+

+

+
+ + + + +
+
+

+
+
+ + + + + diff --git a/view/template.html b/view/template.html new file mode 100644 index 0000000..04d72d9 --- /dev/null +++ b/view/template.html @@ -0,0 +1,108 @@ + + + +
+ +
+ +
+

Nome do Sinala:

+
+

+

+ +
+

+

+

+ +
+

+
+ +
+

+

+

+

+

+
+ + + +
+
+

+
+
+ + + + diff --git a/view/videos/.gitempty b/view/videos/.gitempty new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/view/videos/.gitempty diff --git a/view/videos/ENSINADO_AVATAR.blend b/view/videos/ENSINADO_AVATAR.blend new file mode 100644 index 0000000..bd8b678 Binary files /dev/null and b/view/videos/ENSINADO_AVATAR.blend differ diff --git a/view/videos/ENSINADO_AVATAR.mp4 b/view/videos/ENSINADO_AVATAR.mp4 new file mode 100644 index 0000000..3f55030 Binary files /dev/null and b/view/videos/ENSINADO_AVATAR.mp4 differ diff --git a/view/videos/ENSINADO_AVATAR.webm b/view/videos/ENSINADO_AVATAR.webm new file mode 100644 index 0000000..daa1f9d Binary files /dev/null and b/view/videos/ENSINADO_AVATAR.webm differ diff --git a/view/videos/ENSINADO_REF.mp4 b/view/videos/ENSINADO_REF.mp4 new file mode 100644 index 0000000..c47d6d9 Binary files /dev/null and b/view/videos/ENSINADO_REF.mp4 differ diff --git a/view/videos/ENSINADO_REF.webm b/view/videos/ENSINADO_REF.webm new file mode 100644 index 0000000..5a6c143 Binary files /dev/null and b/view/videos/ENSINADO_REF.webm differ diff --git a/view/videos/ENTANTO_AVATAR.blend b/view/videos/ENTANTO_AVATAR.blend new file mode 100644 index 0000000..69bb9ac Binary files /dev/null and b/view/videos/ENTANTO_AVATAR.blend differ diff --git a/view/videos/ENTANTO_AVATAR.mp4 b/view/videos/ENTANTO_AVATAR.mp4 new file mode 100644 index 0000000..39c76d0 Binary files /dev/null and b/view/videos/ENTANTO_AVATAR.mp4 differ diff --git a/view/videos/ENTANTO_AVATAR.webm b/view/videos/ENTANTO_AVATAR.webm new file mode 100644 index 0000000..d80339e Binary files /dev/null and b/view/videos/ENTANTO_AVATAR.webm differ diff --git a/view/videos/ENTANTO_REF.mp4 b/view/videos/ENTANTO_REF.mp4 new file mode 100644 index 0000000..392c247 Binary files /dev/null and b/view/videos/ENTANTO_REF.mp4 differ diff --git a/view/videos/ENTANTO_REF.webm b/view/videos/ENTANTO_REF.webm new file mode 100644 index 0000000..b9ac680 Binary files /dev/null and b/view/videos/ENTANTO_REF.webm differ diff --git a/view/videos/ENTENDIDO_AVATAR.blend b/view/videos/ENTENDIDO_AVATAR.blend new file mode 100644 index 0000000..dc82dba Binary files /dev/null and b/view/videos/ENTENDIDO_AVATAR.blend differ diff --git a/view/videos/ENTENDIDO_AVATAR.mp4 b/view/videos/ENTENDIDO_AVATAR.mp4 new file mode 100644 index 0000000..003df6d Binary files /dev/null and b/view/videos/ENTENDIDO_AVATAR.mp4 differ diff --git a/view/videos/ENTENDIDO_AVATAR.webm b/view/videos/ENTENDIDO_AVATAR.webm new file mode 100644 index 0000000..fd64277 Binary files /dev/null and b/view/videos/ENTENDIDO_AVATAR.webm differ diff --git a/view/videos/ENTENDIDO_REF.mp4 b/view/videos/ENTENDIDO_REF.mp4 new file mode 100644 index 0000000..49b91fc Binary files /dev/null and b/view/videos/ENTENDIDO_REF.mp4 differ diff --git a/view/videos/ENTENDIDO_REF.webm b/view/videos/ENTENDIDO_REF.webm new file mode 100644 index 0000000..b5bf46e Binary files /dev/null and b/view/videos/ENTENDIDO_REF.webm differ diff --git a/views/assets/css/main.css b/views/assets/css/main.css deleted file mode 100644 index 8448ac2..0000000 --- a/views/assets/css/main.css +++ /dev/null @@ -1,49 +0,0 @@ - -header, section, footer, aside, nav, main, article, figure { - display: block; -} - -header { - text-align: center; - margin-bottom: 20px; - border-bottom: 1px solid rgba(230, 230, 230, 1.0);; -} - -h1, h2, h3, h4,h5, h6 { - color: rgba(125, 200, 255, 1.0); - font-family: verdana; -} - -.row { - margin-left: 1%; - margin-right: 1%; -} - -.input-group { - width: 100%; -} - -.btn-info { - width: 100%; -} - -.btn-file { - position: relative; - overflow: hidden; -} - -.btn-file input[type=file] { - position: absolute; - top: 0; - right: 0; - min-width: 100%; - min-height: 100%; - font-size: 100px; - text-align: right; - /* filter: alpha(opacity=0); */ - opacity: 0; - outline: none; - background: white; - cursor: inherit; - display: block; -} diff --git a/views/img/blender.svg b/views/img/blender.svg deleted file mode 100644 index bc1a3a9..0000000 --- a/views/img/blender.svg +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - Jakub Steiner - - - http://jimmac.musichall.cz - - - - - - - - - - - - - - - - - - - - - diff --git a/views/index.html b/views/index.html deleted file mode 100644 index d3662eb..0000000 --- a/views/index.html +++ /dev/null @@ -1,62 +0,0 @@ - - - Corretor de Sinais - - - - - - -
-
-

Corretor de Sinais

-
-
-

-

- -
-

-

-

- -
-

-
-
-

-

-

-

-

-

-
-
-

-

-

-

-

-
- - - - -
-
-

-
-
- - - - - diff --git a/views/videos/.gitempty b/views/videos/.gitempty deleted file mode 100644 index e69de29..0000000 --- a/views/videos/.gitempty +++ /dev/null -- libgit2 0.21.2