Commits

Jason Moiron committed 70a0b21

add remove for watchlist

  • Participants
  • Parent commits a0a2a6e

Comments (0)

Files changed (3)

 	tx.Commit()
 }
 
+func (w *Watchlist) Remove(name string) {
+	w.Load()
+	tx := Begin(config.db)
+	Exec(tx, "delete from watchlist where name=?;", name)
+	tx.Commit()
+}
+
 func (w *Watchlist) Set(name string, number string) error {
 	w.Load()
 	tx := Begin(config.db)
 
 func FileExtension(str string) string {
 	spl := strings.Split(str, ".")
-	return spl[len(spl)-1]
+	ext := spl[len(spl)-1]
+	ext = strings.Split(ext, "?")[0]
+	return ext
 }
 
 func tick() { fmt.Printf("%s\n", time.Now().String()) }
 		return
 	}
 
+	if opts.Remove {
+		RemoveWatchlist(optarg.Remainder...)
+		return
+	}
+
 	if opts.Set {
 		if len(optarg.Remainder) < 2 {
 			fmt.Printf("--set requires a name and a number.\n")
 	w.Add(match.Name)
 }
 
+func RemoveWatchlist(terms ...string) {
+	term := strings.Join(terms, " ")
+	w := new(Watchlist)
+
+	series, err := FindOneSeries(true, term)
+	if err != nil {
+		return
+	}
+	if len(series) == 0 {
+		fmt.Printf("No series found matching term %s\n", Yellow(term, true))
+		return
+	}
+	if len(series) > 1 {
+		e := fmt.Sprintf("Found %d series matching term %s:\n", len(series), Yellow(term, true))
+		for _, s := range series {
+			e += fmt.Sprintf(" * %s (%s)\n", s.Name, s.Site)
+		}
+		fmt.Printf(e)
+		return
+	}
+
+	match := series[0]
+	fmt.Printf("Removing series %s\n", Yellow(match.Name, true))
+	w.Remove(match.Name)
+}
+
 func SetWatchlist(name string, number string) {
 	w := new(Watchlist)
 	err := w.Set(name, number)