-
-
Save scootcho/90525bd93b207c5ac7ec5aee5c0c8fe8 to your computer and use it in GitHub Desktop.
Scripts to display daily pages from The Daily Stoic (https://www.amazon.co.uk/Daily-Stoic-Meditations-Perseverance-translations-ebook/dp/B01KAFIQE6/)
This file contains hidden or 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
| #!/bin/bash | |
| leapyear=1 | |
| year=${1:-$(date '+%Y')} | |
| day=${2:-$(date '+%j')} | |
| ([ $(($day)) -lt 60 ]) || ([ $(($year % 4)) -eq 0 ] && ([ $(($year % 100)) -ne 0 ] || [ $(($year % 400)) -eq 0 ])) && | |
| leapyear=0 | |
| file=$(($day + leapyear)).jpg | |
| qimgv /usr/local/share/daily-stoic/$file |
This file contains hidden or 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
| const fs = require('fs') | |
| const filename = process.argv[2]; | |
| const lastPhraseIncipit = 'we offer this book.' | |
| const firstPhraseEnd = 'STAYING STOIC' | |
| const content = fs.readFileSync(filename) | |
| .toString() | |
| .split(lastPhraseIncipit)[1] | |
| .split(firstPhraseEnd)[0] | |
| .split(/\s{3,}/) | |
| .filter(String) | |
| const months = ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'] | |
| const toNormalCase = (str) => str[0].toUpperCase() + str.toLowerCase().slice(1) | |
| const { result } = content.reduce((acc, token) => { | |
| if (acc.next === 'text-or-date') { | |
| if (months.includes(token)) { | |
| return { ...acc, next: 'section' } | |
| } | |
| const words = token.split(' ') | |
| if (months.includes(words[0].toUpperCase()) && words.length === 2) { | |
| return { ...acc, next: 'title', current: token, result: { ...acc.result, [token]: { text: [], section: toNormalCase(acc.section), section_uppercase: acc.section.toUpperCase() } } } | |
| } | |
| return { ...acc, next: 'text-or-date', result: { ...acc.result, [acc.current]: { ...acc.result[acc.current], text: acc.result[acc.current].text.concat(token) } } } | |
| } | |
| if (acc.next === 'section') { | |
| return { ...acc, next: 'text-or-date', section: token } | |
| } | |
| if (acc.next === 'title') { | |
| return { ...acc, next: 'quote', result: { ...acc.result, [acc.current]: { ...acc.result[acc.current], title: toNormalCase(token), title_uppercase: token.toUpperCase() } } } | |
| } | |
| if (acc.next === 'quote') { | |
| return { ...acc, next: 'author', result: { ...acc.result, [acc.current]: { ...acc.result[acc.current], quote: token } } } | |
| } | |
| if (acc.next === 'author') { | |
| return { ...acc, next: 'text-or-date', result: { ...acc.result, [acc.current]: { ...acc.result[acc.current], author: token } } } | |
| } | |
| }, { result: {}, next: 'text-or-date' }) | |
| console.log(JSON.stringify(result, null, '\t')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment