def getQuestions(self, pageObj, game): rounds = pageObj.findAll("table", {"class": "round"}) categories = [] if len(rounds) != 2: return for i in range(1, 3): print("ROUND " + str(i)) round = rounds[i - 1] categoryElems = round.findAll("td", {"class": "category_name"}) for category in categoryElems: categoryObj = Category(None, game, i, category.get_text()) categoryObj = categoryObj.save(self.db) categories.append(categoryObj) clues = round.findAll("td", {"class": "clue"}) for clue in clues: if clue.find("td", {"class": "clue_text"}) is not None: self.extractClue(clue, game, categories, i) final = pageObj.find("table", {"class": "final_round"}) if final is None: return finalCategoryName = final.find("td", { "class": "category_name" }).get_text() finalCategory = Category(None, game, 3, finalCategoryName) finalCategory = finalCategory.save(self.db) self.extractClue(final, game, finalCategory, 3)
def categories(): if request.method == 'GET': # return an html list of all the categories return render_template('category/index.html', categories=Category.all(), success=True) elif request.method == 'POST': # create new category based on the posted id params = request.get_json() new_category_id = int(params['id']) fields = {key: "" for key, value in form_fields.iteritems()} new_category = Category(new_category_id, fields) new_category.save() return 'OK', 200 else: return 'error', 400
def categories(): if request.method == "GET": # return an html list of all the categories return render_template("category/index.html", categories=Category.all(), success=True) elif request.method == "POST": # create new category based on the posted id params = request.get_json() new_category_id = int(params["id"]) fields = {key: "" for key, value in form_fields.iteritems()} new_category = Category(new_category_id, fields) new_category.save() return "OK", 200 else: return "error", 400
def learn(self): # for each directory in the document root... for category_name in os.listdir(self.docroot): category_path = os.path.join(self.docroot, category_name) # if the category is a file (not a directory), then skip it if os.path.isfile(category_path): continue category = Category(self.database, category_name, self.stop_list) self.categories[category_name] = category # call the function to handle the directory/category category.categorize(category_path) category.save()
def learn(self): # for each directory in the document root... for category_name in os.listdir(self.docroot): category_path = os.path.join(self.docroot, category_name) # if the category is a file (not a directory), then skip it if os.path.isfile(category_path): continue category = Category(self.database, category_name, self.stop_list) self.categories[category_name] = category # call the function to handle the directory/category category.categorize(category_path) category.save()
def categories(): if request.method == 'GET': # return an html list of all the categories return render_template('category/index.html', categories=Category.all(), success=True) elif request.method == 'POST': # create new category based on the posted id params = request.get_json() new_category_id = int(params['id']) fields = {key: "" for key, value in form_fields.iteritems()} new_category = Category(new_category_id, fields) new_category.save() return 'OK', 200 else: return 'error', 400
def go_categories(xmldoc): categorieslist = xmldoc.getElementsByTagName('category') for s in categorieslist: category_id = s.attributes['id'].value name = s.childNodes[0].nodeValue try: parent_id = s.attributes['parentId'].value except: parent_id = None print name print Category.get_by_folder_id(parent_id) print category_id c = Category(name=name.replace('"', '"'), parent=Category.get_by_folder_id(parent_id), folder_id=category_id) print c c.save()