-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclgen.py
106 lines (101 loc) · 4.72 KB
/
clgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# CLGen.py
# Cepheus Light command line character generator by Omer Golan-Joel
# v1.1 - February 11th, 2021
# This is open source code, feel free to use it for any purpose
# contact me at [email protected]
# Import modules
from openpyxl.worksheet.worksheet import Worksheet
import clgen_lib
import sys
import openpyxl
from openpyxl.styles import Font
from openpyxl.worksheet.dimensions import ColumnDimension, DimensionHolder
from openpyxl.utils import get_column_letter
from openpyxl.styles import Alignment
def excel_save(filename, iteration):
workbook = openpyxl.Workbook()
sheet: Worksheet = workbook.active
sheet.title = "Cepheus Light Characters"
sheet['A1'] = "Cepheus Light Characters"
sheet['A1'].font = Font(size=16, bold=True)
sheet['A2'] = "Generated by the Cepheus Light Character Generator by Stellagama Publishing"
for cell in ["A3", "B3", "C3", "D3", "E3", "F3", 'G3', 'H3', 'I3', 'J3', 'K3', 'L3', 'M3', 'N3', 'O3', 'P3']:
sheet[cell].font = Font(bold=True)
sheet['A3'] = "Number"
sheet['B3'] = "Title"
sheet['C3'] = "Given Name"
sheet['D3'] = "Surname"
sheet['E3'] = "STR"
sheet['F3'] = "DEX"
sheet['G3'] = "END"
sheet['H3'] = "INT"
sheet['I3'] = "EDU"
sheet['J3'] = "SOC"
sheet['K3'] = "Age"
sheet['L3'] = "Career"
sheet['M3'] = "Rank"
sheet['N3'] = "Cash"
sheet['O3'] = "Skills"
sheet['P3'] = "Possessions"
excel_row = 4
for character_iteration in range (0, iteration):
character = clgen_lib.Character(death=False)
sheet.cell(row=excel_row, column=1).value = character_iteration+1
sheet.cell(row=excel_row, column=1).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=2).value = character.title
sheet.cell(row=excel_row, column=3).value = character.name
sheet.cell(row=excel_row, column=4).value = character.surname
sheet.cell(row=excel_row, column=5).value = character.upp["STR"]
sheet.cell(row=excel_row, column=5).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=6).value = character.upp["DEX"]
sheet.cell(row=excel_row, column=6).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=7).value = character.upp["END"]
sheet.cell(row=excel_row, column=7).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=8).value = character.upp["INT"]
sheet.cell(row=excel_row, column=8).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=9).value = character.upp["EDU"]
sheet.cell(row=excel_row, column=9).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=10).value = character.upp["SOC"]
sheet.cell(row=excel_row, column=10).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=11).value = character.age
sheet.cell(row=excel_row, column=11).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=12).value = character.career
sheet.cell(row=excel_row, column=13).value = character.rank_name
sheet.cell(row=excel_row, column=14).value = character.cash
sheet.cell(row=excel_row, column=14).alignment = Alignment(horizontal='left')
sheet.cell(row=excel_row, column=15).value = character.skill_string
sheet.cell(row=excel_row, column=16).value = character.possessions_string
excel_row += 1
dim_holder = DimensionHolder(worksheet=sheet)
for col in [2, 3, 4, 13, 15, 16]:
dim_holder[get_column_letter(col)] = ColumnDimension(sheet, min=col, max=col, width=20)
sheet.column_dimensions = dim_holder
workbook.save(filename)
if __name__ == "__main__":
try:
char_iterations = sys.argv[1]
except IndexError:
char_iterations = 1
filecheck = False
i = 1
if char_iterations == "help":
print(f"Cepheus Light Command Line Character Generator\nRun as python 'clgen.py n' where 'n' is the number of characters you want to generate. Default 1 character.")
else:
try:
i = int(char_iterations)
except ValueError:
i = 1
try:
if sys.argv[2]:
filecheck = True
filename = sys.argv[2]
except IndexError:
filecheck = False
if not filecheck:
for i in range (0, i):
character = clgen_lib.Character()
print(f"{character.character_string}\n")
if filecheck:
print(f"Saving Excel spreadsheet {filename}.xlsx")
filename = str(sys.argv[2])
excel_save(filename+".xlsx", i)