예제 #1
0
 def POST(self):
     global last_status
     data = web.input()
     last_status = '<p>Connecting to PyBossa <i class="loading"></i></p>'
     # check endpoint and api_key
     pbclient.set('endpoint', data.endpoint)
     pbclient.set('api_key', data.api_key)
     app = pbclient.find_app(short_name=data.appname)
     if len(app) == 0:
         last_status += '<p class="error" data-field="appname">PyBossa app not found.</p>'
     else:
         app = app[0]
         res = pbclient.update_app(app)
         if res == 403:
             last_status += '<p class="error" data-field="api_key">You\'re not allowed to edit that app. Double check your API key.</p>'
         else:
             last_status += '<p>Loading data from Google spreadsheet <i class="loading"></i></p>'
             url = 'http://spreadsheets.google.com/feeds/cells/%s/%s/public/basic?alt=json' % (data.spreadsheet, data.worksheet)
             r = requests.get(url)
             if r.status_code / 100 == 4:
                 last_status += '<p class="error" data-field="spreadsheet">The spreadsheet could not be found. Make sure that the key is right and that you properly shared the document (click on <i>File > Publish to the web</i>).</p>'
             else:
                 last_status += '<p>Parsing spreadsheet data <i class="loading"></i></p>'
                 tasks = parse_spreadsheet(r.json)
                 tmp = last_status
                 total = len(tasks)
                 completed = 0
                 for info in tasks:
                     info['n_answers'] = int(data.n_answers)
                     res = pbclient.create_task(app.id, info)
                     completed += 1
                     last_status = tmp + '<p>Uploading tasks to PyBossa (%d of %d)<i class="loading"></i></p>' % (completed, total)
                 last_status += '<p>finished.</p>'
     print ''
예제 #2
0
파일: app.py 프로젝트: geotagx/pybossa-nova
def send_data():
    api_key = request.json.get('api_key')
    server_url = request.json.get('server_url')
    data = request.json.get('data')
    project_name = request.json.get('project_name')

    tpl_presenter = render_template('presenter.html',
                                    steps=data['steps'],
                                    project_name=project_name)

    pbclient.set('endpoint', server_url)
    pbclient.set('api_key', api_key)

    # TODO: check error
    app = pbclient.find_app(short_name=project_name)[0]
    app.info['task_presenter'] = tpl_presenter

    for task in pbclient.find_tasks(app.id):
        pbclient.delete_task(task.id)

    for task in data['tasks']:
        pbclient.create_task(app.id, task)

    pbclient.update_app(app)

    return '', 200
예제 #3
0
def setup(*args, **kwargs):
    try:
        global pbclient
        import pbclient
        pbclient.set('endpoint', kwargs.get('server'))
        pbclient.set('api_key', kwargs.get('api_key'))
    except Exception as e:
        raise NidabaPluginException(e.message)
예제 #4
0
파일: __init__.py 프로젝트: PyBossa/enki
 def __init__(self, api_key, endpoint,
              project_short_name, all=0):
     """Initiate."""
     self.project = None
     self.all = all
     pbclient.set('api_key', api_key)
     pbclient.set('endpoint', endpoint)
     if self.project is None:
         self.project = self.get_project(project_short_name)
예제 #5
0
 def test_get_project_not_found(self, Mock):
     """Test get_project not found works"""
     # Project does not exist should return 404 error object
     pbclient.set('endpoint', 'http://localhost')
     pbclient.set('api_key', 'key')
     not_found = self.create_error_output(action='GET', status_code=404,
                                          target='project', exception_cls='NotFound')
     Mock.return_value = self.create_fake_request(not_found)
     err = self.client.get_project(1)
     self.check_error_output(err, not_found)
예제 #6
0
def cli(config, config_file, flickr_api, flickr_secret,
        pybossa_api, pybossa_server, pybossa_project):
    """Create the cli command line."""
    import flickrapi
    home = expanduser("~")
    if os.path.isfile(os.path.join(home, '.trapcamera.cfg')):
        # FLICKR config
        config.parser.read(os.path.join(home, '.trapcamera.cfg'))
        config.flickr_api = config.parser.get('flickr', 'api')
        config.flickr_secret = config.parser.get('flickr', 'secret')
        config.flickr_license_id = config.parser.get('flickr', 'license_id')
        config.flickr_photoset_name = config.parser.get('flickr',
                                                        'photoset_name')
        # DATA config
        config.offline = config.parser.get('data', 'offline')
        config.data = config.parser.get('data', 'images')
        # PYBOSSA config
        config.pybossa_api = config.parser.get('pybossa', 'api_key')
        config.pybossa_server = config.parser.get('pybossa', 'endpoint')
        config.pybossa_project = config.parser.get('pybossa', 'project_id')
        # CAMERA config
        config.camera_sharpness = literal_eval(config.parser.get('camera', 'sharpness'))
        config.camera_contrast = literal_eval(config.parser.get('camera', 'contrast'))
        config.camera_brightness = literal_eval(config.parser.get('camera', 'brightness'))
        config.camera_saturation = literal_eval(config.parser.get('camera', 'saturation'))
        config.camera_iso = literal_eval(config.parser.get('camera', 'ISO'))
        config.camera_video_stabilization = literal_eval(config.parser.get('camera',
                                                              'video_stabilization'))
        config.camera_exposure_compensation = literal_eval(config.parser.get('camera', 'exposure_compensation'))
        config.camera_exposure_mode = literal_eval(config.parser.get('camera', 'exposure_mode'))
        config.camera_meter_mode = literal_eval(config.parser.get('camera', 'meter_mode'))
        config.camera_awb_mode = literal_eval(config.parser.get('camera', 'awb_mode'))
        config.camera_image_effects = literal_eval(config.parser.get('camera', 'image_effect'))
        config.camera_color_effects = literal_eval(config.parser.get('camera', 'color_effects'))
        config.camera_rotation = literal_eval(config.parser.get('camera', 'rotation'))
        config.camera_hflip = literal_eval(config.parser.get('camera', 'hflip'))
        config.camera_vflip = literal_eval(config.parser.get('camera', 'vflip'))
        config.camera_crop = literal_eval(config.parser.get('camera', 'crop'))
        config.camera_resolution = literal_eval(config.parser.get('camera', 'resolution'))
    if flickr_api:
        config.flickr_api = flickr_api
    if flickr_secret:
        config.flickr_secret = flickr_secret

    config.flickrapi = flickrapi.FlickrAPI(config.flickr_api,
                                           config.flickr_secret,
                                           format='parsed-json')

    pbclient.set('endpoint', config.pybossa_server)
    pbclient.set('api_key', config.pybossa_api)

    config.pbclient = pbclient
