-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.rb
70 lines (51 loc) · 1.98 KB
/
run.rb
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
require 'rubygems'
require 'watir-webdriver'
require 'net/http'
require 'json'
require 'yaml'
require 'date'
key = YAML.load_file('keys.yml')["consumer_key"]
print "What would you like to hear about: "
search_term = gets.chomp
print "What language do you like? Describe it using two (or more, if you want Chinese) letters. (Examples that work nicely: es, pl, it, la, de, ar, fr, hu, sv, ja, ko, zh-TW: "
language = gets.chomp
search_result = Net::HTTP.get('api.mendeley.com', URI.escape('/oapi/documents/search/' search_term '/?consumer_key=' key '&items=10'))
search_result_json = JSON.parse(search_result)
search_documents = search_result_json['documents']
doc_ids = []
search_documents.each do |f|
doc_ids << f["uuid"]
end
n = 0
doc_title = nil
doc_abstract = nil
until (doc_title != nil && doc_abstract != nil) do
doc_details = JSON.parse(Net::HTTP.get('api.mendeley.com', URI.escape('/oapi/documents/details/' doc_ids[n] '/?consumer_key=' key)))
doc_title = doc_details["title"]
doc_abstract = doc_details["abstract"]
n = n 1
end
translate_request_url = 'http://translate.google.com/#auto/' language '/' URI.escape(doc_title ". " doc_abstract)
$background = Watir::Browser.new(:firefox)
$background.window.resize_to(0, 0)
if Date.today.mon == 12
$background.goto('http://www.funvid.hu/index.php?page=videos§ion=view&vid_id=101456')
else
$background.goto('http://www.rainymood.com/')
end
$b = Watir::Browser.new(:firefox)
if translate_request_url.length > 2000
$b.goto('http://translate.google.com/#auto/' language '/')
$b.textarea(:id => 'source').set(doc_title ". " doc_abstract)
else
$b.goto(translate_request_url)
end
Watir::Wait.until(5, "Waiting for the 'listen' button.") { $b.div(:id => 'gt-res-listen').present? }
$b.div(:id => 'gt-res-listen').click
puts "Say something once you're done with listening... "
bye1 = gets.chomp
$b.close
$background.goto('http://heeeeeeeey.com/')
puts "Yeah Boiiiiii!"
bye2 = gets.chomp
$background.close