Skip to content

Instantly share code, notes, and snippets.

@AnimaWish
Last active December 15, 2015 15:39
Show Gist options
  • Save AnimaWish/5283738 to your computer and use it in GitHub Desktop.
Save AnimaWish/5283738 to your computer and use it in GitHub Desktop.
# good UI
# more sorting options
# detect downloads, give shows update prompt - make a daemon? how do i do that
# saving/loading - use yaml
# groups/genres?
# priority?
# import from rtf
# {Show => [[Seasons, Episodes], Complete?, Notes]}
require "yaml"
#file = File.open("/Users/Caius/Documents/Notes/series.yaml", "w")
#file = YAML::load("/Users/Caius/Documents/Notes/series.yaml")
file = YAML.load(File.open("/Users/Caius/Documents/Notes/series.yaml"))
$series = Hash.new()
def addseries(title)
if title == ''
puts "Error: No title entered."
elsif $series.key?(title) == false
$series[title] = [[0,0], false, '']
else
puts "Error: Series already exists in list."
end
end
def removeseries(title)
puts "Are you sure you want to remove _#{title}_? (Yes/No)"
print ">"
response = gets.chomp
if response == "Yes"
deletion = true
$series.delete(title) {|title| puts "Error: '#{title}' not found."; deletion = false}
puts "Series _#{title}_ was deleted." if deletion
end
end
def displayseries(solo, title)
displaytitle = title
#titlevariable = 1
unless solo #truncates display if title is too long
#titlevariable = -22
if title.length > 18 #(-1 * titlevariable)
displaytitle = title[0..14] + '...'
end
end
if $series[title][1] #completion
completedisplay = 'x'
end
if $series[title][0][1] == 0
episode = ''
else
episode = '.' + $series[title][0][1].to_s
end
printf "%#-18s - %2s%-3s[%1s] %s \n", displaytitle, $series[title][0][0], episode, completedisplay, $series[title][2]
end
def list(argument)
puts "__Series List__"
if argument.include? 'e'
puts "Title - S#.E#[x] Notes"
end
$series.sort_by {|title, seasonEpisode, complete, notes| title.downcase}.each do |x|
if argument.include? "-x"
unless x[1][1]
displayseries(false, x[0])
end
elsif argument.include? "+x"
if x[1][1]
displayseries(false, x[0])
end
else
displayseries(false, x[0])
end
end
end
def find(title)
found = $series.select{|key, value| key.downcase =~ /#{title.downcase}/}
solostatus = false
if found.count == 1
solostatus = true
end
$findcounty = found.count
found.each do |x|
displayseries(solostatus, x[0])
$lasttitle = x[0]
end
end
def updateseries(title, editTitle)
find(title)
if $findcounty > 1
puts "Error: Multiple matches found."
elsif $findcounty == 0
puts "Error: No matches found."
elsif $findcounty == 1
if editTitle
puts "Editing title of _#{$lasttitle}_"
print ">"
input = gets.chomp
$series[input] = $series[$lasttitle]
$series.delete($lasttitle)
puts "Title _#{$lasttitle}_ was changed to _#{input}_"
else
puts "Editing data for _#{$lasttitle}_, [S#].[E#][x/o]; notes"
puts "ex: 2.0x; Shinigami like apples."
print ">"
input = gets.chomp
inputarray = input.split(';')
season = inputarray[0].split('.')[0]
episode = inputarray[0].split('.')[1]
if inputarray[0].include? 'x' #if there's an x, completion is true, and removes the x
completion = true
inputarray[0].delete!('x')
elsif inputarray[0].include? 'o' #if there's an o, completion is false, removes the o
completion = false
inputarray[0].delete!('o')
elsif $series[$lasttitle][1] #if there isn't a character but it was true before, it's true now
completion = true
else
completion = false
end
unless inputarray[1] == nil
notes = inputarray[1].strip #if there are notes, here they are
else
notes = $series[$lasttitle][2] #otherwise, use old notes
end
if season == "" #if season isn't given, use old season
season = $series[$lasttitle][0][0]
end
if episode == nil #if episode isn't given, use old episode
episode = $series[$lasttitle][0][1]
end
$series[$lasttitle] = [[season.to_i, episode.to_i], completion, notes]
puts "Data for _#{$lasttitle}_ was edited."
end
end
end
def help()
puts "__Available Commands__"
puts "ls(+x/-x,e) List all shows alphabetically (Show/hide completed series, show example)."
puts "+seriestitle Add a series to the list."
puts "--seriestitle Remove a series from the list. This cannot be undone."
puts "*seriestitle Update stored information for a series."
puts "=seriestitle Edit a series title."
puts "/seriestitle Search the series list."
puts "quit Exit program."
end
addseries('House of Cards')
addseries('Game of Thrones')
addseries('Regular Show')
addseries('Tengen Toppa Gurren Lagann')
puts "Television Series Sorter"
loop do
print ">"
input = gets.chomp
case input
when /ls(.*)/
list($1.strip)
when /\+(.*)/
addseries($1.strip)
when /\-\-(.*)/
removeseries($1.strip)
when /\*(.*)/
updateseries($1.strip, false)
when /\=(.*)/
updateseries($1.strip, true)
when /\/(.*)/
find($1.strip)
when 'help'
help()
when 'quit'
puts "Save Changes? (y/n)"
input = gets.chomp
if input == "y"
file.puts YAML::dump($series) #this needs more
#file.dump($series)
break
elsif input == "n"
break
else
puts "Error: Input not understood."
end
end
end
puts $series
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment