Skip to content
This repository has been archived by the owner on Mar 24, 2019. It is now read-only.

Commit

Permalink
Added --poll flag to grades command
Browse files Browse the repository at this point in the history
Now you can repeatedly check your grades without even having to refresh
Quest.
  • Loading branch information
Steven Xie committed Dec 27, 2018
1 parent d3752bb commit bc611b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uhhhhh quest web interface bad 😭 💯
- [x] Login and authentication
- [x] Check grades
- [x] Windows compatibility
- [x] Repeatedly poll for new grades
- [ ] Check schedule?
- [ ] Check course availability?
- [ ] ??? other stuff ???
Expand Down Expand Up @@ -60,7 +61,7 @@ If you're running `quest-cli` in the terminal, try out the following commands:

```bash
quest login # save Quest login to ~/.quest-cli.json (password is obfuscated)
quest grades # check your grades
quest grades # check your grades, repeatedly poll with the --poll flag
quest --help # see other options
```

Expand Down
22 changes: 17 additions & 5 deletions cmd/grades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/cheynewallace/tabby"
kingpin "gopkg.in/alecthomas/kingpin.v2"

"github.com/cheynewallace/tabby"
"github.com/manifoldco/promptui"

"github.com/stevenxie/uwquest"

"github.com/stevenxie/quest-cli/internal/interact"
"github.com/stevenxie/uwquest"
ess "github.com/unixpickle/essentials"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

func registerGradesCmd(app *kingpin.Application) {
Expand All @@ -25,21 +24,27 @@ func registerGradesCmd(app *kingpin.Application) {
// Register flags.
gradesCmd.Flag("term", "The name of the term to load grades for.").Short('t').
StringVar(&gradesOpts.Term)
gradesCmd.Flag("poll", "Poll for new grades every 30s.").Short('p').
BoolVar(&gradesOpts.Poll)
}

var (
gradesCmd *kingpin.CmdClause
gradesOpts struct {
Term string
Poll bool
}
)

const gradesPollDelay = 30 * time.Second

func grades() error {
c, err := interact.BuildClient()
if err != nil {
return err
}

check:
interact.Errln("Fetching terms...")
terms, err := c.Terms()
if err != nil {
Expand Down Expand Up @@ -114,5 +119,12 @@ func grades() error {
interact.Errln()
table.Print()
interact.Errln()

if gradesOpts.Poll {
gradesOpts.Term = target.Name
interact.Errln("Checking again in 30 seconds (press ctrl-c to stop).")
time.Sleep(gradesPollDelay)
goto check
}
return nil
}
14 changes: 13 additions & 1 deletion cmd/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"os"
"strings"

kingpin "gopkg.in/alecthomas/kingpin.v2"

"github.com/stevenxie/quest-cli/internal/interact"
ess "github.com/unixpickle/essentials"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

func registerInteractiveCmd(app *kingpin.Application) {
Expand Down Expand Up @@ -38,11 +39,18 @@ func interactive() error {

var err error
switch command {
// Information commands.
case gradesCmd.FullCommand():
err = grades()
case loginCmd.FullCommand():
err = login()

// Custom commands.
case "poll":
gradesOpts.Poll = true
err = grades()

// Other commands.
case "help":
interactiveHelp()
case "quit":
Expand Down Expand Up @@ -74,6 +82,10 @@ func interactiveHelp() {
}
entries = append(entries, HelpEntry{model.Name, model.Help})
}

// Add custom entries:
entries = append(entries, HelpEntry{"poll", "Poll grades repeatedly, every " +
"30s."})
entries = append(entries, HelpEntry{"quit", "Quit interactive mode."})

fmt.Println("Commands:")
Expand Down

0 comments on commit bc611b5

Please sign in to comment.