1.3.1: More reliable handling of refresh tokens
This commit is contained in:
parent
128a0e4862
commit
caf580779a
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "1.3.0"
|
||||
version = "1.3.1"
|
||||
author = "Adam Blažek"
|
||||
description = "CLI client for Bakaláři"
|
||||
license = "GPL-3.0"
|
||||
|
|
75
src/bk.nim
75
src/bk.nim
|
@ -40,6 +40,15 @@ proc saveConfig(configFile = defaultConfigFile, config: Config) =
|
|||
stderr.writeLine "Error: Can't write the config file."
|
||||
quit QuitFailure
|
||||
|
||||
template withBakalari(configFile: string, body: untyped): untyped =
|
||||
var config = configFile.loadConfig
|
||||
let bakalari {.inject.} = newBakalari(config.website.parseUri, config.refreshToken)
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
config.refreshToken = bakalari.refreshToken
|
||||
configFile.saveConfig(config)
|
||||
|
||||
proc signin(
|
||||
website: string,
|
||||
username: string,
|
||||
|
@ -60,16 +69,13 @@ proc homework(
|
|||
configFile = defaultConfigFile,
|
||||
) =
|
||||
## display the list of homework
|
||||
var config = configFile.loadConfig
|
||||
let bakalari = newBakalari(config.website.parseUri, config.refreshToken)
|
||||
config.refreshToken = bakalari.refreshToken
|
||||
configFile.saveConfig(config)
|
||||
for homework in baka.homework(bakalari):
|
||||
stdout.writeLine "----------------------------------------------------------------".fgLightGray
|
||||
stdout.writeLine (homework.startTime.format("yyyy-MM-dd") & " / " & homework.endTime.format("yyyy-MM-dd")).fgLightCyan
|
||||
stdout.writeLine homework.subject.fgLightYellow
|
||||
stdout.writeLine homework.teacher.fgLightMagenta
|
||||
stdout.writeLine homework.content
|
||||
withBakalari(configFile):
|
||||
for homework in baka.homework(bakalari):
|
||||
stdout.writeLine "----------------------------------------------------------------".fgLightGray
|
||||
stdout.writeLine (homework.startTime.format("yyyy-MM-dd") & " / " & homework.endTime.format("yyyy-MM-dd")).fgLightCyan
|
||||
stdout.writeLine homework.subject.fgLightYellow
|
||||
stdout.writeLine homework.teacher.fgLightMagenta
|
||||
stdout.writeLine homework.content
|
||||
|
||||
proc timetable(
|
||||
configFile = defaultConfigFile,
|
||||
|
@ -87,32 +93,29 @@ proc timetable(
|
|||
quit QuitFailure
|
||||
else:
|
||||
nextWeek ? (now() + 1.weeks) ! now()
|
||||
var config = configFile.loadConfig
|
||||
let bakalari = newBakalari(config.website.parseUri, config.refreshToken)
|
||||
config.refreshToken = bakalari.refreshToken
|
||||
configFile.saveConfig(config)
|
||||
let timetable = baka.timetable(bakalari, permanent, some(date))
|
||||
for day in timetable.days:
|
||||
if oneDay:
|
||||
if date.format("yyyyMMdd") != day.date.format("yyyyMMdd"):
|
||||
continue
|
||||
stdout.writeLine dayNames[day.dayOfWeek] & " " & day.date.format("yyyy-MM-dd")
|
||||
for lesson in day.lessons:
|
||||
var line = ""
|
||||
line &= lesson.hour.number
|
||||
line &= ". "
|
||||
line &= lesson.hour.beginTime.align(5, '0'.Rune).fgLightCyan
|
||||
line &= "-".fgLightCyan
|
||||
line &= lesson.hour.endTime.align(5, '0'.Rune).fgLightCyan
|
||||
line &= " "
|
||||
line &= lesson.subject.abbrev.align(4).fgLightYellow
|
||||
line &= " "
|
||||
line &= lesson.teacher.abbrev.align(4).fgLightMagenta
|
||||
line &= " "
|
||||
line &= lesson.room.abbrev.align(4).fgLightGreen
|
||||
stdout.writeLine line
|
||||
if lesson.change.isSome:
|
||||
stdout.writeLine ("^ " & lesson.change.unsafeGet.fgLightRed).fgLightRed
|
||||
withBakalari(configFile):
|
||||
let timetable = baka.timetable(bakalari, permanent, some(date))
|
||||
for day in timetable.days:
|
||||
if oneDay:
|
||||
if date.format("yyyyMMdd") != day.date.format("yyyyMMdd"):
|
||||
continue
|
||||
stdout.writeLine dayNames[day.dayOfWeek] & " " & day.date.format("yyyy-MM-dd")
|
||||
for lesson in day.lessons:
|
||||
var line = ""
|
||||
line &= lesson.hour.number
|
||||
line &= ". "
|
||||
line &= lesson.hour.beginTime.align(5, '0'.Rune).fgLightCyan
|
||||
line &= "-".fgLightCyan
|
||||
line &= lesson.hour.endTime.align(5, '0'.Rune).fgLightCyan
|
||||
line &= " "
|
||||
line &= lesson.subject.abbrev.align(4).fgLightYellow
|
||||
line &= " "
|
||||
line &= lesson.teacher.abbrev.align(4).fgLightMagenta
|
||||
line &= " "
|
||||
line &= lesson.room.abbrev.align(4).fgLightGreen
|
||||
stdout.writeLine line
|
||||
if lesson.change.isSome:
|
||||
stdout.writeLine ("^ " & lesson.change.unsafeGet.fgLightRed).fgLightRed
|
||||
|
||||
try:
|
||||
dispatchMulti(
|
||||
|
|
Loading…
Reference in New Issue