From 29320b6dd05e98cc30b4b7c42ef5b6b8450ba80b Mon Sep 17 00:00:00 2001 From: George Zhang Date: Sat, 21 Nov 2020 18:59:04 -0500 Subject: [PATCH] Allow comments in config files --- README.md | 4 +++- example.txt | 2 ++ form.py | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6fae4b7..6d4474e 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,9 @@ You can also run the following in case the program window closes immediately. ## Config -The *config.txt* file starts with the link to the Google Form (just copy from the address bar). The following lines have the following form: +The *config.txt* file starts with the link to the Google Form (just copy from the address bar). + +The following lines contain info for each entry and the format is shown below. Empty lines and lines starting with `"#"` are skipped. Spaces between parts are ignored. ``` ["*"] ["!"] type "-" key ";" [title] "=" [value] diff --git a/example.txt b/example.txt index 7fe0c07..1791f76 100644 --- a/example.txt +++ b/example.txt @@ -1,4 +1,6 @@ https://docs.google.com/forms/d/e/1FAIpQLSfWiBiihYkMJcZEAOE3POOKXDv6p4Ox4rX_ZRsQwu77aql8kQ/viewform + +# This is the only prompt (helps identify responses) ! words - 2126808200 ; Short Answer = Default words - 647036320 ; Paragraph = Sent using form.py (example-config.txt) choice - 363426485 ; Multiple Choice (Option 1, Option 2) = Option 1 diff --git a/form.py b/form.py index 53bba40..c0bc5d6 100644 --- a/form.py +++ b/form.py @@ -269,7 +269,14 @@ def open_config(file): file = open(file) with file: url = to_form_url(file.readline()) - entries = [EntryInfo.from_string(line) for line in file if line.strip()] + entries = [] + for line in file: + line = line.strip() + if not line: + continue + if line.startswith("#"): + continue + entries.append(EntryInfo.from_string(line)) return ConfigInfo(url, entries) # Returns the passed config file name