Example #1
0
def get_dblp_key(authors, year):

    if isinstance(authors, str):
        authors = [authors]

    # start with first author's full name
    key = HumanName(authors[0]).last
    key = key.capitalize()  # e.g. de Val
    key = key.replace(' ', '')
    key = key.replace('-', '')
    key = key.replace('ß', 'ss')
    key = key.replace('ä', 'ae')
    key = key.replace('ö', 'oe')
    key = key.replace('ü', 'ue')

    # append co-authors' first letter from name
    for au in authors[1:]:
        cur_author = HumanName(au)
        key += cur_author.last[0]

    # add year
    key += str(year)[2:]

    key = unicodedata.normalize('NFKD', key).encode('ascii', 'ignore').decode()

    return str(key)
Example #2
0
def GetNameLink(name):
    # Finds and returns formatted name and wikilinks for given name.
    name = HumanName(name)
    name.capitalize(force=True)
    name = str(name)
    soup = GetSoup("https://en.wikipedia.org/wiki/" + name.replace(" ", "_"),
                   False).text
    wikitext = name
    tennis = [
        "International Tennis Federation", "Prize money", "Grand Slam",
        "tennis career", "Wikipedia does not have", "may refer to", "WTA",
        "ITF", "ATP"
    ]
    pipe = False
    if soup != None:
        if any([f in soup for f in tennis
                ]):  # player article exists, or no article exists
            if "Redirected from" in soup:
                soup = GetSoup(soup, True)
                title = str(soup.title.string).replace(" - Wikipedia",
                                                       "").strip()
                wikitext = title
                pipe = True  # if name is redirect, pipes wikilink to avoid anachronist names, e.g. using "Margaret Court" instead of "Margaret Smith" before she married.
        else:  # article exists for name but for different person
            wikitext = name + " (tennis)"
            pipe = True
    wikilink = "[[" + wikitext + ("|" + name if pipe else "") + "]]"
    split_name = name.split(" ")
    abbr_name = "-".join(
        f[0] for f in split_name[0].split("-")) + " " + " ".join(
            split_name[1:]
        )  # reduce name to first name initials + last name, e.g. "J-L Struff"
    abbr_wikilink = "[[" + wikitext + "|" + abbr_name + "]]"
    return [name, wikilink, abbr_wikilink]
Example #3
0
def GetNameLink(name, country):
    # Finds and returns formatted name and wikilinks for given name.
    name = HumanName(name)
    name.capitalize(force=True)
    name = str(name)
    soup = GetSoup("https://de.wikipedia.org/wiki/" + name.replace(" ", "_"),
                   False).text
    wikitext = name
    tennis = [
        "International Tennis Federation", "Preisgeld", "Grand Slam",
        "Tenniskarriere", "Diese Seite existiert nicht",
        "ist der Name folgender Personen", "WTA", "ITF", "ATP"
    ]
    pipe = False
    if soup != None:
        if any([f in soup for f in tennis
                ]):  # player article exists, or no article exists
            if "Weitergeleitet von" in soup:
                soup = GetSoup(soup, True)
                title = str(soup.title.string).replace(
                    " - Wikipedia", "").replace(" – Wikipedia", "").strip()
                if len(title.split(" ")) >= 3 and country == "RUS":
                    title = title.split(" ")
                    title = title[0] + " " + " ".join(title[2:])
                wikitext = title
                pipe = False  # If True, then if name is redirect, pipes wikilink to avoid anachronist names, e.g. using "Margaret Court" instead of "Margaret Smith" before she married.
        else:  # article exists for name but for different person
            wikitext = name + " (Tennisspieler)"
            pipe = True
    wikilink = ("Ziel=" if not pipe else "") + wikitext + ("|" + name
                                                           if pipe else "")
    split_name = wikitext.replace(" (Tennisspieler)", "").split(" ")
    abbr_name = ".-".join(
        f[0] for f in split_name[0].split("-")
    ) + ". " + " ".join(
        split_name[1:]
    )  # reduce name to first name initials + last name, e.g. "J.-L. Struff"
    abbr_wikilink = wikitext + "|" + abbr_name
    return [name, wikilink, abbr_wikilink]
def add():
    global initialised
    if not initialised:
        initialise()

    name = HumanName(request.forms.get('name'))
    first_name = name.first.upper()
    last_name = name.last.upper()
    department = request.forms.get('department').upper()
    designation = request.forms.get('designation').upper()
    photo = request.files.get('photo')
    name, ext = os.path.splitext(photo.filename)
    if ext not in ('.png', '.jpg', '.jpeg', '.JPG', '.JPEG', '.PNG'):
        rv = {"status": "photo_invalid"}
        return dict(rv)

    if not os.path.exists(folder_name + "/images/"):
        os.makedirs(folder_name + "/images/")

    name = first_name + "_" + last_name + "_" + department + "_" + designation
    photo.filename = name.replace(" ", "_") + ext
    photo.save(folder_name + "/images/")

    with open(folder_name + "/" + folder_name + ".csv", 'ab+') as csv_file:
        fieldnames = ['firstname', 'lastname', 'designation', 'department', 'photo']
        csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)

        csv_writer.writerow({
          'firstname': first_name,
          'lastname': last_name,
          'department': department,
          'designation': designation,
          'photo': "images/"+photo.filename
        })

    rv = {"status": "ok"}
    return dict(rv)