Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
93 lines (68 loc) · 2.46 KB

File metadata and controls

executable file
·
93 lines (68 loc) · 2.46 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
"""Create Workout Of (the) Day (WOD)"""
import argparse
import csv
import io
import random
from tabulate import tabulate
# --------------------------------------------------
def get_args():
"""Get command-line arguments"""
parser = argparse.ArgumentParser(
description='Create Workout Of (the) Day (WOD)',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-f',
'--file',
help='CSV input file of exercises',
metavar='FILE',
type=argparse.FileType('rt'),
default='inputs/exercises.csv')
parser.add_argument('-s',
'--seed',
help='Random seed',
metavar='seed',
type=int,
default=None)
parser.add_argument('-n',
'--num',
help='Number of exercises',
metavar='exercises',
type=int,
default=4)
parser.add_argument('-e',
'--easy',
help='Halve the reps',
action='store_true')
args = parser.parse_args()
if args.num < 1:
parser.error(f'--num "{args.num}" must be greater than 0')
return args
# --------------------------------------------------
def main():
"""Make a jazz noise here"""
args = get_args()
random.seed(args.seed)
wod = []
exercises = read_csv(args.file)
for name, low, high in random.sample(exercises, k=args.num):
reps = random.randint(low, high)
if args.easy:
reps = int(reps / 2)
wod.append((name, reps))
print(tabulate(wod, headers=('Exercise', 'Reps')))
# --------------------------------------------------
def read_csv(fh):
"""Read the CSV input"""
exercises = []
for row in csv.DictReader(fh, delimiter=','):
low, high = map(int, row['reps'].split('-'))
exercises.append((row['exercise'], low, high))
return exercises
# --------------------------------------------------
def test_read_csv():
"""Test read_csv"""
text = io.StringIO('exercise,reps\nBurpees,20-50\nSitups,40-100')
assert read_csv(text) == [('Burpees', 20, 50), ('Situps', 40, 100)]
# --------------------------------------------------
if __name__ == '__main__':
main()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.