Skip to content

Commit

Permalink
Added Deamon (Email checking) and other additions/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberarm committed May 2, 2012
1 parent 3936a57 commit 4ca8216
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,4 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in jared.gemspec
gemspec
gemspec
3 changes: 2 additions & 1 deletion jared.gemspec
Expand Up @@ -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
55 changes: 42 additions & 13 deletions 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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."
Expand All @@ -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"
Expand All @@ -107,6 +133,9 @@ def self.clock

when "create", "Create"
Helpers.create

when "weather", "Weather"
Helpers.weather(ARGV[1])

else
Helpers.notfound
Expand Down
3 changes: 3 additions & 0 deletions 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
Expand Down
2 changes: 2 additions & 0 deletions 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"
Expand Down
41 changes: 41 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion 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.
Expand Down
44 changes: 42 additions & 2 deletions 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
4 changes: 3 additions & 1 deletion 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
Expand Down
19 changes: 19 additions & 0 deletions 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
19 changes: 16 additions & 3 deletions 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 }
5 changes: 5 additions & 0 deletions 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.