Skip to content
Browse files

Added Deamon (Email checking) and other additions/fixes

  • Loading branch information...
1 parent 3936a57 commit 4ca82164ce40c7b379aa409dfc2c0c60f1579bdf @cyberarm committed May 2, 2012
View
2 Gemfile
@@ -1,4 +1,4 @@
source "http://rubygems.org"
# Specify your gem's dependencies in jared.gemspec
-gemspec
+gemspec
View
3 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
View
55 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
View
3 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
View
2 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"
View
41 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
View
2 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.
View
44 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
+ loop do
+ Deamon.task
+ Deamon.appointment
+ Deamon.message
+ puts
+ puts
+ sleep(60)
+ end
+ end
+ end
View
4 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
View
19 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
View
19 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 }
View
5 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

0 comments on commit 4ca8216

Please sign in to comment.
Something went wrong with that request. Please try again.