Esempio n. 1
0
def run_decode():
    logging.debug('decode your input by our pretrained model')
    try:
        source = request.get_json()['source'] # GET request with String from frontend directly
        logging.debug('input: {}'.format(source)) # GET String-type context from the backend
        try:
            logging.debug('using the pretrained model.')
            sentNums, summary = summarizationModel.decode.run_(source)
        except Exception as e:
            logging.error(e)
        else:
            logging.debug('The number of sentences is {}'.format(sentNums))
            logging.debug('The abstract is that {}'.format(summary))
            results = {'sent_no': sentNums, 'final': summary}
            
        try:
            article = Content(text=source)
            abstract = Summary(text=summary)
            pair = Article(article=article.id, abstract=abstract.id)
            article.save()
            abstract.save()
            pair.save()
        except Exception as e:
            logging.error(e)

        return json.dumps(results)
    except:
        message = {'message' : 'Fail to catch the data from client.'}
        return json.dumps(message)
Esempio n. 2
0
def pub(ctx,request:YuHeLg.Request):
    payload = request.json
    post = Post()
    try:
        post.title = payload.get("title")
        post.author_id = request.user.id
        post.postdate = datetime.datetime.now()
        cont = Content()
        cont.content = payload.get("content")
        post.content = cont
        tags = payload["tags"]
    except Exception as e:
        print(e)
        raise exc.HTTPBadRequest()

    taglist = re.split('[\s,]',tags)
    for tag in taglist:
        t = session.query(Tag).filter(Tag.tag == tag).first()
        if t is None:
            t = Tag()
            t.tag = tag
            session.add(t)
        pt = Post_tag()
        pt.tag = t
        pt.post = post
        session.add(pt)

    session.add(post)
    try:
        session.commit()
        return jsonify(post_id=post.id)
    except:
        session.rollback()
        raise exc.HTTPInternalServerError()
Esempio n. 3
0
def add_content(title, op, text):
    content = Content(title=title,
                      op=op,
                      time_of_upload=datetime.utcnow(),
                      text=text)
    session.add(content)
    session.commit()
Esempio n. 4
0
    def parse_content_page(self, url):
        self.driver.get(url)

        cards = self.driver.find_elements_by_class_name("catalog-list-item__container") #articles-selector js-catalog-item")
        alkogol = []
        for card in cards:
            content = Content()

            try:
                content_category_elm = self.driver.find_element_by_tag_name("h1")
                content.category = content_category_elm.text
            except NoSuchElementException:
                print("product category missing")


            try:
                content_name_elm = card.find_element_by_class_name("catalog-list-item__title")
                content.name = content_name_elm.text
            except NoSuchElementException:
                print("product name missing")


            try:
                content_link_elm = card.find_element_by_class_name("catalog-list-item__title").get_attribute("href")
                content.link = content_link_elm
            except NoSuchElementException:
                print("product link missing")


            try:
                content_price_elm = card.find_element_by_class_name("middle_price")
                content.price = content_price_elm.text
            except NoSuchElementException:
                pass

            try:
                content_sale_elm = card.find_element_by_class_name("baseoldprice")
                content.sale = content_sale_elm.text
            except NoSuchElementException:
                content.sale = "Нет скидки"

            item = str(content)
            row = item.split(",")
            alkogol.append({
                'type' : row[0],
                'title' : row[-5],
                'link': row[-4],
                'price': row[-3],
                'sale' : row[-2],
                'availability': row[-1] 
                })
        return alkogol 
Esempio n. 5
0
    def parse_content_page(self, url):
        self.driver.get(url)
        cards = self.driver.find_elements_by_class_name("catalog_product_item_cont")
        alkogol = []
        for card in cards:
            content = Content()

            try:
                content_category_elm = self.driver.find_element_by_class_name("cont_right_col").find_element_by_tag_name("h1")
                content.category = content_category_elm.text
            except NoSuchElementException:
                print("product category missing")

            try:
                content_name_elm = card.find_element_by_class_name("product_item_name").find_element_by_tag_name("a")
                content.name = content_name_elm.text
            except NoSuchElementException:
                print("product name missing")

            try:
                content_link_elm = card.find_element_by_class_name("product_item_name").find_element_by_tag_name("a").get_attribute('href')
                content.link = content_link_elm
            except NoSuchElementException:
                print("product link missing")
            
            try:
                content_price_elm = card.find_element_by_class_name("i_price").find_element_by_tag_name("div")
                content.price = content_price_elm.text
            except NoSuchElementException:
                content.availability = "not avilable"

            item = str(content)
            row = item.split(",")
            
            print(row)
            alkogol.append({
                'type' : row[0],
                'title' : row[-5],
                'link': row[-4],
                'price': row[-3],
                'sale' : " ",
                'availability': row[-1] 
                })
        return alkogol 
Esempio n. 6
0
    def parse_content_page(self, url):
        self.driver.get(url)
        time.sleep(5)

        cards = self.driver.find_elements_by_class_name("cl_info")
        print(cards)
        alkogol = []
        for card in cards:
            content = Content()

            try:
                content_category_elm = self.driver.find_element_by_tag_name(
                    "h1")
                content.category = content_category_elm.text
                print(content.category)
            except NoSuchElementException:
                print("product category missing")

            try:
                content_name_elm = card.find_element_by_class_name(
                    "goods_name").find_element_by_tag_name("a")
                content.name = content_name_elm.text
                print(content.name)
            except NoSuchElementException:
                print("product name missing")

            try:
                content_link_elm = card.find_element_by_class_name(
                    "goods_name").find_element_by_tag_name("a").get_attribute(
                        "href")
                content.link = content_link_elm
                print(content.link)
            except NoSuchElementException:
                print("product link missing")

            try:
                content_price_elm = card.find_element_by_class_name(
                    "cl_price").find_element_by_tag_name("span")
                content.price = content_price_elm.text
                print(content.price)
            except NoSuchElementException:
                pass

            try:
                content_sale_elm = card.find_element_by_class_name(
                    "cl_price_action").find_element_by_tag_name("span")
                content.sale = content_sale_elm.text
                print(content.sale)
            except NoSuchElementException:
                content.sale = "Нет скидки"

            item = str(content)
            row = item.split(",")
            print(row)
            alkogol.append({
                'type': row[0],
                'title': row[-5],
                'link': row[-4],
                'price': row[-3],
                'sale': row[-2],
                'availability': row[-1]
            })
        return alkogol