コード例 #1
0
    def _get_author(author_name):
        def _check_name(author_name, author_db):
            name_en = author_db["name_en"].upper()
            if author_db["name_ja"] == None:
                name_ja = ""
            else:
                name_ja = "".join(author_db["name_ja"].split())
            # print(author_name, "=>", name_en, name_ja)
            if author_name.upper() == name_en:
                return True
            elif len(name_ja) > 0 and (name_ja == "".join(
                    author_name.split())):
                # Japanene Version
                return True
            elif len(name_en.split(",")) == 2 and len(
                    author_name.split()) == 2:
                _name1 = [s.upper() for s in author_name.split()]
                _name2 = [s.strip() for s in name_en.split(",")]
                if (_name1[0] == _name2[0]) and (
                        _name1[1] == _name2[1]):  # FamilyName + FirstName
                    return True
                elif (_name1[0] == _name2[1]) and (
                        _name1[1] == _name2[0]):  # FirstName + FamilyName
                    return True
            return False

        for _author in [s.strip() for s in author_name.split()]:
            for author_db in get_authors(url_base, _author):
                if _check_name(author_name, author_db):
                    return author_db
        return None
コード例 #2
0
def material(id):
    work = librarymaterial.get_work(id)
    author = authors.get_author_by_work(id)
    free = loans.number_of_free(id)
    times_loaned = loans.times_loaned(id)
    a_list = authors.get_authors()
    type = materialtypes.get_type(id)
    t_list = materialtypes.get_types()
    return render_template("material.html", id=id, work=work, author=author, free=free, times_loaned=times_loaned, a_list=a_list, type=type, t_list=t_list)
コード例 #3
0
def statistics():
    if not accounts.is_admin():
        flash("Ei oikeuksia ylläpitosivulle.", "warning")
        return redirect("/")
    auth_list = authors.get_authors()
    m_list = librarymaterial.get_material_by_name()
    type_list = materialtypes.get_types()
    acc_list = accounts.get_accounts()
    loan_history = loans.get_loan_history()
    return render_template("statistics.html", auth_list=auth_list, m_list=m_list, type_list=type_list, acc_list=acc_list, loan_history=loan_history)
コード例 #4
0
ファイル: author_order.py プロジェクト: whx1994hans/PubZ
def create_author_order(url_base,
                        token,
                        author_order_dict,
                        logger=getLogger(__name__ + '.create_author_order')):
    """
    Args.
    -----
    - url         : str, API Endpoint
    - token       : str, Authentication Token
    - author_order_dict : dict object which contains ["bibtex_title", "authors",]

    Returns.
    --------
    - True/False
    """
    # Check payload
    key_expected, key_actual = set(["bibtex",
                                    "authors"]), set(author_order_dict.keys())
    if not key_expected == key_actual:
        logger.warning(
            "Check author_order_dict. some keys are missing or it contains unsed keys. [diff={}]"
            .format(key_expected - key_actual))
        raise ValueError("Check author_order_dict")

    # Get Bibtex Data
    url_get_bibtex = url_base + "bibtexs/"
    bibtexs = get_bibtexs(url_base, author_order_dict["bibtex"]["title"])
    bibtexs_selected = [
        bibtex for bibtex in bibtexs
        if (bibtex["title_en"] == author_order_dict["bibtex"]["title"]) or (
            bibtex["title_ja"] == author_order_dict["bibtex"]["title"])
    ]
    if len(bibtexs_selected) == 1:
        bibtex = bibtexs_selected[0]
        bibtex["title"] = author_order_dict["bibtex"]["title"]
        bibtex_id = bibtex["id"]
        logger.info("Get Bibtex data: {}".format(bibtex))
    else:
        logger.warning(
            "There is some anbiguity to selected bibtex. [got {}]".format(
                len(bibtexs)))
        logger.warning("Search [{}] ==> {}".format(author_order_dict["bibtex"],
                                                   bibtexs))
        df_tmp = pd.DataFrame({
            "bibtex_title": [author_order_dict["bibtex"]["title"]],
            "bibtex_id": [
                -1,
            ],
            "no": [
                0,
            ],
            "author": [
                author_order_dict["authors"],
            ],
            "status": [False],
            "msg": [
                "Bibtex not found [Got{}]".format(len(bibtexs)),
            ],
        })
        return df_tmp

    # Make Post Request
    url_post = url_base + "author-orders/"
    headers = {
        "Accept": "application/json",
        "Content-type": "application/json",
        "Authorization": "Token {}".format(token),
    }
    logger.debug("Make Requests:")
    logger.debug("- url    : {}".format(url_post))
    logger.debug("- headers: {}".format(headers))
    logger.debug("- params : {}".format(author_order_dict))

    df_ret = []
    authors_list = [a.strip() for a in author_order_dict["authors"].split(",")]
    for no, _author in enumerate(authors_list):
        row = [
            bibtex["title"],
            bibtex_id,
            no,
            _author,
        ]
        # Get Author Data
        url_get_author = url_base + "authors/"
        _author = _author.strip()
        authors = get_authors(url_base, _author)
        authors_selected = [
            author for author in authors
            if (_author == author["name_en"].upper()) or (
                _author == author["name_ja"].upper())
        ]
        if len(authors_selected) == 1:
            author = authors_selected[0]
            author_id = author["id"]
            logger.info("Get Author data: {}".format(author))
        else:
            logger.warning(
                "There is some anbiguity to selected author. [got {}]".format(
                    len(authors)))
            logger.warning("Search [{}] ==> {}".format(_author, authors))
            row = row + [
                False, "Author is unknow [Got {}]".format(len(authors))
            ]
            df_ret.append(row)
            continue

        # Post
        payload = {
            "bibtex_id": bibtex_id,
            "author_id": author_id,
            "order": no + 1,
        }
        r = requests.post(
            url_post,
            headers=headers,
            data=json.dumps(payload),
        )
        ## Check Responce
        logger.info("Response: status={}".format(r.status_code))
        data = json.loads(r.text)
        logger.debug("Response: status={}, data={}".format(
            r.status_code, data))
        if r.status_code == 201:
            logger.info("Success: Create new author_order.\n")
            row = row + [True, "Created"]
            df_ret.append(row)
            continue
        else:
            if str(data) == "['DB IntegrityError']":
                row = row + [True, str(data)]
                df_ret.append(row)
                continue
            logger.warning(
                "Failed: Cannot create new author_order. {} \n".format(data))
            row = row + [False, str(data)]
            df_ret.append(row)
            continue
    return pd.DataFrame(df_ret,
                        columns=[
                            "bibtex_titele", "bibtex_id", "no", "author",
                            "status", "msg"
                        ])
コード例 #5
0
def authors_list():
    a_list = authors.get_authors()
    return render_template("authors_list.html", a_list=a_list)