at master
1 | #!/usr/bin/env python3 |
2 | # |
3 | # The MIT License (MIT) |
4 | # |
5 | # Copyright (c) 2018 Daniel Moch |
6 | # |
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | # of this software and associated documentation files (the "Software"), to deal |
9 | # in the Software without restriction, including without limitation the rights |
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | # copies of the Software, and to permit persons to whom the Software is |
12 | # furnished to do so, subject to the following conditions: |
13 | # |
14 | # The above copyright notice and this permission notice shall be included in all |
15 | # copies or substantial portions of the Software. |
16 | # |
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23 | # SOFTWARE. |
24 | # |
25 | from readingplan import ReadingPlan |
26 | from schedule import Schedule |
27 | from sys import argv |
28 | import configparser |
29 | |
30 | VERSION = '0.2.1-dev' |
31 | |
32 | def print_usage(): |
33 | print('generate_schedule ' + VERSION) |
34 | print('Usage: generate_schedule filename [config]') |
35 | print('\tfilename - File name to export schedule to. Export type is') |
36 | print('\t\tdetermined from extension. Supported types are:') |
37 | print('\t\tJSON (ext: .json)') |
38 | print('\t\tPlain text (ext: .txt)') |
39 | print('\t\tComma-separated values (ext: .csv)') |
40 | print('\t\tLaTeX (ext: .tex)') |
41 | print('\tconfig - Path to config file (default: generate_schedule.ini)') |
42 | |
43 | def generate_schedule(filename, configfile='generate_schedule.ini'): |
44 | """ |
45 | Generate the reading plan, using the ReadingPlan class as a |
46 | generator. This function takes the day-of-week that January 1st |
47 | falls on as its single parameter. |
48 | """ |
49 | config = configparser.ConfigParser() |
50 | config.read(configfile) |
51 | plan = ReadingPlan() |
52 | plan.build_plan(config) |
53 | schedule = Schedule() |
54 | schedule.filename = filename |
55 | while not plan.done: |
56 | schedule.data.append(plan.next_reading()) |
57 | schedule.export() |
58 | |
59 | if __name__ == "__main__": |
60 | if len(argv) > 3: |
61 | print_usage() |
62 | exit(1) |
63 | elif len(argv) < 2: |
64 | print_usage() |
65 | exit(1) |
66 | elif len(argv) == 2: |
67 | generate_schedule(argv[1]) |
68 | else: |
69 | generate_schedule(argv[1], argv[2]) |