예제 #7
0
    def __init__(self, options = None):
        self.get_configuration(options)

        pbclient.set('api_key', self.options.api_key)
        pbclient.set('endpoint', self.options.api_url)

        if self.options.verbose:
            print('Running against PyBosssa instance at: %s' % self.options.api_url)
            print('Using API-KEY: %s' % self.options.api_key)

        if self.options.create_app:
            pbclient.create_app(self.app_config['name'],
                                self.app_config['short_name'],
                                self.app_config['description'])
            self.setup_app()
        else:
            self.find_app_by_short_name()

        if self.options.create_task:
            self.create_task()

        if self.options.update_template:
            print "Updating app template"
            # discard return value
            self.setup_app()

        if self.options.update_tasks:
            def tasks():
                offset = 0
                limit = 100
                while True:
                    tasks = pbclient.get_tasks(self.app.id, offset=offset, limit=limit)
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)

            def update_task(task, count):
                print "Updating task: %s" % task.id
                if 'n_answers' in task.info:
                    del(task.info['n_answers'])
                task.n_answers = self.options.update_tasks
                pbclient.update_task(task)
                count[0] += 1

            print "Updating task n_answers"
            find_app_by_short_name()

            n_tasks = [0]
            [update_task(t, n_tasks) for t in tasks()]
            print "%s Tasks have been updated!" % n_tasks[0]
예제 #8
0
def setup():    
    # settings
    pbclient.set('api_key', "c008cbd5-7885-4c49-a0fe-6cdee926651f")
    pbclient.set('endpoint', 'http://localhost/pybossa')

    # Create the app
    #pbclient.create_app('Semantics Map','Semantics','What is the perceived relation between words? ');
    dir = os.path.dirname(__file__)
        
    #update app
    pyBossaApp = pbclient.find_app(short_name='Semantics')[0]
    pyBossaApp.long_description = contents(dir + '/../View/long_description.html')
    pyBossaApp.info['task_presenter'] = contents(dir + '/../View/template.html')
    pyBossaApp.info['thumbnail'] = "http://societic.ibercivis.es/semantics/static/images/icon.jpg"
    #pyBossaApp.info['tutorial'] = contents('tutorial.html')
    pyBossaApp.category_id = 1
    pbclient.update_app(pyBossaApp)

    #create tasks
    try:
        cnx = get_connection()
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            return "Something is wrong your username or password"
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
                return "Database does not exists"
        else:
            return err;
    else:
        #Get Data
        cursor = cnx.cursor()
        cursor.execute("SELECT * FROM startwords")
        words = cursor.fetchall()        
        cursor.close()
        cnx.close()

        #if (len(words)>0):            
        #    for item in words:
        #            task_info = dict(start=item[0],
        #                end=item[1],
        #                startWord=getWord(item[0]),
        #                endWord=getWord(item[1]) )
        #            pbclient.create_task(pyBossaApp.id, task_info)
        
    return "ok"
예제 #9
0
파일: server.py 프로젝트: JalfLSD/Sun4All
def setup():    
    # settings
    pbclient.set('api_key', "74690b3e-e980-4299-b006-9c6a5c50b355")
    pbclient.set('endpoint', 'http://pybossa.socientize.eu/pybossa')

    # Create the app
    #pbclient.create_app('Semantics Map','Semantics','What is the perceived relation between words? ');
    #update app
    pyBossaApp = pbclient.find_app(short_name='Sun4All')[0];
    #pyBossaApp.long_description = '- add long description -';
    #pyBossaApp.info['task_presenter'] = contents('template.html')
    #pyBossaApp.info['thumbnail'] = "http://societic.ibercivis.es/semantics/static/images/icon.jpg"
    #pyBossaApp.info['tutorial'] = contents('tutorial.html')
    #pbclient.update_app(pyBossaApp)

    #create tasks
    try:
        cnx = get_connection();
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            return "Something is wrong your username or password";
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
                return "Database does not exists";
        else:
            return err;
    else:
        #Get Data
        cursor = cnx.cursor();
        cursor.execute("SELECT * FROM images");
        words = cursor.fetchall();        
        cursor.close();
        cnx.close();

        if (len(words)>0):            
            for item in words:
                    task_info = dict(n_answers=5,
                        start=item[0],
                        end=item[1],
                        startWord=getWord(item[0]),
                        endWord=getWord(item[1]) )
                    pbclient.create_task(pyBossaApp.id, task_info)
        
    return "ok";
예제 #10
0
파일: settings.py 프로젝트: sorin/moonsheep
import pbclient

from django.conf import settings

# tasks sources
RANDOM_SOURCE = 'random'
PYBOSSA_SOURCE = 'pybossa'
DEFAULT_SOURCE = RANDOM_SOURCE

TASK_SOURCE = getattr(settings, 'MOONSHEEP_TASK_SOURCE', DEFAULT_SOURCE)
"""
If set Moonsheep won't communicate with PyBossa and will:
1. serve random mocked tasks
2. send form submissions straight to the verification
   won't test cross-checking as there is going to be only one entry, but will allow to test the whole flow  
"""

# pybossa endpoints
DEFAULT_PYBOSSA_URL = 'http://localhost:5000'
DEFAULT_PYBOSSA_PROJECT_ID = 1

PYBOSSA_BASE_URL = getattr(settings, 'PYBOSSA_URL',
                           DEFAULT_PYBOSSA_URL).rstrip('/')
