Example #1
0
def put_data_resume_in_base(data_from_resumes_list, db_session):
    all_keywords = []
    all_urls = []

    for item in Keywords.query.all():
        all_keywords.append(item.keyword)

    for item in Resume.query.all():
        all_urls.append(item.url)

    for item in data_from_resumes_list:
        if item['url'] not in all_urls:
            all_urls.append(item['url'])
            resume = Resume(item['title'], item['gender'], item['age'],
                            item['has_degree'], item['city'],
                            str(item['keywords']), item['salary'], item['url'])
            db_session.add(resume)

        for keyword in item['keywords']:
            if keyword not in all_keywords:
                all_keywords.append(item['keywords'])
                k = Keywords(keyword.lower())
                db_session.add(k)
                all_keywords.append(keyword.lower())
    db_session.commit()
Example #2
0
def add_news(req):
    check = News.objects.filter(link=req.POST['link'])
    mnews = ""
    if check.count() != 0:
        # record already exist
        if check[0].time > int(req.POST['time']):
            return HttpResponse(json.dumps({'status': 'OK'}, indent=4),
                                content_type='application/json')
        mnews = check[0]
    else:
        mnews = News()
    mnews.title = req.POST['title']
    mnews.content = req.POST['content']
    mnews.link = req.POST['link']
    mnews.time = int(req.POST['time'])
    mnews.save()
    keywords = json.loads(req.POST['keywords'])
    refers = json.loads(req.POST['refers'])
    for word in keywords:
        mkeywords = Keywords()
        mkeywords.news = mnews
        mkeywords.words = word
        mkeywords.save()
    for refer in refers:
        mrefer = Refers()
        mrefer.news = mnews
        mrefer.refer = refer
        mrefer.save()
    return HttpResponse(json.dumps({'status': 'OK'}),
                        content_type='application/json')
Example #3
0
def write_to_db(suggestion):
    try:
        sug = Keywords(suggestion)
        db.session.add(sug)
        db.session.commit()
    except:
        db.session.rollback()
Example #4
0
def suggestion():
    search_for = Keywords(request.form['keyword'])
    suggestions = check(search_for.keyword)
    return render_template('suggestions.html',
                           keyword=search_for.keyword,
                           suggestions=suggestions,
                           pagination=False)
Example #5
0
def save_in_db(keyword, position=None):
    """Save keyword in db."""
    try:
        keyword = Keywords(keyword, position)
        db.session.add(keyword)
        db.session.commit()
        print(f"Keyword {keyword} had seen stored.")
    except Exception as e:
        print(f"Keyword {keyword} had not seen stored. Reason {e}.")
Example #6
0
def save_product_indexing(result, product):
    indexed = 0.0
    indexing_data = {}
    keyword_length = 0
    entities = []
    for value in result:
        keyword = value.keys()[0]
        indexing = value.values()[0]
        keyword_entity = Keywords(keyword=keyword, indexing=indexing)
        #save in memory
        entities.append(keyword_entity)
        if (indexing == True):
            indexed += 1
        keyword_length += 1
    indexing_rate = float(indexed) / float(keyword_length) * 100
    historic_entity = ProductHistoricIndexing(indexing_rate=indexing_rate,
                                              product=product)
    #save transactional operation
    historic_entity.save()
    #finish save of keywords
    for entity in entities:
        entity.historic = historic_entity
        entity.save()
    return historic_entity.id