def chargen(): death_toggle = request.args.get("Death", 'None Selected') death = False if death_toggle == "Death": death = True elif death_toggle == "Life": death = False career_option = request.args.get("Career", None) career = [] careerDefault = "Any" if career_option is not None: if career_option != "any": career = career_option careerDefault = career_option character = clgen_lib.Character(death, career) return render_template("index.html", title=character.title, name=character.name, surname=character.surname, upp_string=character.upp_string, age=character.age, status=character.status, career=character.career, rank_name=character.rank_name, terms=character.terms, credits=character.cash, possessions=character.possessions_string, skills=character.skill_string, deathDefault=death, careerDefault=careerDefault) if request.args.get('generate') == 'Generate': return redirect(url_for('chargen', Death=death)) else: pass
def apiChargen(): death = True darg = request.args.get("death", None) if darg is not None: if darg.lower() == "false": death = False print("death="+str(death)) character = clgen_lib.Character(death) return Response(json.dumps(character.__dict__), mimetype='application/json')
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)