PYBOSSA_API_BASE_URL = PYBOSSA_BASE_URL + "/api"
PYBOSSA_API_KEY = getattr(settings, 'PYBOSSA_API_KEY', '')
PYBOSSA_PROJECT_ID = getattr(settings, 'PYBOSSA_PROJECT_ID',
                             DEFAULT_PYBOSSA_PROJECT_ID)

pbclient.set('endpoint', PYBOSSA_BASE_URL)
pbclient.set('api_key', PYBOSSA_API_KEY)
예제 #11
0
        metavar="APP-CONFIG",
        default="app.json",
    )

    parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
    (options, args) = parser.parse_args()

    # Load app details
    try:
        with file(options.app_config) as app_json:
            app_config = json.load(app_json)
    except IOError as e:
        print "application config file is missing! Please create a new one"
        exit(1)

    pbclient.set("endpoint", options.api_url)

    if not options.api_key:
        parser.error(
            "You must supply an API-KEY to create an \
                      applicationa and tasks in PyBossa"
        )
    else:
        pbclient.set("api_key", options.api_key)

    if options.verbose:
        print ("Running against PyBosssa instance at: %s" % options.api_url)
        print ("Using API-KEY: %s" % options.api_key)

    def find_app_by_short_name():
        return pbclient.find_app(short_name=app_config["short_name"])[0]
예제 #12
0
                      help="Application config file",
                      metavar="APP-CONFIG",
                      default="app.json")

    parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
    (options, args) = parser.parse_args()

    # Load app details
    try:
        with file(options.app_config) as app_json:
            app_config = json.load(app_json)
    except IOError as e:
        print "application config file is missing! Please create a new one"
        exit(1)

    pbclient.set('endpoint', options.api_url)

    if not options.api_key:
        parser.error("You must supply an API-KEY to create an \
                      applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    def find_app_by_short_name():
        try:
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
예제 #13
0
def run(app_config, options):
    def check_api_error(api_response):
        """Check if returned API response contains an error"""
        if type(api_response) == dict and (api_response.get("status") == "failed"):
            raise exceptions.HTTPError

    def format_error(module, error):
        """Format the error for the given module"""
        logging.error(module)
        # Beautify JSON error
        if type(error) == list:
            print "Application not found"
        else:
            print json.dumps(error, sort_keys=True, indent=4, separators=(",", ": "))
        exit(1)

    def find_app_by_short_name():
        try:
            response = pbclient.find_app(short_name=app_config["short_name"])
            check_api_error(response)
            return response[0]
        except:
            format_error("pbclient.find_app", response)

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents("long_description.html")
        app.category_id = 5
        app.hidden = 1
        app.info["task_presenter"] = contents("template.html")
        app.info["thumbnail"] = app_config["thumbnail"]
        app.info["tutorial"] = contents("tutorial.html")

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
            return app
        except:
            format_error("pbclient.update_app", response)

    def create_photo_task(app, photo, question, priority=0):
        # Data for the tasks
        task_info = photo
        try:
            response = pbclient.create_task(app.id, task_info, priority_0=priority)
            check_api_error(response)
        except:
            format_error("pbclient.create_task", response)

    def add_photo_tasks(app):
        # First of all we get the URL photos
        # Then, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        photos = get_flickr_set_photos(options.photoset_id)
        question = app_config["question"]
        # [create_photo_task(app, p, question, priority=random.random()) for p in photos]
        # Estimate how many minutes it has to wait before reaching the limit
        # Limit is 300 tasks per 15 minutes
        wait = (15 * 60) / 300
        if len(photos) > 300:
            wait = wait + 1  # Adding one second will take 20 minutes to add 300 tasks
        print "Wait %s seconds between each create_task request" % wait
        for p in photos:
            create_photo_task(app, p, question, priority=0)
            time.sleep(wait)

    pbclient.set("api_key", options.api_key)
    pbclient.set("endpoint", options.api_url)

    if options.verbose:
        print ("Running against PyBosssa instance at: %s" % options.api_url)
        print ("Using API-KEY: %s" % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            try:
                response = pbclient.create_app(app_config["name"], app_config["short_name"], app_config["description"])

                check_api_error(response)
                app = setup_app()
            except:
                format_error("pbclient.create_app", response)
        else:
            app = find_app_by_short_name()
        add_photo_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:

        def tasks(app):
            offset = 0
            limit = 100
            while True:
                try:
                    tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                    check_api_error(tasks)
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)
                except:
                    format_error("pbclient.get_tasks", response)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if "n_answers" in task.info:
                del (task.info["n_answers"])
            task.n_answers = options.update_tasks
            try:
                response = pbclient.update_task(task)
                check_api_error(response)
                count[0] += 1
            except:
                format_error("pbclient.update_task", response)

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #14
0
    def __init__(self, options = None):
        if options:
            self.options = options
        else:
            self.handle_arguments()

        if self.options.list:
            for appjson in glob.glob(os.path.join(os.path.dirname(__file__), "*", "app.json")):
                with open(appjson) as f:
                    config = json.load(f)
                    config['dirname'] = os.path.split(os.path.split(appjson)[0])[1]
                    print """%(dirname)s
    %(name)s
    %(description)s
""" % config
            return

        self.get_configuration()

        self.handle_result(pbclient.set('api_key', self.options.api_key))
        self.handle_result(pbclient.set('endpoint', self.options.api_url))

        if self.options.verbose:
            print('Running against PyBosssa instance at: %s' % self.options.api_url)
            print('Using API-KEY: %s' % self.options.api_key)

        if self.options.create_app:
            self.handle_result(
                pbclient.create_app(self.app_config['name'],
                                    self.app_config['short_name'],
                                    self.app_config['description']))
            self.setup_app()
        else:
            self.find_app_by_short_name()

        if self.options.load_tasks:
            self.load_tasks()

        if self.options.create_task:
            self.create_task()

        if self.options.update_template:
            print "Updating app template"
            # discard return value
            self.setup_app()

        if self.options.update_tasks:
            def tasks():
                offset = 0
                limit = 100
                while True:
                    tasks = self.handle_result(pbclient.get_tasks(self.app.id, offset=offset, limit=limit))
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)

            def update_task(task, count):
                print "Updating task: %s" % task.id
                if 'n_answers' in task.info:
                    del(task.info['n_answers'])
                task.n_answers = self.options.update_tasks
                self.handle_result(pbclient.update_task(task))
                count[0] += 1

            print "Updating task n_answers"
            self.find_app_by_short_name()

            n_tasks = [0]
            [update_task(t, n_tasks) for t in tasks()]
            print "%s Tasks have been updated!" % n_tasks[0]
