2 # Display Latin famous phrases in the terminal
10 def main(args=sys.argv[1:]):
12 parser = argparse.ArgumentParser(description="Latin famous phrases in the terminal.")
13 parser.add_argument("-e", "--english", action='store_true', help="Print the English translation.")
14 parser.add_argument("-i", "--id", action='store_true', help="Print the id of the phrase.")
15 parser.add_argument("-l", "--latin", action='store_true', help="Print the Latin phrase (default)")
16 parser.add_argument("-m", "--min", default=0, type=int, help="Set the minimum length of the Latin phrase")
17 parser.add_argument("-M", "--max", default=10000000, type=int, help="Set the maximum length of Latin phrase")
18 parser.add_argument("-n", "--notes", action='store_true', help="Print any notes on phrase")
19 args = parser.parse_args()
23 # Find phrases of the right size
24 with open('/usr/share/phrases/phrases.csv') as f:
25 reader = csv.reader(f)
26 all_lines = list(reader)
27 next(reader, None) # skip header
30 if args.max >= int(row[4]) >= args.min: # generate a shortlist of phrases of the right length
31 right_length.append(row[0])
33 pass # skip malformed rows
36 chosen = int(right_length[random.randint(0, len(right_length) - 1)]) # choose a random id from the shortlist
38 sys.exit("No phrase within the given parameters!")
40 # Output as specified in flags
41 if not (args.english or args.latin or args.notes):
42 print(all_lines[chosen][1])
45 print(all_lines[chosen][1])
47 print(all_lines[chosen][1])
49 print(all_lines[chosen][2])
51 print(all_lines[chosen][3])
53 if __name__ == "__main__":