jared 0.0.5 → 0.0.7a1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,114 @@
1
+ class Helpers
2
+ # Opens a Green Shoes app to manage tasks.
3
+ def self.task
4
+ Lib.db
5
+ require "green_shoes"
6
+ Shoes.app title: "Jared Tasks" do
7
+ title "Tasks"
8
+ button "add task" do
9
+ Shoes.app title: "Add Task", width: 250, height: 400 do
10
+ title "add task"
11
+ stack do
12
+ para "Task title:"
13
+ @title = edit_line text: ""
14
+ para "Task desciption:"
15
+ @desciption = edit_box text: ""
16
+ para "Task due date:"
17
+ @due = edit_line text: ""
18
+ button "Add Task" do
19
+ new_task = Task.new(:title => @title.text, :desciption => @desciption.text, :due => Chronic.parse(@due.text))
20
+ new_task.save!
21
+ if new_task
22
+ alert "added task"
23
+ close
24
+ else
25
+ alert "failed to add task. Make sure you use a unique title."
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ button "Refresh" do
33
+ $tasks_s.clear do
34
+ $tasks_s = stack do
35
+ task = Task.find(:all)
36
+ task.each do |t|
37
+ tagline t.title
38
+ para t.desciption
39
+ puts t.due.to_s
40
+ puts Time.new(t.due.to_s)
41
+ para "Due: " + Time.new(t.due.to_s).strftime("%B %d %Y")
42
+ flow do
43
+ button "Edit", state: "nil" do
44
+ Shoes.app title: "Editing Task: #{t.title}", width: 250, height: 400 do
45
+ title "edit task"
46
+ stack do
47
+ para "Task title:"
48
+ @title = edit_line text: "#{t.title}"
49
+ para "Task desciption:"
50
+ @desciption = edit_box text: "#{t.desciption}"
51
+ para "Task due date:"
52
+ @due = edit_line text: "#{Time.new(t.due.to_s).strftime("%B %d %Y")}"
53
+ button "update Task" do
54
+ task = Task.find(t.id)
55
+ @edit_task = task.update_attributes(:title => @title.text, :desciption => @desciption.text, :due => Chronic.parse(@due.text))
56
+ close
57
+ end
58
+ end
59
+ end
60
+ end
61
+ button "Delete" do
62
+ delete = confirm "Deleting... Are you sure?"
63
+ if delete == true
64
+ Task.destroy(t.id)
65
+ alert "removed #{t.title}"
66
+ end
67
+ end
68
+ para
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ task = Task.find(:all)
76
+ $tasks_s = stack do
77
+ task.each do |t|
78
+ tagline t.title
79
+ para t.desciption
80
+ para "Due: #{Time.new(t.due.to_s).strftime("%B %d %Y")}"
81
+ flow do
82
+ button "Edit", state: "nil" do
83
+ Shoes.app title: "Editing Task: #{t.title}", width: 250, height: 400 do
84
+ title "edit task"
85
+ stack do
86
+ para "Task title:"
87
+ @title = edit_line text: "#{t.title}"
88
+ para "Task desciption:"
89
+ @desciption = edit_box text: "#{t.desciption}"
90
+ para "Task due date:"
91
+ @due = edit_line text: "#{Time.new(t.due.to_s).strftime("%B %d %Y")}"
92
+ button "update Task" do
93
+ task = Task.find(t.id)
94
+ @edit_task = task.update_attributes(:title => @title.text, :desciption => @desciption.text, :due => Chronic.parse(@due.text))
95
+ close
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ button "Delete" do
102
+ delete = confirm "Deleting... Are you sure?"
103
+ if delete == true
104
+ Task.destroy(t.id)
105
+ alert "removed #{t.title}"
106
+ end
107
+ end
108
+ para
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,74 @@
1
+ if Time.now.strftime("%a") == "Sun"
2
+ $day = "Mon"
3
+ $dn = "Monday"
4
+ elsif Time.now.strftime("%a") == "Mon"
5
+ $day = "Tue"
6
+ $dn = "Tuesday"
7
+ elsif Time.now.strftime("%a") == "Tue"
8
+ $day = "Wed"
9
+ $dn = "Wednesday"
10
+ elsif Time.now.strftime("%a") == "Wed"
11
+ $day = "Thu"
12
+ $dn = "Thursday"
13
+ elsif Time.now.strftime("%a") == "Thu"
14
+ $day = "Fri"
15
+ $dn = "Friday"
16
+ elsif Time.now.strftime("%a") == "Fri"
17
+ $day = "Sat"
18
+ $dn = "Saturday"
19
+ elsif Time.now.strftime("%a") == "Sat"
20
+ $day = "Sun"
21
+ $dn = "Sunday"
22
+ end
23
+
24
+ class Helpers
25
+ Lib.db
26
+ require_relative "../models/user.rb"
27
+ @user = User.first
28
+ # Checks weather.
29
+ #
30
+ # Usage: <em>jared weather (10001/today/tomorrow/forecast)</em>
31
+ def self.weather(option=nil)
32
+ begin
33
+ weather = GoogleWeather.new(@user.zip)
34
+
35
+ if option == nil
36
+ forecast = weather.current_conditions
37
+ puts weather.forecast_information.city + "."
38
+ puts forecast.temp_f + " Degrees Fahrenheit.", forecast.temp_c + " Degrees Celsius.", forecast.condition + ".", forecast.wind_condition + ".", forecast.humidity + "."
39
+
40
+ elsif option == "today"
41
+ weather.forecast_conditions.each do |condition|
42
+ if condition.day_of_week == Time.now.strftime("%a")
43
+ puts Time.now.strftime("%A")
44
+ puts " #{condition.condition}."
45
+ puts " High: #{condition.high} Degrees Fahrenheit."
46
+ puts " Low: #{condition.low} Degrees Fahrenheit."
47
+ end
48
+ end
49
+
50
+ elsif option == "tomorrow"
51
+ weather.forecast_conditions.each do |condition|
52
+ if condition.day_of_week == $day
53
+ puts $dn
54
+ puts " #{condition.condition}."
55
+ puts " High: #{condition.high} Degrees Fahrenheit."
56
+ puts " Low: #{condition.low} Degrees Fahrenheit."
57
+ end
58
+ end
59
+
60
+ elsif option == "forecast"
61
+ weather.forecast_conditions.each do |condition|
62
+ puts "#{condition.day_of_week}."
63
+ puts " #{condition.condition}."
64
+ puts " High: #{condition.high} Degrees Fahrenheit."
65
+ puts " Low: #{condition.low} Degrees Fahrenheit."
66
+ end
67
+ else
68
+ puts "Unable to fetch weather due to argument error."
69
+ end
70
+ rescue SocketError
71
+ puts "A connection error occurred fetching weather information."
72
+ end
73
+ end
74
+ end
data/lib/jared/jared.rb CHANGED
@@ -1,130 +1,140 @@
1
- require "rubygems"
2
- require 'commandable'
3
- require 'fileutils'
4
- require "yaml"
5
- #require "jared/version.rb"
6
- require "jared/helpers.rb"
7
-
8
- class Jared
9
- extend Commandable
10
- config = YAML.load_file("#{Helper.gem_root}/lib/config.yml")
11
- if config['color'] == "false"
12
- Commandable.color_output = false
13
- else
14
- Commandable.color_output = true
15
- end
16
- Commandable.verbose_parameters = false
17
- Commandable.app_exe = "Jared, Your Ruby powered Digital Assistant (RDA)"
18
-
19
- command "have jared say hi to you"
20
- # Have jared say hi to you
21
- def hi
22
- config = YAML.load_file("#{Helper.gem_root}/lib/config.yml")
23
- if config['name'] == nil
24
- puts Helper.say "Hello #{Etc.getlogin.capitalize},"
25
- else
26
- puts Helper.say "Hello #{config['name']},"
27
- end
28
- puts Helper.say " I'm Jared.\n Just call me your Ruby powered Digital Assistant or RDA.\nAsk me to do something by typing: jared command"
29
- end
30
-
31
-
32
- command "Install ruby gems. 'install jared_talk' installs festivaltts4r, ' install <name>'"
33
- # Install ruby gems. 'install jared_talk' installs festivaltts4r, ' install <name>'
34
- def install(gem)
35
- if gem.include? ("ror")
36
- puts Helper.say "Installing gem: rails"
37
- system("gem install rails")
38
- puts Helper.say "Installed gem: rails"
39
- elsif gem.include? ("jared_talk")
40
- puts Helper.say "Installing gem: Festival tts4r"
41
- system("gem install festivaltts4r")
42
- puts Helper.say "Installed gem: Festival tts4r"
43
- else
44
- puts Helper.say "Installing gem: #{gem}"
45
- system("gem install #{gem}")
46
- puts Helper.say "Installed gem: #{gem}"
47
- end
48
- end
49
-
50
-
51
- command "Tell the current time, 'time now/month/day/date/year'"
52
- # Tell the current time, 'time now/month/day/date/year'
53
- def time(time)
54
- if time.include? ("now")
55
- puts Helper.say "current time is: " + Helper.get_time
56
- elsif time.include? ("month")
57
- puts Helper.say "current month is: " + Helper.get_month
58
- elsif time.include? ("day")
59
- puts Helper.say "current day is: " + Helper.get_day
60
- elsif time.include? ("date")
61
- puts Helper.say "current date is: " + Helper.get_date
62
- elsif time.include? ("year")
63
- puts Helper.say "current year is: " + Helper.get_year
64
- else
65
- Helper.error
66
- end
67
- end
68
-
69
-
70
- command "create a new file or folder and names it, 'jared create dir/folder/file/rails blog'"
71
- # Create a new file or directory and names it, 'jared create dir/file/rails blog'
72
- def create(type, name)
73
- if type.include? ("folder")
74
- Helper.create_dir "#{name}"
75
- elsif type.include? ("dir")
76
- Helper.create_dir "#{name}"
77
- elsif type.include? ("rails")
78
- begin
79
- require "rails"
80
- system("rails new #{name}")
81
- puts Helper.say "Your new Rails app is ready"
82
- rescue LoadError
83
- puts Helper.say "Ruby on rails is not installed. install it with, 'jared install rails'"
84
- end
85
- elsif type.include? ("file")
86
- File.open("#{name}", 'w') do |file|
87
- if name.include? (".html")
88
- file.puts Helper.html
89
- end
90
- Helper.create_file name
91
- end
92
- else
93
- puts "#{Helper.error}"
94
- end
95
- end
96
-
97
-
98
- command "clones the requested repo 'git <url> <name(optional)>'"
99
- # Clones the requested repo 'git <url> <name(optional)>'
100
- def git(url, name = nil)
101
- if name == nil
102
- system("git clone #{url}")
103
- puts Helper.say "Git is cloning #{url}"
104
- else
105
- system("git clone #{url} #{name}")
106
- puts Helper.say "Git is cloning #{url} into #{name}"
107
- end
108
- end
109
-
110
-
111
- command "have jared say something 'say enter text wish spoken here.'"
112
- #
113
- def say(say = "proper command is, 'jared say 'text''")
114
- puts Helper.say say
115
- end
116
-
117
-
118
- command "Configure Jared 'jared config <your name> <talk 'true/false'> <help text color 'true/false'>'"
119
- # Configure Jared 'jared config <your name>'
120
- def config(name, talk, color)
121
- @yml = {"name" => "#{name}", "talk" => "#{talk}", "color" => "#{color}"}
122
- File.open("#{Helper.gem_root}/lib/config.yml", "w+") do |config|
123
- config.puts YAML::dump(@yml)
124
- end
125
- puts Helper.say "name is now set to #{name}"
126
- puts Helper.say "I will talk: #{talk}"
127
- puts Helper.say "Help color is: #{color}"
128
- end
129
- end
130
- Commandable.execute(ARGV)
1
+ require 'thor'
2
+
3
+ class Jared < Thor
4
+ default_task :hi
5
+
6
+ desc "hi", "Dynamic greeting based on the current time."
7
+ def hi
8
+ require_relative 'helpers/greeting.rb'
9
+ Helpers.greeting
10
+ end
11
+
12
+ desc "time", "Gets the current time."
13
+ def time
14
+ puts "#{Time.now.strftime("%I:%M:%S%P")}"
15
+ end
16
+
17
+ desc "weather [FORECAST]", "Gets weather information, If no argument then returns current weather information."
18
+ def weather(option=nil)
19
+ require_relative 'helpers/weather.rb'
20
+ require 'google_weather'
21
+ Helpers.weather(option)
22
+ end
23
+
24
+ desc "clock", "Open a Green Shoes powered clock."
25
+ def clock
26
+ require_relative 'helpers/clock.rb'
27
+ require 'green_shoes'
28
+ Helpers.clock
29
+ end
30
+
31
+ desc "create TYPE NAME", "create"
32
+ def create(type,name)
33
+ require_relative 'helpers/create.rb'
34
+ Helpers.create
35
+ end
36
+
37
+ desc "whereis PLACE", "Finds PLACE via Google Maps"
38
+ def whereis(place)
39
+ require_relative 'helpers/map.rb'
40
+ require 'launchy'
41
+ Helpers.map(place)
42
+ end
43
+
44
+ desc "day", "Displays the current day"
45
+ def day
46
+ puts Time.now.strftime("%A")
47
+ end
48
+
49
+ desc "whatis WORD", "Looks up the meaning of WORD."
50
+ def whatis(word)
51
+ require_relative 'helpers/define.rb'
52
+ Helpers.define(word)
53
+ end
54
+
55
+ desc "deamon MAIL/TASK/CAL", "Checks every minute for new mail/tasks/appointments."
56
+ def deamon(function=nil)
57
+ require_relative 'helpers/deamon.rb'
58
+ require 'gmail'
59
+ require 'gibberish'
60
+ Helpers.deamon
61
+ end
62
+
63
+ desc "jamendo MODE", "Plays music from Jamendo."
64
+ def jamendo(mode='once')
65
+ require_relative 'helpers/jamendo.rb'
66
+ at_exit do
67
+ require_relative 'lib.rb'
68
+ Lib.db
69
+ @jared = Info.first
70
+ @jared.update_attributes(:author_url => "", :music_url => "", :album_image => "", :album_url => "", :now_playing => "", :now_playing_author => "", :now_playing_album => "")
71
+ end
72
+ Helpers.jamendo(mode)
73
+ end
74
+
75
+ desc "play FILE", "Plays File, local or remote."
76
+ def play(media='')
77
+ require_relative 'helpers/player.rb'
78
+ Helpers.play(media)
79
+ end
80
+
81
+ desc "task", "Manage your Tasks"
82
+ def task
83
+ #require 'green_shoes'
84
+ #require 'chronic'
85
+ puts "Task is not yet available."
86
+ #Helpers.task
87
+ end
88
+
89
+ desc "config", "Configure Jared."
90
+ def config
91
+ require_relative 'helpers/config.rb'
92
+ require 'green_shoes'
93
+ require 'gibberish'
94
+ Helpers.config
95
+ end
96
+
97
+ desc "view FILENAME", "View file.png in system viewer."
98
+ def view(filename)
99
+ require 'sys/uname'
100
+ include Sys
101
+ if Uname.sysname.include?("Linux")
102
+ puts "Opening #{filename}"
103
+ system("xdg-open #{Dir.pwd}/#{filename}")
104
+ elsif Uname.sysname.include?("Windows")
105
+ puts "Opening #{filename}"
106
+ system("call \"#{Dir.pwd}/#{filename}\"")
107
+ else
108
+ puts "Your system is not supported."
109
+ end
110
+ end
111
+
112
+ desc "date", "Gets the current date."
113
+ def date
114
+ require_relative 'helpers/date.rb'
115
+ Helpers.date
116
+ end
117
+
118
+ desc "cal", "Calendar"
119
+ def cal
120
+ puts "Calendar is not yet available."
121
+ #require 'green_shoes'
122
+ #Helpers.cal
123
+ end
124
+
125
+ desc "mail", "Checks your mailbox for new mails."
126
+ def mail
127
+ require_relative 'helpers/mail.rb'
128
+ require 'gmail'
129
+ require 'gibberish'
130
+ Helpers.mail
131
+ end
132
+
133
+ desc "stock SYMBOL MODE", "Check semi-current stock data."
134
+ def stock(s,m='last')
135
+ require_relative 'helpers/stock.rb'
136
+ Helpers.stock(s,m)
137
+ end
138
+ end
139
+
140
+ Jared.start
data/lib/jared/lib.rb ADDED
@@ -0,0 +1,13 @@
1
+ # Lib file loads all Helpers and Models.
2
+
3
+ class Lib
4
+ # ActiveRecord DataBase connect
5
+ def self.db
6
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{Dir.home}/.jared.sqlite3")
7
+ end
8
+ end
9
+
10
+ # Model files requires
11
+ require_relative 'models/info.rb'
12
+ require_relative 'models/task.rb'
13
+ require_relative 'models/user.rb'
@@ -0,0 +1,2 @@
1
+ class Info < ActiveRecord::Base
2
+ end
@@ -0,0 +1,5 @@
1
+ class Task < ActiveRecord::Base
2
+ validates_presence_of :title, :desciption
3
+ validates_uniqueness_of :title
4
+ default_scope :order => 'created_at DESC'
5
+ end
@@ -0,0 +1,5 @@
1
+ class User < ActiveRecord::Base
2
+ validates_presence_of :name, :zip
3
+ validates_length_of :zip, :minimum=>5, :maximum=>5
4
+ default_scope :order => 'created_at DESC'
5
+ end
data/lib/jared/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Jared
2
- VERSION = "0.0.3"
3
- end
1
+ module Jared
2
+ VERSION = "0.0.7a1"
3
+ end
data/lib/jared.rb ADDED
@@ -0,0 +1,75 @@
1
+ #!/bin/ruby
2
+ require "faster_require"
3
+ require 'etc'
4
+ require "fileutils"
5
+ require 'sqlite3'
6
+ require 'active_record'
7
+
8
+ unless File.exist?("#{Dir.home}/.jared.sqlite3")
9
+ puts "Setting up database."
10
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{Dir.home}/.jared.sqlite3")
11
+ ActiveRecord::Migration.verbose = false
12
+
13
+ ActiveRecord::Schema.define do
14
+ create_table :tasks do |t|
15
+ t.column :title, :string
16
+ t.column :desciption, :string
17
+ t.column :due, :datetime
18
+ t.timestamps
19
+ end
20
+ end
21
+
22
+ ActiveRecord::Schema.define do
23
+ create_table :infos do |t|
24
+ t.column :status, :string
25
+ t.column :now_playing, :string
26
+ t.column :now_playing_album, :string
27
+ t.column :album_image, :string
28
+ t.column :now_playing_author, :string
29
+ t.column :author_url, :string
30
+ t.column :music_url, :string
31
+ t.column :album_url, :string
32
+ t.timestamps
33
+ end
34
+ end
35
+
36
+ ActiveRecord::Schema.define do
37
+ create_table :users do |t|
38
+ t.column :name, :string
39
+ t.column :zip, :string
40
+ t.column :mail_username, :string
41
+ t.column :mail_password, :string
42
+ t.column :mail_provider, :string
43
+ t.column :music, :string
44
+ t.timestamps
45
+ end
46
+ end
47
+ end
48
+
49
+ require_relative "jared/lib.rb"
50
+ #require "jared/lib"
51
+ Lib.db
52
+ if User.first.blank?
53
+ require 'green_shoes'
54
+ new_user = User.new(:name => "#{Etc.getlogin}", :zip => "10001", :music => 'classical')
55
+ new_user.save
56
+ c=confirm "Setup Jared?"
57
+ if c == true
58
+ Helpers.config
59
+ else
60
+ alert "Run: 'jared config' to setup later."
61
+ end
62
+ end
63
+
64
+ if Info.first.blank?
65
+ require 'green_shoes'
66
+ jrd = Info.new(:status => "Ready", :now_playing => "", :now_playing_author => "")
67
+ jrd.save
68
+ if jrd
69
+ puts 'Ready.'
70
+ else
71
+ puts 'Failed to create Info!'
72
+ end
73
+ end
74
+
75
+ require_relative "jared/jared.rb"
data/readme.md CHANGED
@@ -1,2 +1,87 @@
1
- # Jared
2
- A Ruby powered Digital Assistant (RDA)
1
+ # Jared - Ruby Powered Digital Assistant (RDA)
2
+ ## What is Jared?
3
+ Jared's goal is to be a reality of Jarvis from the film, Ironman.
4
+
5
+ However, thats a **long** ways down the road, starting Jared small and working slowly up to the end goal of a voice-activated house control A.I.
6
+ ## Install Jared
7
+ You can get the lasest stable release on RubyGems via *gem install jared*
8
+
9
+ ## Usage
10
+
11
+ ### Clock
12
+ Opens a digital clock in a Green Shoes app.
13
+
14
+ Usage: jared clock
15
+
16
+ ### Cal
17
+ <span style="color:red;">Not yet implemented.</span>
18
+
19
+ Manage your appointments.
20
+
21
+ Usage: jared cal
22
+
23
+ ### Day
24
+ Puts current day.
25
+
26
+ Usage: Jared day
27
+
28
+ Tuesday
29
+
30
+ ### Deamon
31
+ Run mail/task/appointment check every 60 seconds.
32
+
33
+ Usage: jared deamon (mail/task/cal(endar))
34
+
35
+ (if there is no second argument it'll check all three every 60 seconds.)
36
+
37
+ ### Date
38
+ Puts the current date.
39
+
40
+ Usage: jared date
41
+
42
+ Wednesday the 22nd of February 2012
43
+
44
+ (02/22/2012)
45
+
46
+ ### Mail
47
+ Checks Gmail for new mails.
48
+
49
+ Usage: jared mail
50
+
51
+ ### Task
52
+ Manage your tasks.
53
+
54
+ Opens a Green Shoes window for managing Tasks.
55
+
56
+ Usage: jared task
57
+
58
+ ### Time
59
+ puts the current time
60
+
61
+ Usage: jared time
62
+
63
+ 05:21 am
64
+
65
+ ### Weather
66
+ Check you local weather information.
67
+
68
+ Usage: jared weather (today/tomorrow/forecast)
69
+
70
+ ### Whatis
71
+ <span style="color:red;">Not yet implemented.</span>
72
+
73
+ Google's the definition of the word.
74
+
75
+ Usage: jared whatis glass
76
+
77
+ ### Whereis
78
+ Opens Gmaps in default browser.
79
+
80
+ Usage: jared whereis
81
+
82
+ Search Gmaps for > Walmart
83
+
84
+ ### View
85
+ Opens the file in the system viewer.
86
+
87
+ Usage: jared view jared.rb