コード例 #1
0
ファイル: views.py プロジェクト: markharley/anarxiv
def updatePapers():
    NoDays = 4
    thisDay = datetime.date.today()
    oneDay = datetime.timedelta(days=1)
    date = thisDay - oneDay * NoDays

    papers = newPaper.objects.filter(added_at=date)

    for article in papers:
        posts = article.post_set.all()
        # Deletes the paper if it has not comments on it
        if len(posts) == 0:
            article.delete()
        else:
            url = (
                "https://inspirehep.net/search?of=recjson&ln=en&ln=en&p=find+eprint+arxiv:"
                + str(article.arxiv_no)
                + "&of=hb&action_search=Search&sf=earliestdate&so=d&rm=&rg=25&sc=0"
            )
            try:
                data = requests.get(url).json()
                inspires_no = data[0]["recid"]
                paperStore(inspires_no)

                # Move the messages over
                y = Paper.objects.get(Inspires_no=inspires_no)
                posts = article.post_set.all()
                for post in posts:
                    temp = post.message
                    temp2 = Post(message=temp, paper=y)
                    temp2.save()

                    # Delete the paper
                article.delete()

            except ValueError:
                pass
コード例 #2
0
ファイル: views.py プロジェクト: markharley/anarxiv
def messageSubmission(request):
    message = request.POST["message"]
    message_id = request.POST["id"]
    arxivno = request.POST["arxivno"]

    # Check if the message is clean or not
    if not checkClean(message):
        return JsonResponse({"messageHTML": "UNCLEAN"})

    else:

        # If the paper has an arXiv number
        if arxivno != "0":

            # We check the newPaper and Paper databases
            if newPaper.objects.filter(arxiv_no=arxivno).count() != 0:
                paper = newPaper.objects.get(arxiv_no=arxivno)
                numposts = len(paper.post_set.all())
                post = Post(message=message, new_paper=paper, messageID=numposts + 1, poster=request.user)

            elif Paper.objects.filter(arxiv_no=arxivno).count() != 0:
                paper = Paper.objects.get(arxiv_no=arxivno)
                numposts = len(paper.post_set.all())
                post = Post(message=message, paper=paper, messageID=numposts + 1, poster=request.user)

                # Else we create the paper object
            else:
                p = arXivSearch(arxivno, "")["paperList"][0]
                paper = Paper(
                    title=p["title"], abstract=p["abstract"], arxiv_no=p["arxiv_no"], journal=p["journal_ref"]
                )
                paper.save()
                post = Post(message=message, paper=paper, messageID=1, poster=request.user)

                authors = p["authorlist"]

                for author in authors:

                    if (
                        Author.objects.filter(firstName=author["firstName"], secondName=author["secondName"]).count()
                        == 0
                    ):

                        temp = Author(firstName=author["firstName"], secondName=author["secondName"])
                        temp.save()
                        # Adds the paper to the Author
                        temp.articles.add(paper)

                    else:
                        temp = Author.objects.get(firstName=author["firstName"], secondName=author["secondName"])
                        temp.articles.add(paper)

                        # If the paper does not have an arXiv number
        else:
            # We just have to look for the paper in the Paper database
            if Paper.objects.filter(Inspires_no=message_id).count() == 1:
                paper = Paper.objects.get(Inspires_no=message_id)
                numposts = len(paper.post_set.all())
                post = Post(message=message, paper=paper, messageID=numposts + 1, poster=request.user)

                # Else we create the paper object
            else:
                temp = paperStore(message_id, "Inspires")
                post = Post(message=message, paper=temp, messageID=1, poster=request.user)

        post.save()

        context = {"message": post.message, "time": post.date, "number": post.messageID, "user": post.poster.username}
        template = loader.get_template("message.html")

        temp = str(template.render(context).encode("utf8"))

        return JsonResponse({"messageHTML": temp, "message_number": post.messageID})