def create_project(project_id, xml_project=None, project_category=None): if xml_project is None: xml = XML(config.XML_URL) project = xml.get_project(project_id) category = xml.get_category(project.categoryid.text) else: category = project_category project = xml_project if Categories.get_category(int(project.categoryid.text)) is None: if category is None: xml = XML(config.XML_URL) category = xml.get_category(project.categoryid.text) Categories.create_category(category_id=int( project.categoryid.text), category_name=category.text) html = HTML(project.url.text) project_data = { 'offer_id': project['id'], 'category': int(project.categoryid.text), 'url': project.url.text, 'price': float(project.price.text), 'currency': project.currencyid.text, 'picture': ImageInfo.create_img(project.picture.text), 'available': project['available'], 'short_desc': project.typeprefix.text, 'full_desc': html.get_full_description(), 'goal_price': html.get_goal_price(), 'current_price': html.get_current_price(), 'city': html.get_city(), 'model': project.model.text, } Projects.create_project(project_data)
def get_category_by_name(category_name): try: category = Categories.get(name=category_name.title()) return category.category_id except Exception: categories = Categories.select() for category in categories: add_names = category.additional_names.split[','] for add_name in add_names: if add_name == category_name.lower(): return category.category_id return -1
def get_category_by_name(category_name): try: print(f'category_name= {category_name}') category = Categories.get(name=category_name.title()) return category.category_id except Exception: categories = Categories.select() for category in categories: if category.additional_names != '': add_names = category.additional_names.split(',')[:-1] for add_name in add_names: if add_name.lower() == category_name.lower(): return category.category_id return -1
def update_category(category_id, **kwargs): category = Categories.get_category(category_id) category_data = category.__dict__.get('__data__') for key, item in kwargs.items(): category_data.update({f'{key}': item}) category.save() DataSet['PROJECTS'] = Database.get_all_category_names()
def get_all_category_names(): names = [] categories = Categories.select() for category in categories: additional = [] if category.additional_names != '': additional = category.additional_names.split(',')[:-1] additional.append(category.name) names += additional return names
def get_all_categories(): return Categories.select()
def create_category(category_id): xml = XML(xml_url=config.XML_URL) category = xml.get_category(category_id) Categories.create_category(category_id=category_id, category_name=category.text) DataSet['PROJECTS'] = Database.get_all_category_names()
def update_category(category_id, **kwargs): category = Categories.get_category(category_id) category_data = category.__dict__.get('__data__') for key, item in kwargs.items(): category_data.update({f'{key}': f'{item}'}) category.save()
def create_category(category_id): xml = XML(xml_url=config.XML_URL) category = xml.get_category(category_id) Categories.create_category(category_id=category_id, category_name=category.text) pass