예제 #15
0
    parser.add_argument("-n", "--number-answers", help="Number of answers per task", default=1)
    # Verbose?
    parser.add_argument("-v", "--verbose", action="store_true")

    args = parser.parse_args()

    # Load app details
    try:
        app_json = open('app.json')
        app_config = json.load(app_json)
        app_json.close()
    except IOError as e:
        print "app.json is missing! Please create a new one"
        exit(0)

    pbclient.set('endpoint', args.server)
    pbclient.set('api_key', args.api_key)

    if args.verbose:
        print('Running against PyBosssa instance at: %s' % args.server)
        print('Using API-KEY: %s' % args.api_key)

    if args.create_app:
        try:
            response = pbclient.create_app(app_config['name'],
                                           app_config['short_name'],
                                           app_config['description'])
            check_api_error(response)
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            app = response[0]
예제 #16
0
def run(app_config, options):
    def find_app_by_short_name():
        return pbclient.find_app(short_name=app_config['short_name'])[0]

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        pbclient.update_app(app)
        return app

    def create_phrasal_verb_task(app, phrasal_verb, exemplo_parte_1, verbo, exemplo_parte_2, particula, exemplo_parte_3, question1, question2):
        # Data for the tasks
        task_info = dict(question1=question1,
                         question2=question2,
                         n_answers=5,
                         phrasal_verb=phrasal_verb,
                         exemplo_parte_1=exemplo_parte_1,
                         verbo=verbo,
                         exemplo_parte_2=exemplo_parte_2,
                         particula=particula,
                         exemplo_parte_3=exemplo_parte_3)
        pbclient.create_task(app.id, task_info)

    def add_phrasal_verbs_tasks(app):
        question1 = app_config['question1']
        question2 = app_config['question2']

        phrasal_verbs = get_phrasal_verbs()

        for phrasal_verb_object in phrasal_verbs:

	    phrasal_verb = phrasal_verb_object['phrasal_verb']
	    exemplo_parte_1 = phrasal_verb_object['exemplo_parte_1'] 
	    verbo = phrasal_verb_object['verbo']
	    exemplo_parte_2 = phrasal_verb_object['exemplo_parte_2']
	    particula = phrasal_verb_object['particula']
	    exemplo_parte_3 = phrasal_verb_object['exemplo_parte_3']

            create_phrasal_verb_task(app, phrasal_verb, exemplo_parte_1, verbo, exemplo_parte_2, particula, exemplo_parte_3, question1, question2)

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            pbclient.create_app(app_config['name'],
                                app_config['short_name'],
                                app_config['description'])

            app = setup_app()
        else:
            app = find_app_by_short_name()
        add_phrasal_verbs_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app): 
            offset = 0
            limit = 100
            while True:
                tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                if len(tasks) == 0:
                    break
                for task in tasks:
                    yield task
                offset += len(tasks)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            pbclient.update_task(task)
            count[0] += 1

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
def run(app_config, options):
    def find_app_by_short_name():
        return pbclient.find_app(short_name=app_config['short_name'])[0]

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        pbclient.update_app(app)
        return app

    def create_msg_task(app, msg, question):
        # Data for the tasks
        # msgs_text and msgs_html are lists, hence 'msgs' not 'msg'.
        # msg_subject and msg_date are simple strings.
        task_info = dict(question=question,
                         n_answers=options.n_answers,
                         msgs_text=msg['msgs_text'],
                         msgs_html=msg['msgs_html'],
                         msg_subject=msg['msg_subject'],
                         msg_date=msg['msg_date'])

        print task_info['msg_subject']
        print len(pbclient.get_tasks(app.id))

        # from erpy.ipshell import ipshell
        # ipshell('here')
        # sys.exit()
        # return

        pbclient.create_task(app.id, task_info)

    def add_msg_tasks(app):
        # First of all we get the emails.
        # Then, we have to create a set of tasks for the application
        # For this, we get first the email messages from local offlineimap dir.
        msgs = get_emails()
        question = app_config['question']
        [create_msg_task(app, m, question) for m in msgs]

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            pbclient.create_app(app_config['name'],
                                app_config['short_name'],
                                app_config['description'])

            app = setup_app()
        else:
            app = find_app_by_short_name()
        add_msg_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app):
            offset = 0
            limit = 100
            while True:
                tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                if len(tasks) == 0:
                    break
                for task in tasks:
                    yield task
                offset += len(tasks)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            pbclient.update_task(task)
            count[0] += 1

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #18
0
    (options, args) = parser.parse_args()
    
    # Load app details
    try:
        app_json = open('app.json')
        app_config = json.load(app_json)
        app_json.close()
    except IOError as e:
        print "app.json is missing! Please create a new one"
        exit(0)
        
    # If an endpoint is not provided, localhost on the port 5000 is assigned
    if not options.api_url:
        options.api_url = 'http://localhost:5000/'
       
    pbclient.set('endpoint', options.api_url+"/pybossa")

    if not options.api_key:
        parser.error("You must supply an API-KEY to create an \
                      applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)

    if (options.verbose):
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if not options.n_answers:
        options.n_answers = 15

    if not options.input_path:
예제 #19
0
 def __init__(self, endpoint, api_key, project_id):
     pbclient.set('endpoint', endpoint)
     pbclient.set('api_key', api_key)
     self.project_id = project_id
예제 #20
0
import pbclient
import settings
import piexif
from PIL import Image
from flask import Flask, request, jsonify, render_template, json
from flask import send_from_directory, redirect, url_for
from werkzeug import secure_filename
from piexif._exceptions import InvalidImageDataError
from s3 import upload_to_s3
from video import handle_video
from tasks import check_exists, create_task
from redis import Redis
from rq import Queue
from socketIO_client import SocketIO

pbclient.set('api_key', settings.APIKEY)
pbclient.set('endpoint', settings.SERVER_NAME)


def async_upload(**kwargs):
    sio = SocketIO(settings.SOCKETIO_SERVER, settings.SOCKETIO_PORT)
    project_id = kwargs['project_id']
    project_name = kwargs['project_name']
    camera_id = kwargs['camera_id']
    deploymentLocationID = kwargs['deploymentLocationID']
    filename = kwargs['filename']
    path = kwargs['path']
    room = kwargs['room']
    duplicates = kwargs['duplicates']

    with open(path) as file:
예제 #21
0
def run(app_config, options):
    def find_app_by_short_name():
        return pbclient.find_app(short_name=app_config['short_name'])[0]

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        pbclient.update_app(app)
        return app

    def create_video_task(app, oembed, question):
        # Data for the tasks
        task_info = dict(question=question,
                         n_answers=options.n_answers,
                         oembed=oembed)
        pbclient.create_task(app.id, task_info)

    def add_video_tasks(app):
        # First of all we get the URL video
        # Then, we have to create a set of tasks for the application
        # For this, we get first the video URLs from Vimeo
        oembeds = get_videos(tags=options.tags)
        question = app_config['question']
        [create_video_task(app, o, question) for o in oembeds]

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            pbclient.create_app(app_config['name'],
                                app_config['short_name'],
                                app_config['description'])

            app = setup_app()
        else:
            app = find_app_by_short_name()
        add_video_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app):
            offset = 0
            limit = 100
            while True:
                tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                if len(tasks) == 0:
                    break
                for task in tasks:
                    yield task
                offset += len(tasks)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            pbclient.update_task(task)
            count[0] += 1

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #22
0
    # Verbose?
    parser.add_argument("-v", "--verbose", action="store_true")

    args = parser.parse_args()


    app_config = None
    # Load app details
    try:
        with file('app.json') as app_json:
            app_config = json.load(app_json)
    except IOError:
        print "application config file is missing! Please create a new one"
        exit(1)

    pbclient.set('endpoint', args.server)
    pbclient.set('api_key', args.api_key)

    if args.verbose:
        print('Running against PyBosssa instance at: %s' % args.server)
        print('Using API-KEY: %s' % args.api_key)

    if args.dry:
        create_tasks(app_config, False)
        exit(0)

    if args.create_app:
        try:
            response = pbclient.create_app(app_config['name'],
                                           app_config['short_name'],
                                           app_config['description'])
