-
Notifications
You must be signed in to change notification settings - Fork 4
/
stellagama.py
154 lines (120 loc) · 3.37 KB
/
stellagama.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# stellagama.py
# A module with various useful functions by Omer Golan-Joel
# v3.1 - July 19th, 2020
# This is open source code, feel free to use it for any purpose
# contact me at [email protected]
# import modules
import random
import os
import platform
# functions
def yn():
query = 1
while query == 1:
answer = input("Y/N: ")
if answer.lower() == "y":
return "yes"
break
if answer.lower() == "n":
return "no"
break
else:
print("Invalid Answer")
def dice(n, sides):
die = 0
roll = 0
while die < n:
roll = roll + random.randint(1, sides)
die += 1
return roll
def pseudo_hex(num):
num = int(num)
code = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q",
"R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
num = code[num]
return num
def current_dir():
if platform.system() == "Windows":
directory = os.listdir(".\\")
else:
directory = os.getcwd()
return directory
def check_file_exists(check_file):
if check_file in os.listdir():
file_exists = True
else:
file_exists = False
return file_exists
def savefile(extension):
filename = str(input("Please enter file name to generate: "))
filecheck = filename + "." + extension
save = 1
if check_file_exists(filecheck):
print(" ")
print("File already exists. Overwrite?")
overwrite = yn()
if overwrite == "y":
save = 0
if overwrite == "n":
filename = input("Please enter new file name to generate: ")
filename = filename + "." + extension
return filename
def clear_screen():
if platform.system() == "Windows":
os.system('cls')
else:
os.system('clear')
def random_line(filename):
with open(filename, "r", encoding='utf-8', errors='ignore') as line_list:
line = random.choice(line_list.readlines())
line = line.strip()
return line
class Getch:
def __init__(self):
try:
self.impl = GetchWindows()
except ImportError:
self.impl = GetchUnix()
def __call__(self):
return self.impl()
class GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class GetchWindows:
def __init__(self):
import msvcrt
def __call__(self):
import msvcrt
return msvcrt.getch()
def getkeypress():
if platform.system() == "Windows":
directory = os.listdir(".\\")
key = Getch()
return key().decode()
else:
key = Getch()
return key()
def list_stringer(input_list):
output_list = []
for item in input_list:
output_list.append(str(item))
return ' '.join(output_list)
def second_highest(number_list):
secondary = 0
maximal = max(number_list)
for number in number_list:
if maximal > number > secondary:
secondary = number
else:
number = number
return secondary