-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAIN-CLI.rb
More file actions
146 lines (103 loc) · 3.51 KB
/
MAIN-CLI.rb
File metadata and controls
146 lines (103 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env ruby
require 'readline'
require 'pp'
require 'docx'
require "mongo"
include Mongo
require File.dirname(__FILE__)+"/class/mongo.class.rb"
#require File.dirname(__FILE__)+"/class/timer.class.rb"
#require File.dirname(__FILE__)+"/class/rocketio.class.rb"
#require File.dirname(__FILE__)+"/class/logging.class.rb"
require File.dirname(__FILE__)+"/class/google.class.rb"
require File.dirname(__FILE__)+"/class/yaml.class.rb"
#require File.dirname(__FILE__)+"/class/optparse.class.rb"
require 'sentimental'
Sentimental.load_defaults
analyzer = Sentimental.new
#require_relative "lib/zip.rb"
$configuration = Yamlconfig::load("config.yml")
db = MongoClient.new("localhost", 27017, :pool_size =>45, :pool_timeout => 45).db("googlefiles")
coll = db.collection("students")
def putsHeader(stringr)
print "\033[s\033[1A\033[1000D\033[K"
puts stringr
print "\033[u\033["
print Readline.point + 2
print "C"
end
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
Readline.completion_append_character = " "
Readline.completion_proc = Proc.new do |str|
Readline.completion_append_character = " "
case Readline.line_buffer[0..Readline.point]
when /^ .*/
putsHeader "Remove that space"
""
when /^.* email.*/
Readline.completion_append_character = ""
emailaddress = /^.* email (.*)/.match(Readline.line_buffer[0..Readline.point]).captures[0]
putsHeader "Searching for #{emailaddress}"
search = str
return_emailaddress = coll.find({"_id" =>/#{search}/ }, {:fields => ["_id"]})
return_emailaddress.map {|a| a['_id'] }
else
['get','list','view','email','files','help'].grep(/^#{Regexp.escape(str)}/)
end
end
##
##
##
while line = Readline.readline('> ', true)
case line
when /^help$/
puts "####################################################################"
puts "################ HELP ###################"
puts "####################################################################"
puts "Allowed Commands"
print " "
['get','list','view','email','files','help'].each { |i| print "#{i}, "; }
puts ""
when /^e$/
print "\033[s\033[1A\033[1000D\033[3C[xit]\033[u\033[1B\033[1000D"
exit 130
when /^exit$/
exit 130
when /^list email .* .*$/
captures = /^list email (.*) (.*)/.match(line).captures
pp captures.count
emailaddress = captures[0]
amount = captures[1].to_i
amount = 20 if amount == 0
if ( captures.count == 2 ) && (amount != 0)
puts "## Custom Listing Emails for #{emailaddress}"
person_object = GoogleAPI.new(emailaddress)
puts "Total emails: #{person_object.total}"
person_object.list_emails(amount).each do |listing|
puts "[#{listing[0]}] #{listing[1]}"
end
end
when /^list email [^-\s]*$/
emailaddress = /^list email (.*)/.match(line).captures[0]
#pp emailaddress.class
puts "## Listing Emails for #{emailaddress}"
person_object = GoogleAPI.new(emailaddress)
puts "Total emails: #{person_object.total}"
person_object.list_emails(30).each do |listing|
puts "[#{listing[0]}] #{listing[1]} [#{analyzer.get_sentiment listing[2]} #{analyzer.get_score listing[2]}]"
#puts "[#{listing[02]}]"
end
when /^get email [^-\s]* [^-\s]*/
captures = /^get email (.*) (.*)/.match(line).captures
emailaddress = captures[0]
emailid = captures[1]
#pp emailaddress
puts "## Get Email for #{emailaddress}"
person_object = GoogleAPI.new(emailaddress)
email = person_object.email(emailid)
puts email[1]
puts email[2]
else
puts "## No Action"
#puts line
end
end