예제 #23
0
def setup():
    pbclient.set('endpoint', flask_app.config.get('ETL_PYBOSSA_HOST'))
    pbclient.set('api_key', flask_app.config.get('ETL_PYBOSSA_KEY'))
    apps = pbclient.find_app(short_name='lobbyfacts-nee')
    return apps.pop()
예제 #24
0
def run(app_config, options):
    def check_api_error(api_response):
        """Check if returned API response contains an error"""
        if type(api_response) == dict and (api_response.get('status') == 'failed'):
            raise exceptions.HTTPError

    def format_error(module, error):
        """Format the error for the given module"""
        logging.error(module)
        # Beautify JSON error
        if type(error) == list:
            print "Application not found"
        else:
            print json.dumps(error, sort_keys=True, indent=4, separators=(',', ': '))
        exit(1)

    def find_app_by_short_name():
        try:
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            return response[0]
        except:
            format_error("pbclient.find_app", response)

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
            return app
        except:
            format_error("pbclient.update_app", response)

    def create_graph_task(app, graph, question, priority=0):
        # Data for the tasks
        task_info = graph
        try:
            response = pbclient.create_task(app.id, task_info, priority_0=priority,
                                            n_answers=options.n_answers)
            #if int(response.headers['X-Rate-Limit']) < 10:
            #    print "We are close to hit the maximum rate limit"
            #    print "Sleeping 5 minutes before adding more tasks"
            #    sleep(300)
            check_api_error(response)
        except:
            format_error("pbclient.create_task", response)

    def add_graph_levels(app):
        # First of all we get the URL photos
        # Then, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        data = graphs.get()
        question = app_config['question']
        [create_graph_task(app, g, question, priority=random.random()) for g in data]

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            try:
                response = pbclient.create_app(app_config['name'],
                                               app_config['short_name'],
                                               app_config['description'])

                check_api_error(response)
                app = setup_app()
            except:
                format_error("pbclient.create_app", response)
        else:
            app = find_app_by_short_name()
        add_graph_levels(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app):
            offset = 0
            limit = 100
            while True:
                try:
                    tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                    check_api_error(tasks)
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)
                except:
                    format_error("pbclient.get_tasks", response)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            try:
                response = pbclient.update_task(task)
                check_api_error(response)
                count[0] += 1
            except:
                format_error("pbclient.update_task", response)

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #25
0
파일: setup.py 프로젝트: JalfLSD/Sun4All
import pbclient

def contents(filename):
    return file(filename).read()

# settings
pbclient.set('api_key', "c008cbd5-7885-4c49-a0fe-6cdee926651f")
pbclient.set('endpoint', 'http://localhost/pybossa')

# Create the app
#response = pbclient.create_app('Sun for All', 'Sun4All','The aim of the project is the collection of over 30,000 images of the Sun (spectroheliograms) existing at the Astronomical Observatory of the University of Coimbra, the result of work of more than 80 years of daily observations of the Sun started in 1926.');

#update app
pyBossaApp = pbclient.find_app(short_name='Sun4All')[0];
#pyBossaApp.long_description = '- add long description -';
pyBossaApp.info['task_presenter'] = contents('../Site/static/templates/template.html')
pyBossaApp.info['tutorial'] = contents('../Site/static/templates/tutorial.html')
pyBossaApp.info['thumbnail'] = "https://pybossa.socientize.eu/sun4all/images/icon2.jpg"
pyBossaApp.category_id = 2

