-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import click | ||
from database import get_collection | ||
|
||
@click.command() | ||
@click.argument('collection_id', type=int) | ||
@click.argument('output_file', type=click.Path(writable=True)) | ||
def checklist(collection_id, output_file): | ||
""" | ||
Export a collection of items as a markdown checklist. | ||
COLLECTION_ID: The ID of the collection to export. | ||
OUTPUT_FILE: The file to write the markdown checklist to. | ||
""" | ||
try: | ||
collection = get_collection(collection_id) | ||
markdown_content = generate_markdown_checklist(collection) | ||
|
||
with open(output_file, 'w') as file: | ||
file.write(markdown_content) | ||
|
||
click.echo(f"Collection {collection_id} exported to {output_file} successfully.") | ||
except Exception as e: | ||
click.echo(f"An error occurred: {e}") | ||
|
||
def generate_markdown_checklist(collection): | ||
""" | ||
Generate a markdown checklist for a given collection. | ||
""" | ||
checklist = f"# {collection.name}\n" | ||
checklist += f"{collection.description}\n\n" | ||
|
||
for category, items_list in collection.items.items(): | ||
checklist += f"### {category}\n\n" | ||
for item in items_list: | ||
name = pad_string(item.name, 30) | ||
checklist += f"- [ ] {name} ({item.note})\n" | ||
checklist += f"\n" | ||
|
||
return checklist | ||
|
||
def pad_string(s, width): | ||
return s + ' ' * (width - len(s)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Kungsleden | ||
|
||
Zweden met Milan ♥︎ | ||
|
||
## Items | ||
|
||
### Shelter | ||
- [ ] Bonfus Middus 2 (900.0 Shelter) | ||
- [ ] Mongar 2 (2400.0 Shelter) | ||
- [ ] Hilleberg Soulo (2800.0 Shelter) | ||
### Sleep | ||
- [ ] Thermarest XTherm (580.0 Sleep) | ||
- [ ] Cumulus XLite 200 (380.0 Sleep) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Kungsleden | ||
Zweden met Milan ♥︎ | ||
|
||
## Items | ||
|
||
### Shelter | ||
- [ ] Bonfus Middus 2 (900.0 Shelter) | ||
- [ ] Mongar 2 (2400.0 Shelter) | ||
- [ ] Hilleberg Soulo (2800.0 Shelter) | ||
### Sleep | ||
- [ ] Thermarest XTherm (580.0 Sleep) | ||
- [ ] Cumulus XLite 200 (380.0 Sleep) |