feat: initial commit

This commit is contained in:
2024-11-19 22:28:04 +01:00
parent e55f4176be
commit afa380db31
6 changed files with 73 additions and 0 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
out
.venv

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
out
.venv

12
Dockerfile Normal file
View File

@@ -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" ]

14
entrypoint.sh Normal file
View File

@@ -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

42
pyrpg.py Normal file
View File

@@ -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()

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
nltk