pbclient.update_app(pyBossaApp)
def __setup_pbclient(app):
    pbclient.set('endpoint', app.config['PYBOSSA_URL'])
    pbclient.set('api_key', app.config['API_KEY'])
def run(app_config, options):
    def check_api_error(api_response):
        """Check if returned API response contains an error"""
        if type(api_response) == dict and (api_response.get('status')
                                           == 'failed'):
            raise exceptions.HTTPError

    def format_error(module, error):
        """Format the error for the given module"""
        logging.error(module)
        # Beautify JSON error
        if type(error) == list:
            print "Application not found"
        else:
            print json.dumps(error,
                             sort_keys=True,
                             indent=4,
                             separators=(',', ': '))
        exit(1)

    def find_app_by_short_name():
        try:
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            return response[0]
        except:
            format_error("pbclient.find_app", response)

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
            return app
        except:
            format_error("pbclient.update_app", response)

    def create_photo_task(app, photo, question, priority=0):
        # Data for the tasks
        task_info = photo
        try:
            response = pbclient.create_task(app.id,
                                            task_info,
                                            priority_0=priority)
            check_api_error(response)
        except:
            format_error("pbclient.create_task", response)

    def add_photo_tasks(app):
        # First of all we get the URL photos
        # Then, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from S3
        photos = get_s3_photos(options.s3_bucket_folder)
        question = app_config['question']
        #[create_photo_task(app, p, question, priority=random.random()) for p in photos]
        for p in photos:
            create_photo_task(app, p, question)
            print "Creating task..."
            sleep(4)

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.s3_bucket_folder:
            if options.create_app:
                try:
                    response = pbclient.create_app(app_config['name'],
                                                   app_config['short_name'],
                                                   app_config['description'])

                    check_api_error(response)
                    app = setup_app()
                except:
                    format_error("pbclient.create_app", response)
            else:
                app = find_app_by_short_name()
            add_photo_tasks(app)
        else:
            parser.error("Please check --help or -h for the available options")

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:

        def tasks(app):
            offset = 0
            limit = 100
            while True:
                try:
                    tasks = pbclient.get_tasks(app.id,
                                               offset=offset,
                                               limit=limit)
                    check_api_error(tasks)
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)
                except:
                    format_error("pbclient.get_tasks", response)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del (task.info['n_answers'])
            task.n_answers = options.update_tasks
            try:
                response = pbclient.update_task(task)
                check_api_error(response)
                count[0] += 1
            except:
                format_error("pbclient.update_task", response)

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #28
0
def run(app_config, options):
    def check_api_error(api_response):
        """Check if returned API response contains an error"""
        if type(api_response) == dict and (api_response.get('status') == 'failed'):
            raise exceptions.HTTPError

    def format_error(module, error):
        """Format the error for the given module"""
        logging.error(module)
        # Beautify JSON error
        if type(error) == list:
            print "Application not found"
        else:
            print json.dumps(error, sort_keys=True, indent=4, separators=(',', ': '))
        exit(1)

    def find_app_by_short_name():
        try:
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            return response[0]
        except:
            format_error("pbclient.find_app", response)

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail'] #Cuidado que tira el icono de la aplicacion
        app.info['tutorial'] = contents('tutorial.html')

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
            return app
        except:
            format_error("pbclient.update_app", response)

    def create_photo_task(app, photo, question, priority=0):
        # Data for the tasks
        task_info = dict(
                         n_answers=options.n_answers,
                         idiss=photo['idISS'],
                         link_big=photo['link_big'],
                         link_small=photo['link_small'],
                         linkData=photo['linkData'],
                         citylon=photo['citylon'],
                         citylat=photo['citylat'],
                         focal=photo['focal'])
        try:
            response = pbclient.create_task(app.id, task_info, priority_0=priority)
            check_api_error(response)
        except:
            #response = pbclient.create_task(app.id, task_info, priority_0=priority)
            format_error("pbclient.create_task", response)

    def add_photo_tasks(app):
        photos = get_iss_photos(                                )
        question = app_config['question']
        [create_photo_task(app, p, question, priority=random.random()) for p in photos]


    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            try:
                response = pbclient.create_app(app_config['name'],
                                               app_config['short_name'],
                                               app_config['description'])

                check_api_error(response)
                app = setup_app()
            except:
                format_error("pbclient.create_app", response)
        else:
            app = find_app_by_short_name()
        add_photo_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app):
            offset = 0
            limit = 100
            while True:
                try:
                    tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                    check_api_error(tasks)
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)
                except:
                    format_error("pbclient.get_tasks", response)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            try:
                response = pbclient.update_task(task)
                check_api_error(response)
                count[0] += 1
            except:
                format_error("pbclient.update_task", response)

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
import os
import random
import urllib2
import urllib
import pbclient
import requests

VIDEOS_DIR = "/local/adabriand/pybossa_apps/app-libras/libras-static/libras-videos/"
APP_DIR = os.path.dirname(os.path.abspath(__file__))
SCRIPTS_BLENDER_DIR = os.path.join(APP_DIR, "scripts-blender")
BLEND_FILE = os.path.join(SCRIPTS_BLENDER_DIR, "mulher05_iK_14_05.blend")
MOV_PONTUAL_SCRIPT = os.path.join(SCRIPTS_BLENDER_DIR, "movPontual.py")
PYBOSSA_ENDPOINT = "http://localhost/pybossa"
PYBOSSA_API_KEY = "53b8465d-91b0-4286-b2d8-834fbd89e194" 

pbclient.set('endpoint', PYBOSSA_ENDPOINT)
app = Flask(__name__)

@app.route( "/api/getCurrIpAddr" )
def getCurrIpAddr():
    return jsonify( curr_usr_ip = getUserIp() )

