Skip to content
Snippets Groups Projects
Commit 241e3f8e authored by Millian Poquet's avatar Millian Poquet
Browse files

fetch-ics -> fetch-celcat (more output options)

parent db55e32e
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,16 @@ This project tries to make CELCAT usable by: ...@@ -11,7 +11,16 @@ This project tries to make CELCAT usable by:
- **TODO**: Providing a way to sync ics with a CalDAV server, to enable all calendar clients to synchronize from it - **TODO**: Providing a way to sync ics with a CalDAV server, to enable all calendar clients to synchronize from it
### Usage ### Usage
`fetch-ics <COURSE-REQUESTS-FILE.csv> [-o <OUTPUT-FILE.ics>]` ```
Usage: fetch-celcat [OPTIONS] COURSE_REQUEST_FILE
Options:
--json, --json-raw TEXT If set, raw CELCAT events are written as JSON to this file.
--csv-raw TEXT If set, raw (unfiltered) events are written as CSV to this file.
--csv TEXT If set, filteret events are written as CSV to this file.
--ics TEXT If set, filtered events are written as ICS to this file.
--help Show this message and exit.
```
The course request input file defines which courses you are interested in. The course request input file defines which courses you are interested in.
For example, if you give the following courses: For example, if you give the following courses:
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
let pkgs = nixpkgs.legacyPackages.${system}; let pkgs = nixpkgs.legacyPackages.${system};
in rec { in rec {
packages = import ./default.nix { inherit pkgs; }; packages = import ./default.nix { inherit pkgs; };
apps.fetch-ics = flake-utils.lib.mkApp { drv = packages.lflex_celcat_survival; exePath = "/bin/fetch-ics"; }; apps.fetch-celcat = flake-utils.lib.mkApp { drv = packages.lflex_celcat_survival; exePath = "/bin/fetch-celcat"; };
defaultPackage = packages.lflex_celcat_survival; defaultPackage = packages.lflex_celcat_survival;
} }
); );
......
...@@ -5,22 +5,41 @@ import lflex_celcat_survival as lcs ...@@ -5,22 +5,41 @@ import lflex_celcat_survival as lcs
@click.command() @click.command()
@click.argument('course_request_file') @click.argument('course_request_file')
@click.option('--output-file', '-o', default=None, help='Where to write the generated ICS (stdout if unset).') @click.option('--json', '--json-raw', default=None, help='If set, raw CELCAT events are written as JSON to this file.')
def main(course_request_file, output_file): @click.option('--csv-raw', default=None, help='If set, raw (unfiltered) events are written as CSV to this file.')
@click.option('--csv', default=None, help='If set, filteret events are written as CSV to this file.')
@click.option('--ics', default=None, help='If set, filtered events are written as ICS to this file.')
def main(course_request_file, json, csv_raw, csv, ics):
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
req = lcs.course_request.CourseRequest(course_request_file) req = lcs.course_request.CourseRequest(course_request_file)
if all(o is None for o in [json, csv_raw, csv, ics]):
logging.warning('No option set, doing nothing.')
return
celcat_raw_response = req.do_request() celcat_raw_response = req.do_request()
if json is not None:
with open(json, 'w') as f:
f.write(celcat_raw_response)
if all(o is None for o in [csv_raw, csv, ics]):
return
celcat_events = lcs.events.CelcatEvents(celcat_raw_response) celcat_events = lcs.events.CelcatEvents(celcat_raw_response)
if csv_raw is not None:
celcat_events.df.to_csv(csv_raw, index=False)
if all(o is None for o in [csv, ics]):
return
filtered_celcat_events = lcs.events.FilteredCelcatEvents(req, celcat_events) filtered_celcat_events = lcs.events.FilteredCelcatEvents(req, celcat_events)
filtered_celcat_events.check_expected_nb_timeslots() filtered_celcat_events.check_expected_nb_timeslots()
if csv is not None:
filtered_celcat_events.df.to_csv(csv, index=False)
if all(o is None for o in [ics]):
return
calendar = lcs.ics.course_df_to_ics(filtered_celcat_events.df) calendar = lcs.ics.course_df_to_ics(filtered_celcat_events.df)
if ics is not None:
if output_file is None: with open(ics, 'w') as f:
print(calendar)
else:
with open(output_file, 'w') as f:
f.write(str(calendar)) f.write(str(calendar))
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -29,4 +29,4 @@ dependencies = [ ...@@ -29,4 +29,4 @@ dependencies = [
] ]
[project.scripts] [project.scripts]
fetch-ics = "lflex_celcat_survival.cmd.fetch_ics:main" fetch-celcat = "lflex_celcat_survival.cmd.fetch_celcat:main"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment