示例#1
0
文件: views.py 项目: randoms/prophet
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')
示例#2
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()
示例#3
0
def write_to_db(suggestion):
    try:
        sug = Keywords(suggestion)
        db.session.add(sug)
        db.session.commit()
    except:
        db.session.rollback()
示例#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)
示例#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}.")
示例#6
0
def index(request):
    if not request.POST:
        all_urls = Urls.objects.all()
        form = GifForm()
        return render(request, 'index.html', {"urls": all_urls, "form": form})
    else:
        form = GifForm(request.POST)
        if form.is_valid():
            formurl = form.cleaned_data['url']
            url = Urls(urls=formurl)
            url.save()
            formkeys = form.cleaned_data['keywords']
            keywords = formkeys.split(',')
            for keyz in keywords:
                key = Keywords(keywords=keyz)
                key.save()
                lookup = Lookup(keywords=key, urls=url)
            return HttpResponse(json.dumps({"success": True, "url": formurl}))
        else:
            return HttpResponse(json.dumps({"error": "Invalid form post"}))
示例#7
0
文件: views.py 项目: randoms/prophet
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')
示例#8
0
def update_labels(bug, labels):
    bug_labels = set([str(l.name) for l in bug.kws.all()])
    new_labels = set(labels)
    if bug_labels != new_labels:
        for l in labels:
            try:
                kw = Keyworddefs.objects.get(name=l)
            except Keyworddefs.DoesNotExist:
                return False
        # we have to delete all old labels, unfortunately the Keywords table
        # has a multicolumn primary key, which django can't handle, so we have
        # to use raw SQL
        for kw in bug.kws.all():
            from django.db import connection, transaction
            cursor = connection.cursor()
            cursor.execute("DELETE FROM keywords WHERE bug_id = %s AND keywordid = %s", [bug.bug_id, kw.id])
            transaction.commit_unless_managed()
        for l in new_labels:
            kw = Keyworddefs.objects.get(name=l)
            k = Keywords(bug_id=bug, keywordid=kw)
            k.save()
    return True
示例#9
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