@app.route("/api/validateTask", methods = ['POST'] )
def validateTask():
    task_info = json.loads( request.data )

    app_id = pbclient.find_app( short_name = "librasdictionary" )[0].id

    # sets the task as completed
    requests.put( "%s/api/task/%s?api_key=%s" % 
                 (PYBOSSA_ENDPOINT, task_info["task_id"], PYBOSSA_API_KEY), 
예제 #30
0
def run(app_config, options):
    def check_api_error(api_response):
        """Check if returned API response contains an error"""
        if type(api_response) == dict and (api_response.get('status')
                                           == 'failed'):
            raise exceptions.HTTPError

    def format_error(module, error):
        """Format the error for the given module"""
        logging.error(module)
        # Beautify JSON error
        if type(error) == list:
            print "Application not found"
        else:
            print json.dumps(error,
                             sort_keys=True,
                             indent=4,
                             separators=(',', ': '))
        exit(1)

    def find_app_by_short_name():
        try:
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            return response[0]
        except:
            format_error("pbclient.find_app", response)

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.category_id = 5
        app.hidden = 1
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
            return app
        except:
            format_error("pbclient.update_app", response)

    def create_photo_task(app, photo, question, priority=0):
        # Data for the tasks
        task_info = photo
        try:
            response = pbclient.create_task(app.id,
                                            task_info,
                                            priority_0=priority)
            check_api_error(response)
        except:
            format_error("pbclient.create_task", response)

    def add_photo_tasks(app):
        # First of all we get the URL photos
        # Then, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        photos = get_flickr_set_photos(options.photoset_id)
        question = app_config['question']
        #[create_photo_task(app, p, question, priority=random.random()) for p in photos]
        # Estimate how many minutes it has to wait before reaching the limit
        # Limit is 300 tasks per 15 minutes
        wait = (15 * 60) / 300
        if len(photos) > 300:
            wait = wait + 1  # Adding one second will take 20 minutes to add 300 tasks
        print "Wait %s seconds between each create_task request" % wait
        for p in photos:
            create_photo_task(app, p, question, priority=0)
            time.sleep(wait)

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            try:
                response = pbclient.create_app(app_config['name'],
                                               app_config['short_name'],
                                               app_config['description'])

                check_api_error(response)
                app = setup_app()
            except:
                format_error("pbclient.create_app", response)
        else:
            app = find_app_by_short_name()
        add_photo_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:

        def tasks(app):
            offset = 0
            limit = 100
            while True:
                try:
                    tasks = pbclient.get_tasks(app.id,
                                               offset=offset,
                                               limit=limit)
                    check_api_error(tasks)
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)
                except:
                    format_error("pbclient.get_tasks", response)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del (task.info['n_answers'])
            task.n_answers = options.update_tasks
            try:
                response = pbclient.update_task(task)
                check_api_error(response)
                count[0] += 1
            except:
                format_error("pbclient.update_task", response)

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #31
0
import config
import pbclient


pbclient.set('endpoint', config.ENDPOINT)
pbclient.set('api_key', config.API_KEY)


def push_presenter():
    html = open('presenter.html').read()

    # prepend categories to presenter
    cat_html = """
    <script type="text/javascript">
    window.LobbyFactsCategories = %s;
    </script>

    """ % open('categories.json').read()

    html = cat_html + html

    app = pbclient.find_app(short_name=config.APP)[0]

    app.info['task_presenter'] = html
    app.long_description = open('long-description.html').read().replace('%APP%', config.APP)
    app.info['sched'] = 'default'
    app.info['thumbnail'] = 'http://i46.tinypic.com/14js2tx.png'

    pbclient.update_app(app)

예제 #32
0
#!/usr/bin/env python

import web
import json
import pbclient
import requests
import settings

web.config.debug = settings.DEBUG

pbclient.set('endpoint', settings.ENDPOINT)

urls = (
  '/', 'app_overview',
  '/api/(.+)', 'api',
  '/([^\/]+)/?', 'app_index',
  '/([^\/]+)/newtask', 'app_newtask',
  '/([^\/]+)/progress', 'app_progress',
  '/([^\/]+)/progress/data', 'app_progress_data',
  '/([^\/]+)/task/(\d+)', 'app_task'
)

app = web.application(urls, globals())
render = web.template.render('templates/')

_pybossa_application_cache = {}


def _get_app(app_name):
    global _pybossa_application_cache
    if app_name in _pybossa_application_cache:
예제 #33
0
def run(app_config, options):
    def check_api_error(api_response):
        """Check if returned API response contains an error"""
        if type(api_response) == dict and (api_response.get('status') == 'failed'):
            raise exceptions.HTTPError

    def format_error(module, error):
        """Format the error for the given module"""
        logging.error(module)
        # Beautify JSON error
        if type(error) == list:
            print "Application not found"
        else:
            print json.dumps(error, sort_keys=True, indent=4, separators=(',', ': '))
        exit(1)

    def find_app_by_short_name():
        try:
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            return response[0]
        except:
            format_error("pbclient.find_app", response)

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
            return app
        except:
            format_error("pbclient.update_app", response)
    #TODO: Change this to save two URL photos, the question answered
    def create_photo_task(app, photo, question, priority=0):
        # Data for the tasks
        #task_info = dict(question=question,
        #                 n_answers=options.n_answers,
        #                 link=photo['link'],
        #                 url_m=photo['url_m'],
        #                 url_b=photo['url_b'])
        task_info = dict(question=question,
                         n_answers=options.n_answers,
                         url_c=photo['url_c'],
                         url_a=photo['url_a'])
        try:
            response = pbclient.create_task(app.id, task_info, priority_0=priority)
            check_api_error(response)
        except:
            format_error("pbclient.create_task", response)

    def add_photo_tasks(app):
        # First of all we get the URL photos
        # Then, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        photos = get_photos()
        question = app_config['question']
        [create_photo_task(app, p, question, priority=random.random()) for p in photos]#TODO: change this to support local photos!

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            try:
		print(app_config['name'])
		print(app_config['short_name'])
		print(app_config['description'])
		print(options)
                response = pbclient.create_app(app_config['name'],
                                               app_config['short_name'],
                                               app_config['description'])

		check_api_error(response)
                app = setup_app()
            except:
                format_error("pbclient.create_app", response)
        else:
            app = find_app_by_short_name()
        add_photo_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app):
            offset = 0
            limit = 100
            while True:
                try:
                    tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                    check_api_error(tasks)
                    if len(tasks) == 0:
                        break
                    for task in tasks:
                        yield task
                    offset += len(tasks)
                except:
                    format_error("pbclient.get_tasks", response)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            try:
                response = pbclient.update_task(task)
                check_api_error(response)
                count[0] += 1
            except:
                format_error("pbclient.update_task", response)

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #34
0
 def test_set(self):
     """Test setter works."""
     from pbclient import _opts
     pbclient.set('foo', 'bar')
     assert 'foo' in _opts.keys()
     assert _opts['foo'] == 'bar'
