2 # Display Latin famous phrases in the terminal
10 def main(args=sys.argv[1:]):
12 parser = argparse.ArgumentParser(
13 description="Latin famous phrases in the terminal.")
14 parser.add_argument("-i", "--id",
16 help="print the id of the phrase.")
17 parser.add_argument("-l", "--latin",
19 help="print the Latin phrase (default)")
20 parser.add_argument("-e", "--english",
22 help="print the English translation.")
23 parser.add_argument("-n", "--notes",
25 help="print any notes on phrase")
26 parser.add_argument("-m", "--min",
29 help="set the minimum length of the Latin phrase")
30 parser.add_argument("-M", "--max",
33 help="set the maximum length of Latin phrase")
34 parser.add_argument("-p", "--num",
36 help="print number of possibilities within constraints")
37 parser.add_argument("-f", "--file",
38 default="/usr/share/phrases/phrases.csv",
39 help="set the location of the phrase file")
40 args = parser.parse_args()
44 # convert csv file into list
45 with open(args.file) as f:
46 reader = csv.reader(f)
47 next(reader, None) # skip header
48 all_lines = list(reader)
51 # iterate through all the phrases
53 try: # generate a shortlist of phrases of the right length
54 if args.max >= int(row[4]) >= args.min:
55 right_length.append(row[0])
56 except: # skip malformed rows without exiting
59 try: # choose a random id from the shortlist
60 chosen = int(right_length[random.randint(0, len(right_length) - 1)])
62 sys.exit("No phrase within the given parameters!")
64 # Output as specified in flags
66 if int(row[0]) == chosen:
83 print(len(right_length))
85 if __name__ == "__main__":