Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New, exciting stuff! #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2018 Antoine Busque
Copyright (c) 2018 Philippe Proulx

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include qng/data *
recursive-include qngng/data *
109 changes: 60 additions & 49 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,97 +1,108 @@
===
qng
===
=====
qngng
=====

**qngng**, the Queb name generator: *next generation*.

This is a fork of the more basic `qng <https://github.com/abusque/qng>`_
project which includes the novel ``qngng-uda`` program to generate a
random name from the `UDA <https://uda.ca/>`_ directory.

Unfortunately, the qng maintainer is unresponsive and won't follow up
with community contributions, so this fork is necessary.

**qng**, the Queb name generator.

Requirements
------------
To run **qngng**, you only need Python ≥ 3.6.

To run **qng**, you will only need Python ≥ 3.6.

For installing, we recommend using the ``pip`` package manager.

Installing
----------

To install **qng** system-wide, run:
To install **qngng** system-wide, run:

.. code-block:: sh

sudo pip3 install qng
$ sudo pip3 install qngng

To install **qng** manually from source, the steps are as follows:
To install **qngng** manually from source, the steps are as follows:

.. code-block:: sh

git clone git@github.com:abusque/qng.git
cd qng
sudo ./setup.py install
$ git clone https://github.com/eepp/qngng
$ cd qngng
$ sudo ./setup.py install

Using
-----

Once installed, you can use **qng** by running the following command:
Usage
-----
qngng
~~~~~
Once installed, you can use **qngng**:

.. code-block:: sh

qng

$ qngng

This will generate a single random Queb name.
This generates a single random Queb name.

You can also generate names for a specific gender:

.. code-block:: sh

qng --gender male

$ qngng --gender=male

Generate names according to their relative popularity:

.. code-block:: sh

qng --weighted

$ qngng --weighted

Generate a name formatted as "snake_case" without any diacritics
(useful for naming your containers):
Generate a name formatted as "snake_case" without any diacritics:

.. code-block:: sh

qng --snake-case
$ qngng --snake-case

Generate a name formatted as "kebab-case" without any diacritics:

.. code-block:: sh

All the above options may be combined if desired. Refer to the help
for more details:
$ qngng --kebab-case

qngng-uda
~~~~~~~~~
If you want to get a real `UDA <https://uda.ca/>`_ member name, you can
use ``qngng-uda``:

.. code-block:: sh

qng --help
$ qngng-uda

Like ``qngng``, ``qngng-uda`` supports the ``--gender``, ``--snake-case``,
and ``--kebab-case`` options.

Development
-----------
You can get the name of an UDA actor, host (*animateur* in French), or
singer with the ``--type`` option:

For local development of **qng**, you may use
`pipenv <https://docs.pipenv.org/>`_. Use ``pipenv install --dev`` to
generate a virtual environment into which the dependencies will be
installed. You may then use ``pipenv shell`` to activate that
environment.
.. code-block:: sh

For publishing releases to PyPI, we recommend using
`Twine <https://pypi.org/project/twine/>`_.
$ qngng-uda --type=actor
$ qngng-uda --type=host
$ qngng-uda --type=singer

References
----------