예제 #35
0
def run(app_config, options):
    def find_app_by_short_name():
        return pbclient.find_app(short_name=app_config['short_name'])[0]

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        pbclient.update_app(app)
        return app

    def create_photo_task(app, photo, question):
        # Data for the tasks
        task_info = dict(question=question,
                         n_answers=options.n_answers,
                         link=photo)
        pbclient.create_task(app.id, task_info)

    def add_photo_tasks(app):
        # First of all we get the URL photos
        # Then, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        photos = ['http://i.imgur.com/4RvBQIF.png', 'http://i.imgur.com/rRPPKKq.png',
                  'http://i.imgur.com/GYsQWYQ.png', 'http://i.imgur.com/gcfzAAz.png',
                  'http://i.imgur.com/gcfzAAz.png', 'http://i.imgur.com/14tJo6K.png',
                  'http://i.imgur.com/oozn3FT.png', 'http://i.imgur.com/dWWLc33.png',
                  'http://i.imgur.com/5RFsuhC.png', 'http://i.imgur.com/ZRQHoVM.png',
                  'http://i.imgur.com/3cUziEs.png']

        question = app_config['question']
        [create_photo_task(app, p, question) for p in photos]

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            pbclient.create_app(app_config['name'],
                                app_config['short_name'],
                                app_config['description'])

            app = setup_app()
        else:
            app = find_app_by_short_name()
        add_photo_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app):
            offset = 0
            limit = 100
            while True:
                tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                if len(tasks) == 0:
                    break
                for task in tasks:
                    yield task
                offset += len(tasks)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            pbclient.update_task(task)
            count[0] += 1

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #36
0
def run(app_config, options):
    def find_app_by_short_name():
        return pbclient.find_app(short_name=app_config['short_name'])[0]

    def setup_app():
        app = find_app_by_short_name()
        app.long_description = contents('long_description.html')
        app.info['task_presenter'] = contents('template.html')
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = contents('tutorial.html')

        pbclient.update_app(app)
        return app

    def create_video_task(app, oembed, question):
        # Data for the tasks
        task_info = dict(question=question,
                         n_answers=options.n_answers,
                         oembed=oembed)
        pbclient.create_task(app.id, task_info)

    def add_video_tasks(app):
        # First of all we get the URL photos
        # Then, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        oembeds = get_videos(tags=options.tags)
        question = app_config['question']
        [create_video_task(app, o, question) for o in oembeds]

    pbclient.set('api_key', options.api_key)
    pbclient.set('endpoint', options.api_url)

    if options.verbose:
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if options.create_app or options.add_more_tasks:
        if options.create_app:
            pbclient.create_app(app_config['name'],
                                app_config['short_name'],
                                app_config['description'])

            app = setup_app()
        else:
            app = find_app_by_short_name()
        add_video_tasks(app)

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        def tasks(app):
            offset = 0
            limit = 100
            while True:
                tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
                if len(tasks) == 0:
                    break
                for task in tasks:
                    yield task
                offset += len(tasks)

        def update_task(task, count):
            print "Updating task: %s" % task.id
            if 'n_answers' in task.info:
                del(task.info['n_answers'])
            task.n_answers = options.update_tasks
            pbclient.update_task(task)
            count[0] += 1

        print "Updating task n_answers"
        app = find_app_by_short_name()

        n_tasks = [0]
        [update_task(t, n_tasks) for t in tasks(app)]
        print "%s Tasks have been updated!" % n_tasks[0]
예제 #37
0
import os
import random
import urllib2
import urllib
import pbclient
import requests

app = Flask(__name__)

VIDEOS_DIR = "/home/thyagofas/web_dev/pybossa/app-libras/static_libras/libras-videos/"
APP_DIR = os.path.dirname(os.path.abspath(__file__))
SCRIPTS_BLENDER_DIR = os.path.join(APP_DIR, "scripts-blender")
BLEND_FILE = os.path.join(SCRIPTS_BLENDER_DIR, "mulher05_iK_14_05.blend")
MOV_PONTUAL_SCRIPT = os.path.join(SCRIPTS_BLENDER_DIR, "movPontual.py")

pbclient.set('endpoint', "http://*****:*****@app.route( "/getCurrIpAddr" )
def getCurrIpAddr():
    return jsonify( curr_usr_ip = getUserIp() )

@app.route( "/validateTask", methods = ['POST'] )
def validateTask():
    task_info = json.loads( request.data )

    app_id = pbclient.find_app( short_name = "librasdictionary" )[0].id

    # sets the task as completed
    requests.put( "%s/api/task/%s?api_key=%s" % 
                 ( "http://localhost:8080/pybossa", task_info["task_id"], "53b8465d-91b0-4286-b2d8-834fbd89e194" ), 
                      dest="verbose")

    (options, args) = parser.parse_args()

    # Load app details
    try:
        app_json = open('app.json')
        app_config = json.load(app_json)
        app_json.close()
    except IOError as e:
        print "app.json is missing! Please create a new one"
        exit(0)

    if not options.api_url:
        options.api_url = 'http://localhost:5000'
    pbclient.set('endpoint', options.api_url)

    if not options.api_key:
        parser.error("You must supply an API-KEY to create " +\
                     "an application and tasks in PyBossa")
    pbclient.set('api_key', options.api_key)

    if not options.template:
        print("Using default template: template.html")
        options.template = "template.html"

    if not options.cities:
        parser.error("You must supply a file name with the cities")
    if not options.n_answers:
        options.n_answers = 5