diff --git a/Gemfile b/Gemfile index 9ab4c01..e2769c7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source "http://rubygems.org" # Specify your gem's dependencies in jared.gemspec -gemspec +gemspec \ No newline at end of file diff --git a/jared.gemspec b/jared.gemspec index 2cf773b..7a99431 100644 --- a/jared.gemspec +++ b/jared.gemspec @@ -24,5 +24,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency "activerecord" s.add_runtime_dependency "sqlite3" s.add_runtime_dependency "launchy" - #s.add_runtime_dependency "wordnik" + s.add_runtime_dependency 'google-weather' + s.add_runtime_dependency 'gmail' end \ No newline at end of file diff --git a/lib/jared.rb b/lib/jared.rb index f885644..1ff79bf 100644 --- a/lib/jared.rb +++ b/lib/jared.rb @@ -1,18 +1,26 @@ +#!/bin/ruby + require 'etc' require "fileutils" require 'sys/uname' require 'launchy' require 'sqlite3' require 'active_record' +require 'google_weather' +require 'gmail' include Sys -#require_relative "jared/lib.rb" -require "jared/lib" -ActiveRecord::Base.establish_connection( - :adapter => 'sqlite3', - :database => "#{Dir.home}/.jared.sqlite3") +begin + require "green_shoes" +rescue LoadError + puts "Please install 'green_shoes' for more functionality" +end unless File.exist?("#{Dir.home}/.jared.sqlite3") +puts "Setting up database." +ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{Dir.home}/.jared.sqlite3") +ActiveRecord::Migration.verbose = false + ActiveRecord::Schema.define do create_table :tasks do |t| t.column :title, :string @@ -21,12 +29,29 @@ t.timestamps end end + + ActiveRecord::Schema.define do + create_table :users do |t| + t.column :name, :string + t.column :zip, :string + t.column :mail_username, :string + t.column :mail_password, :string + t.column :mail_provider, :string + t.timestamps + end + end end -begin - require "green_shoes" -rescue LoadError - puts "Please install 'green_shoes' for more functionality" +require_relative "jared/lib.rb" +#require "jared/lib" +if User.first.blank? + c=confirm "Setup Jared?" + if c == true + Helpers.config + sleep(3) + alert 'opening' + Helpers.config + end end class Jared @@ -61,7 +86,7 @@ def self.clock system("xdg-open #{Dir.pwd}/#{ARGV[1]}") elsif Uname.sysname.include?("Windows") puts "Opening #{ARGV[1]}" - system("\"#{Dir.pwd}/#{ARGV[1]}\"") + system("call \"#{Dir.pwd}/#{ARGV[1]}\"") else puts "Your system is not supported." end @@ -75,11 +100,12 @@ def self.clock when "date", "Date" Jared.date +when "config", "Config", "configure", "Configure" +Helpers.config + when "cal", "Cal", "calendar", "Calendar" puts "Calendar is not yet available." - if Dir.pwd.include?("/home/#{Etc.getlogin}/jared") Helpers.cal - end when "task", "Task" puts "Task is not yet available." @@ -89,7 +115,7 @@ def self.clock puts Time.now.strftime("%A") when "deamon", "Deamon" -puts "Deamon is not yet available." +#puts "Deamon is not yet available." Helpers.deamon when "time", "Time" @@ -107,6 +133,9 @@ def self.clock when "create", "Create" Helpers.create + +when "weather", "Weather" + Helpers.weather(ARGV[1]) else Helpers.notfound diff --git a/lib/jared/helpers/calendar.rb b/lib/jared/helpers/calendar.rb index a06079f..b7618c7 100644 --- a/lib/jared/helpers/calendar.rb +++ b/lib/jared/helpers/calendar.rb @@ -1,4 +1,7 @@ class Helpers +# == Calendar +# Not yet implemented. +# _jared_ _cal_ Manage your appointments in a Green Shoes app. def self.cal require "green_shoes" Shoes.app do diff --git a/lib/jared/helpers/clock.rb b/lib/jared/helpers/clock.rb index 533c12d..43acbbc 100644 --- a/lib/jared/helpers/clock.rb +++ b/lib/jared/helpers/clock.rb @@ -1,4 +1,6 @@ class Helpers +# == Clock +# _jared_ _clock_ Opens a digital clock in a Green Shoes app. def self.clock begin require "green_shoes" diff --git a/lib/jared/helpers/config.rb b/lib/jared/helpers/config.rb new file mode 100644 index 0000000..f4613e5 --- /dev/null +++ b/lib/jared/helpers/config.rb @@ -0,0 +1,41 @@ +class Helpers +Lib.db + + def self.config + Shoes.app title: "Jared - Configuration", height: 300, width: 500 do + background "#333".."#666" + tagline "Configure Jared to your person" + @user = User.first + if @user.blank? + button "Create profile" do + new_user = User.new(:name => "#{Etc.getlogin}", :zip => "00000") + new_user.save + if new_user + alert "Success. Rerun command `jared config` to continue." + close + else + alert "Failed. Retry." + end + end + else + para 'Your name:' + @name = edit_line "#{@user.name}" + para 'Your zipcode (For weather)' + @zip = edit_line "#{@user.zip}" + para 'Your Gmail email address (For email checking)' + @mail = edit_line "#{@user.mail_username}" + para 'Your Gmail password (Will be encrypted)' + @password = edit_line "#{@user.mail_password}", secret: true + button "Save" do + update_user = @user.update_attributes(:name => @name.text, :zip => @zip.text, :mail_username => @mail.text, :mail_password => @password.text) + if update_user == true + alert "Saved." + close + else + alert "failed to save." + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/jared/helpers/date.rb b/lib/jared/helpers/date.rb index 9f8cd19..c0bc041 100644 --- a/lib/jared/helpers/date.rb +++ b/lib/jared/helpers/date.rb @@ -1,5 +1,5 @@ class Helpers - # = Date and Time + # == Date and Time # _jared_ _time_ returns the current time. # #e.g. diff --git a/lib/jared/helpers/deamon.rb b/lib/jared/helpers/deamon.rb index 486b43c..dc86359 100644 --- a/lib/jared/helpers/deamon.rb +++ b/lib/jared/helpers/deamon.rb @@ -1,4 +1,44 @@ +# Deamon +# TODO: run every x minutes on Linux and Windows + +class Deamon + Lib.db + + def self.task + # TODO: Add tasks to deamon + puts "Jared Tasks" + puts "0 Tasks due today." + end + def self.appointment + # TODO: add appointments to deamon + puts "Jared Calendar" + puts "0 Appointments due today." + end + def self.message + # TODO: add messages(emails) to deamon + # limit to lastest 15 messages + @user = User.first + Gmail.connect(@user.mail_username, @user.mail_password) do |gmail| + puts "Google Mail" + puts gmail.inbox.count(:unread).to_s + " Unread messages." + gmail.inbox.emails(:unread).each do |email| + email.unread! + print "From:",email.sender[0].mailbox,"@", email.sender[0].host, ", Subject:",email.subject + puts + end + end + end +end + class Helpers def self.deamon - end -end \ No newline at end of file + loop do + Deamon.task + Deamon.appointment + Deamon.message + puts + puts + sleep(60) + end + end + end \ No newline at end of file diff --git a/lib/jared/helpers/task.rb b/lib/jared/helpers/task.rb index 727c612..f3abe48 100644 --- a/lib/jared/helpers/task.rb +++ b/lib/jared/helpers/task.rb @@ -1,10 +1,12 @@ class Helpers def self.task + Lib.db + ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => "#{Dir.home}/.jared.sqlite3") require "green_shoes" - require_relative "models/task.rb" + #require_relative "../models/task.rb" Shoes.app title: "Jared Tasks" do title "Tasks" button "add task" do diff --git a/lib/jared/helpers/weather.rb b/lib/jared/helpers/weather.rb new file mode 100644 index 0000000..ebce909 --- /dev/null +++ b/lib/jared/helpers/weather.rb @@ -0,0 +1,19 @@ +class Helpers +Lib.db + + require_relative "../models/user.rb" + @user = User.first + def self.weather(zip) + begin + if zip == nil + weather = GoogleWeather.new(@user.zip) + else + weather = GoogleWeather.new(zip) + end + forecast = weather.current_conditions + puts forecast.temp_f + " Degrees Fahrenheit", forecast.condition + rescue SocketError + puts "A connection error occurred fetching weather information." + end + end +end \ No newline at end of file diff --git a/lib/jared/lib.rb b/lib/jared/lib.rb index 93fa1f3..63f30ab 100644 --- a/lib/jared/lib.rb +++ b/lib/jared/lib.rb @@ -1,5 +1,18 @@ -# Lib file loads all Helpers +# Lib file loads all Helpers and Models. +# ActiveRecord DataBase connect + +class Lib + def self.db + ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{Dir.home}/.jared.sqlite3") + end +end path = Gem::Specification.find_by_name("jared") -Dir["#{path.gem_dir}/lib/jared/helpers/*.rb"].each {|file| require file } -#Dir[File.dirname(__FILE__) + '/helpers/*.rb'].each {|file| require file } + +# Model files requires +Dir["#{path.gem_dir}/lib/jared/models/*.rb"].each {|file| require file } +#Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file } + +# Helper files requires +#Dir["#{path.gem_dir}/lib/jared/helpers/*.rb"].each {|file| require file } +Dir[File.dirname(__FILE__) + '/helpers/*.rb'].each {|file| require file } \ No newline at end of file diff --git a/lib/jared/models/user.rb b/lib/jared/models/user.rb new file mode 100644 index 0000000..ccc34f4 --- /dev/null +++ b/lib/jared/models/user.rb @@ -0,0 +1,5 @@ +class User < ActiveRecord::Base + validates_presence_of :name, :zip + validates_length_of :zip, :minimum=>5, :maximum=>5 + default_scope :order => 'created_at DESC' +end