The data for **qng** was sourced from `l'institut de la statistique`_
for surnames, and from `PrénomsQuébec.ca`_ for first names (who in
turn get their data from Retraite Québec's `banque de prénoms`_).
Sources
-------
The data for **qngng** was sourced from l'`Institut de la statistique
<http://www.stat.gouv.qc.ca/statistiques/population-demographie/caracteristiques/noms_famille_1000.htm>`_
for surnames, and from `PrénomsQuébec.ca
<https://www.prenomsquebec.ca/>`_ for first names (who in turn get their
data from Retraite Québec's `Banque de prénoms
<https://www.rrq.gouv.qc.ca/fr/enfants/banque_prenoms/Pages/banque_prenoms.aspx>`_).

Scripts used for scraping the data from the web pages can be found
under the ``scripts/`` directory.
The data for the ``qngng-uda`` command was sourced from the April 2019
UDA directory.

.. _l'institut de la statistique: http://www.stat.gouv.qc.ca/statistiques/population-demographie/caracteristiques/noms_famille_1000.htm
.. _PrénomsQuébec.ca: https://www.prenomsquebec.ca/
.. _banque de prénoms: https://www.rrq.gouv.qc.ca/fr/enfants/banque_prenoms/Pages/banque_prenoms.aspx
Scripts used for scraping the data from the web pages are in the
``scripts`` directory.
2 changes: 0 additions & 2 deletions qng/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions qngng/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = '0.2'
__description__ = 'The Queb name generator: next generation'
4 changes: 2 additions & 2 deletions qng/cli.py → qngng/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import unicodedata
from typing import Optional

import qng
import qngng


_BASE_DIR = os.path.dirname(os.path.realpath(__file__))
_DATA_DIR = os.path.join(_BASE_DIR, 'data')


def _parse_args():
parser = argparse.ArgumentParser(description=qng.__description__)
parser = argparse.ArgumentParser(description=qngng.__description__)

parser.add_argument('--gender', '-g', choices=['male', 'female'],
help='Filter first names by gender')
Expand Down
94 changes: 94 additions & 0 deletions qngng/cli_qngng.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import argparse
import json
import operator
import os
import random
import sys
import unicodedata
from typing import Optional

import qngng
from qngng import common


def _parse_args():
parser = argparse.ArgumentParser(description=qngng.__description__)

parser.add_argument('--gender', '-g', choices=['male', 'female'],
help='Filter first names by gender')
parser.add_argument('--snake-case', '-s', action='store_true',
help='Print names in "snake_case" format')
parser.add_argument('--kebab-case', '-k', action='store_true',
help='Print names in "kebab-case" format')
parser.add_argument('--weighted', '-w', action='store_true',
help='Pick names according to their relative popularity')
args = parser.parse_args()
common._validate_snake_kebab_args(args)
return args


def _read_name_file(filename):
file_path = os.path.join(common._DATA_DIR, filename)
with open(file_path) as f:
names = json.load(f)

return names


def _get_names(gender: Optional[str] = None):
names = _read_name_file('names.json')

if gender:
names = [name for name in names if name['gender'] == gender]

return names


def _get_surnames():
return _read_name_file('surnames.json')


def _get_random_name(name_list) -> str:
length = len(name_list)
index = random.randrange(length)

return name_list[index]['name']


def _get_weighted_random_name(name_list) -> str:
name_list = sorted(
name_list,
key=operator.itemgetter('weight'),
reverse=True,
)

total_weight = sum(entry['weight'] for entry in name_list)
random_weight = random.randrange(total_weight + 1)

for entry in name_list:
random_weight -= entry['weight']
if random_weight <= 0:
return entry['name']


def _run(args):
names = _get_names(gender=args.gender)
surnames = _get_surnames()

if args.weighted:
get_random_name = _get_weighted_random_name
else:
get_random_name = _get_random_name

name = get_random_name(names)
surname = get_random_name(surnames)
common._print_name(name, surname, args)


def main():
args = _parse_args()

try:
_run(args)
except KeyboardInterrupt:
sys.exit(1)
75 changes: 75 additions & 0 deletions qngng/cli_qngng_uda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import argparse
import json
import operator
import os
import random
import sys
import unicodedata
from typing import Optional

import qngng
from qngng import common


def _parse_args():
parser = argparse.ArgumentParser(description=qngng.__description__)
parser.add_argument('--gender', '-g', choices=['male', 'female'],
help='Filter first names by gender')
parser.add_argument('--snake-case', '-s', action='store_true',
help='Print names in "snake_case" format')
parser.add_argument('--type', '-t', choices=['actor', 'host', 'singer'],
help='Filter names by UDA membership type')
parser.add_argument('--kebab-case', '-k', action='store_true',
help='Print names in "kebab-case" format')
args = parser.parse_args()
common._validate_snake_kebab_args(args)
return args


def _read_name_file(filename: str):
file_path = os.path.join(common._DATA_DIR, f'uda-{filename}.json')

with open(file_path) as f:
names = json.load(f)

return names


def _append_entries(entries, filename_male, filename_female, gender):
if gender == 'male' or gender is None:
entries += _read_name_file(filename_male)

if gender == 'female' or gender is None:
entries += _read_name_file(filename_female)


def _get_random_entry(entries):
return entries[random.randrange(len(entries))]


def _run(args):
entries = []

if args.type:
if args.type == 'actor':
_append_entries(entries, 'actors', 'actresses', args.gender)
elif args.type == 'host':
_append_entries(entries, 'hosts-m', 'hosts-f', args.gender)
elif args.type == 'singer':
_append_entries(entries, 'singers-m', 'singers-f', args.gender)
else:
_append_entries(entries, 'actors', 'actresses', args.gender)
_append_entries(entries, 'hosts-m', 'hosts-f', args.gender)
_append_entries(entries, 'singers-m', 'singers-f', args.gender)

entry = _get_random_entry(entries)
common._print_name(entry['name'], entry['surname'], args)


def main():
args = _parse_args()

try:
_run(args)
except KeyboardInterrupt:
sys.exit(1)
Loading