def create_tasks(engine): log.info("Updating tasks on pyBossa...") app = setup() with flask_app.open_resource('resources/pbnetworks_template.html') as f: app.info['task_presenter'] = f.read() pbclient.update_app(app) tasks = pbclient.get_tasks(app.id, limit=30000) existing = dict([(t.data.get('info').get('signature'), t) for t in tasks]) for rep in sl.all(engine, sl.get_table(engine, 'representative')): networking = rep.get('networking') if networking is None or len(networking.strip()) < 3: continue signature = rep.get('identification_code') + networking signature = sha1(signature.encode('ascii', 'ignore')).hexdigest() rep['signature'] = signature print [rep.get('name')] log.debug("Task: %s", rep['name']) rep['last_update_date'] = rep['last_update_date'].isoformat() rep['registration_date'] = rep['registration_date'].isoformat() #print [(k, type(v)) for k,v in rep.items()] if signature in existing: task = existing.get(signature) task.data['info'] = rep pbclient.update_task(task) else: pbclient.create_task(app.id, rep)
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
def setup_app(self): self.find_app_by_short_name() self.app.long_description = self.contents('long_description.html') self.app.info['task_presenter'] = self.contents('template.html') self.app.info['thumbnail'] = self.app_config['thumbnail'] self.app.info['tutorial'] = self.contents('tutorial.html') pbclient.update_app(self.app)
def push_presenter(): html = open('presenter.html').read() app = pbclient.find_app(short_name=config.APP)[0] app.info['task_presenter'] = html app.info['sched'] = 'default' pbclient.update_app(app)
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 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 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 ''
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"
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)
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 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 setup_app(self): self.find_app_by_short_name() self.app.long_description = self.contents('long_description.html') self.app.info['task_presenter'] = self.contents('template.html') self.app.info['thumbnail'] = self.app_config['thumbnail'] self.app.info['tutorial'] = self.contents('tutorial.html') self.handle_result(pbclient.update_app(self.app)) staticroot = os.path.realpath(os.path.join(self.options.app_root, 'static')) for path, dirs, files in os.walk(staticroot, topdown=False, followlinks=True): for filename in files: filepath = os.path.join(path, filename) with open(filepath) as file: # Remove the prefix and then remove any inherit-symlinks dst = file.name[len(staticroot):].replace("inherit/", "")[1:] print "Uploading %s" % (dst,) print " from %s" % os.path.realpath(file.name) result = pbclient.add_file(self.app, file, dst) if result['status'] != 'ok' : print result assert False
print('Using API-KEY: %s' % options.api_key) if not options.n_answers: options.n_answers = 30 if options.create_app: pbclient.create_app(app_config['name'], app_config['short_name'], app_config['description']) app = pbclient.find_app(short_name=app_config['short_name'])[0] app.long_description = open('long_description.html').read() app.info['task_presenter'] = open('template.html').read() app.info['thumbnail'] = app_config['thumbnail'] app.info['tutorial'] = open('tutorial.html').read() pbclient.update_app(app) # First of all we get the URL photos photos = get_flickr_photos() # Finally, we have to create a set of tasks for the application # For this, we get first the photo URLs from Flickr for i in xrange(1): for photo in photos: # Data for the tasks task_info = dict(question=app_config['question'], n_answers=int(options.n_answers), link=photo['link'], url_m=photo['url_m'], url_b=photo['url_b']) pbclient.create_task(app.id, task_info) else: if options.add_more_tasks:
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)
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] app.long_description = open('long_description.html').read() app.info['task_presenter'] = open('template.html').read() app.info['thumbnail'] = app_config['thumbnail'] app.info['tutorial'] = open('tutorial.html').read() except: format_error("pbclient.create_app or pbclient.find_app", response) try: response = pbclient.update_app(app) check_api_error(response) except: format_error("pbclient.update_app", response) coordinates = get_coordinates(options.coordinates) for c in coordinates: lon, lat = c.split(",") task_info = dict(question=app_config['question'], n_answers=int(options.n_answers), lon=float(lon), lat=float(lat)) try: response = pbclient.create_task(app.id, task_info) check_api_error(response) except:
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] app.long_description = open('long_description.html').read() app.info['task_presenter'] = open('template.html').read() app.info['thumbnail'] = app_config['thumbnail'] except: format_error("pbclient.create_app", response) try: response = pbclient.update_app(app) check_api_error(response) for page in range(1, 15): # Data for the tasks task_info = dict(question=app_config['question'], page=page, pdf_url=options.pdf_url) response = pbclient.create_task(app.id, task_info) check_api_error(response) except: format_error("pbclient.update_app or pbclient.create_task", response) else: if options.add_more_tasks: try: response = pbclient.find_app(short_name=app_config['short_name'])
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: pbclient.create_app(app_config['name'], app_config['short_name'], app_config['description']) app = pbclient.find_app(short_name=app_config['short_name'])[0] app.long_description = open('long_description.html').read() app.info['task_presenter'] = open('template.html').read() app.info['thumbnail'] = app_config['thumbnail'] app.info['tutorial'] = open('tutorial.html').read() pbclient.update_app(app) cities = get_cities(options.cities) for city in cities: task_info = dict(question=app_config['question'], n_answers=int(options.n_answers), city=city.rstrip()) pbclient.create_task(app.id, task_info) if options.update_template: print "Updating app template" app = pbclient.find_app(short_name=app_config['short_name'])[0] app.long_description = open('long_description.html').read() app.info['task_presenter'] = open('template.html').read() app.info['tutorial'] = open('tutorial.html').read() pbclient.update_app(app)