def jump(args): try: search_history_id = args.get('search_history_id') paper_id = args.get('paper_id') search_history = SearchHistory.objects(id=search_history_id).get() search_item = search_history.item paper = Paper.objects(id=paper_id).get() click_history = ClickHistory( search_item=search_item, search_history=search_history, paper=paper, user=User.objects(id=flask_login.current_user.id).get() if flask_login.current_user.is_authenticated else None ) click_history.save() if ClickCount.objects(search_item=search_item, paper=paper).count() > 0: click_count = ClickCount.objects(search_item=search_item, paper=paper).get() else: click_count = ClickCount( search_item=search_item, paper=paper ) click_count.count = click_count.count + 1 click_count.save() return redirect(paper.url) except Exception as e: logging.warning(e) abort(401)
def store_paper(paper): if Paper.objects(title=paper.get("Title")).count() == 0: authors = [] for author in paper.get("Author"): if Author.objects(name=author).count() == 0: author = Author(name=author) author.save() else: author = Author.objects(name=author).get() authors.append(author) paper_mongo = Paper( title=paper.get("Title"), abstract=paper.get("Abstract"), journal=paper.get("Journal"), authors=authors, date=paper.get("Date"), url=paper.get("URL") ) paper_mongo.save() else: paper_mongo = Paper.objects(title=paper.get("Title")).get() return paper_mongo
def show(id): try: count = request.args.get('count', 20) offset = int(request.args.get('offset', 0)) item = SubscriptionItem.objects(id=id).get() papers = Paper.objects(subscriptions=item).order_by('-date').skip(offset).limit(count) if papers.count() > 0: return jsonify(response=[paper.serialize() for paper in papers]) else: return jsonify(response=[], more=False) except Exception as e: logging.warning(e) logging.warning(id) return jsonify(error="error")
def show(id): try: paper = Paper.objects(id=id).get() abstract = paper.abstract tokens = ''.join(c for c in abstract if c.isalnum() or c.isspace()).split() tokens.extend([p.plural(token) for token in tokens]) two_word = [ " ".join(tokens[i:i+2]) for i in range(len(tokens)-1)] two_word_plural = [ p.plural(w) for w in two_word ] tokens.extend(two_word) tokens.extend(two_word_plural) tokens.extend([t[0].upper()+t[1:] if t[0].islower() else t[0].lower()+t[1:] for t in tokens]) terms = [term.serialize() for term in Term.objects(name__in=tokens)] abstract = [abstract] for term in terms: # print('term {}; len {}'.format(term['name'], len(abstract))) name = term['name'] for i in range(len(abstract)): part = abstract[i] if isinstance(part, str): re1 = re.compile(name, re.I) # print("search {} in {}".format(name, part)) m = re.search(re1, part) if m: term_here = term.copy() term_here['here'] = m.group() part = re.split(re1, part) new_part = [term_here] * (len(part) * 2 - 1) new_part[0::2] = part part = new_part abstract = abstract[:i] + part + abstract[i+1:] continue plural = p.plural(name) re2 = re.compile(plural, re.I) # print("search {} in {}".format(name, part)) m = re.search(re2, part) if m: term_here = term.copy() term_here['here'] = m.group() part = re.split(re2, part) new_part = [term_here] * (len(part) * 2 - 1) new_part[0::2] = part part = new_part abstract = abstract[:i] + part + abstract[i+1:] return jsonify(response=abstract) except Exception as e: logging.warning(e) return jsonify(response=list(), error=True)
def get_timeline(): user = User.objects(id=current_user.id).get() papers = Paper.objects(subscriptions__in=user.subscriptions).order_by('-date') return papers