Prepared repo or first upload of updated code.
This commit is contained in:
parent
c141426908
commit
aa4ddbb7f4
2 changed files with 23 additions and 90 deletions
|
|
@ -1,80 +0,0 @@
|
||||||
|
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
from Generator import NpcGenerator
|
|
||||||
|
|
||||||
|
|
||||||
def validate_api_token():
|
|
||||||
token = os.getenv("APITOKEN")
|
|
||||||
if not token:
|
|
||||||
sys.exit("❌ Error: API token is missing. Make sure APITOKEN=<token> is set in your .env file.")
|
|
||||||
token = token.strip('"').strip("'")
|
|
||||||
os.environ["APITOKEN"] = token
|
|
||||||
return token
|
|
||||||
|
|
||||||
|
|
||||||
def select_campaign(generator):
|
|
||||||
campaigns = generator.get_campaigns().get("data", [])
|
|
||||||
if not campaigns:
|
|
||||||
sys.exit("❌ No campaigns found.")
|
|
||||||
|
|
||||||
print("\nAvailable campaigns:")
|
|
||||||
for idx, campaign in enumerate(campaigns):
|
|
||||||
print(f" [{idx}] {campaign['name']} (ID: {campaign['id']})")
|
|
||||||
print(" [x] Exit")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
choice = input("\nEnter the number of the campaign to use (or 'x' to cancel): ").strip().lower()
|
|
||||||
if choice == 'x':
|
|
||||||
print("Exiting.")
|
|
||||||
sys.exit(0)
|
|
||||||
try:
|
|
||||||
index = int(choice)
|
|
||||||
if 0 <= index < len(campaigns):
|
|
||||||
return campaigns[index]['name']
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
print("Invalid choice. Try again.")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(description="Generate random NPCs in a Kanka campaign.")
|
|
||||||
parser.add_argument("--host", help="Set API base URL (e.g., https://kanka.example.com/api/1.0/)")
|
|
||||||
parser.add_argument("--campaign", help="Specify campaign name directly")
|
|
||||||
parser.add_argument("--count", type=int, help="Number of NPCs to generate", default=None)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
# Normalize host input if provided
|
|
||||||
if args.host:
|
|
||||||
host = args.host.strip()
|
|
||||||
if not host.startswith("http://") and not host.startswith("https://"):
|
|
||||||
host = "https://" + host
|
|
||||||
if not host.endswith("/api/1.0/"):
|
|
||||||
host = host.rstrip("/") + "/api/1.0/"
|
|
||||||
os.environ["API_URL"] = host
|
|
||||||
|
|
||||||
validate_api_token()
|
|
||||||
generator = NpcGenerator()
|
|
||||||
|
|
||||||
campaign_name = args.campaign or select_campaign(generator)
|
|
||||||
|
|
||||||
count = args.count
|
|
||||||
if count is None:
|
|
||||||
try:
|
|
||||||
count = int(input("Enter number of NPCs to generate: "))
|
|
||||||
except ValueError:
|
|
||||||
sys.exit("❌ Invalid number entered.")
|
|
||||||
|
|
||||||
generator.create_npcs(campaign_name, count)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
33
npc-gen.py
33
npc-gen.py
|
|
@ -4,14 +4,19 @@
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from Generator import NpcGenerator
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
from Generator import NpcGenerator
|
||||||
|
|
||||||
|
|
||||||
def validate_api_token():
|
def validate_api_token():
|
||||||
token = os.getenv("APITOKEN")
|
token = os.getenv("APITOKEN")
|
||||||
if not token or len(token) < 30:
|
if not token:
|
||||||
sys.exit("❌ Error: API token is missing or looks invalid. Make sure APITOKEN=<token> is set in your .env file.")
|
sys.exit("❌ Error: API token is missing. Make sure APITOKEN=<token> is set in your .env file.")
|
||||||
|
token = token.strip('"').strip("'")
|
||||||
|
os.environ["APITOKEN"] = token
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -23,12 +28,17 @@ def select_campaign(generator):
|
||||||
print("\nAvailable campaigns:")
|
print("\nAvailable campaigns:")
|
||||||
for idx, campaign in enumerate(campaigns):
|
for idx, campaign in enumerate(campaigns):
|
||||||
print(f" [{idx}] {campaign['name']} (ID: {campaign['id']})")
|
print(f" [{idx}] {campaign['name']} (ID: {campaign['id']})")
|
||||||
|
print(" [x] Exit")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
choice = input("\nEnter the number of the campaign to use (or 'x' to cancel): ").strip().lower()
|
||||||
|
if choice == 'x':
|
||||||
|
print("Exiting.")
|
||||||
|
sys.exit(0)
|
||||||
try:
|
try:
|
||||||
choice = int(input("\nEnter the number of the campaign to use: "))
|
index = int(choice)
|
||||||
if 0 <= choice < len(campaigns):
|
if 0 <= index < len(campaigns):
|
||||||
return campaigns[choice]['name']
|
return campaigns[index]['name']
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
print("Invalid choice. Try again.")
|
print("Invalid choice. Try again.")
|
||||||
|
|
@ -42,17 +52,20 @@ def main():
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Set host override if provided
|
# Normalize host input if provided
|
||||||
if args.host:
|
if args.host:
|
||||||
os.environ["API_URL"] = args.host
|
host = args.host.strip()
|
||||||
|
if not host.startswith("http://") and not host.startswith("https://"):
|
||||||
|
host = "https://" + host
|
||||||
|
if not host.endswith("/api/1.0/"):
|
||||||
|
host = host.rstrip("/") + "/api/1.0/"
|
||||||
|
os.environ["API_URL"] = host
|
||||||
|
|
||||||
validate_api_token()
|
validate_api_token()
|
||||||
generator = NpcGenerator()
|
generator = NpcGenerator()
|
||||||
|
|
||||||
# Determine campaign name
|
|
||||||
campaign_name = args.campaign or select_campaign(generator)
|
campaign_name = args.campaign or select_campaign(generator)
|
||||||
|
|
||||||
# Determine NPC count
|
|
||||||
count = args.count
|
count = args.count
|
||||||
if count is None:
|
if count is None:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue