From afa380db31b52ba6a6e0873a0bf1c7d26be69492 Mon Sep 17 00:00:00 2001 From: Rawleenc Date: Tue, 19 Nov 2024 22:28:04 +0100 Subject: [PATCH] feat: initial commit --- .dockerignore | 2 ++ .gitignore | 2 ++ Dockerfile | 12 ++++++++++++ entrypoint.sh | 14 ++++++++++++++ pyrpg.py | 42 ++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 6 files changed, 73 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 entrypoint.sh create mode 100644 pyrpg.py create mode 100644 requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8bd3289 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +out +.venv \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8bd3289 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +out +.venv \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..96326fc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3-alpine + +COPY . /app +WORKDIR /app + +VOLUME /app/out + +RUN pip install -r requirements.txt + +ENTRYPOINT [ "/app/entrypoint.sh" ] + +CMD [ "start" ] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..06b0aef --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "No command provided" + exit 1 +fi + +if [ "$1" = "start" ]; then + echo "Running the command: python /app/pyrpg.py ${NUMBER_OF_PSEUDONYMS:-100}" + python /app/pyrpg.py ${NUMBER_OF_PSEUDONYMS:-100} +else + echo "Running the command: $@" + exec "$@" +fi diff --git a/pyrpg.py b/pyrpg.py new file mode 100644 index 0000000..0ba28f7 --- /dev/null +++ b/pyrpg.py @@ -0,0 +1,42 @@ +import nltk +import sys +import random +import os + +def main(): + try: + num_pseudonyms = int(sys.argv[1]) if len(sys.argv) == 2 else 100 + except ValueError: + print("The argument must be an integer.") + return + + # Load the corpora + nltk.download('wordnet') + nltk.download('averaged_perceptron_tagger') + nltk.download('universal_tagset') + + # Get all the adjectives and nouns + adjectives = set() + nouns = set() + for synset in nltk.corpus.wordnet.all_synsets(): + for lemma in synset.lemmas(): + if lemma.name().isalpha(): + if synset.pos() == 'a': + adjectives.add(lemma.name()) + elif synset.pos() == 'n': + nouns.add(lemma.name()) + + # Create the output directory if it doesn't exist + os.makedirs('out', exist_ok=True) + + # Write the pseudonyms to a file + with open('out/pseudonyms.txt', 'w+') as file: + for _ in range(num_pseudonyms): + adjective = list(adjectives)[random.randint(0, len(adjectives) - 1)].capitalize() + noun = list(nouns)[random.randint(0, len(nouns) - 1)].capitalize() + number = random.randint(1, 999) + pseudonym = f'{adjective}-{noun}-{number}' + file.write(pseudonym + '\n') + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6fa2de4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +nltk \ No newline at end of file