# Dependencies: ruby-full, watir, xvfb, iceweasel, geckodriver # Run `Xvfb :10 -ac &` before running this script require 'watir' NEW_DOC_URL = "https://docs.google.com/document/create" EMAIL_ADDRESS = ENV['DOCWRITER_EMAIL'] PASSWORD = ENV['DOCWRITER_PASSWORD'] SHARE_WITH_EMAIL = ENV['DOCWRITER_SHARETO'] browser = Watir::Browser.new(:firefox) browser.goto NEW_DOC_URL el = browser.input(id: "identifierId") el.wait_until_present el.send_keys EMAIL_ADDRESS btn = browser.div(id: "identifierNext") btn.wait_until_present btn.click pswd = browser.input(name: "password") pswd.wait_until_present pswd.send_keys PASSWORD btn = browser.div(id: "passwordNext") btn.wait_until_present btn.click # Write the title el = browser.input(class: "docs-title-input") el.wait_until_present el.click until el.value.empty? el.send_keys :backspace end el.send_keys DateTime.now.new_offset(Rational(-4, 24)).strftime("%h %d, %Y - %I:%M%p") el.send_keys :return # Share the doc el = browser.div(class: "jfk-button-action") el.wait_until_present el.click sleep 2 iframe = browser.iframes.find {|i| i.class_name == "share-client-content-iframe"} sleep 1 iframe.textarea(class: "apps-share-chips-input").send_keys SHARE_WITH_EMAIL sleep 1 iframe.div(class: "simple-sharing-primary-button").click cursor = browser.div(class: 'kix-cursor-caret') cursor.wait_until_present puts "READY" $stdout.flush table = { "0,0" => ",", "0,1" => "/", "0,2" => "1", "0,3" => "3", "0,4" => "7", "0,5" => "5", "0,6" => "-", "0,7" => "9", "1,0" => ".", "1,1" => "PLUSMINUS", "1,2" => "2", "1,3" => "4", "1,4" => "8", "1,5" => "6", "1,6" => "=", "1,7" => "0", "2,0" => "HALF", "2,1" => "q", "2,2" => "e", "2,3" => "t", "2,4" => "o", "2,5" => "u", "2,6" => "n", "2,7" => "v", "3,0" => ";", "3,1" => "z", "3,2" => "f", "3,3" => "h", "3,4" => "s", "3,5" => "k", "3,6" => "x", "3,7" => "c", "4,0" => "]", "4,1" => "w", "4,2" => "r", "4,3" => "y", "4,4" => "p", "4,5" => "i", "4,6" => "m", "4,7" => "b", "5,0" => "'", "5,1" => "a", "5,2" => "g", "5,3" => "j", "5,4" => "d", "5,5" => "l", "5,6" => "_SWITCH", "5,7" => "\t", "6,0" => " ", "6,1" => "\n", "6,2" => "W_OUT", "6,3" => "RELOC", "6,4" => "ALT", "6,5" => "\b", "6,6" => "CORRECT", "6,7" => "CODE", "7,0" => "SHIFT", "7,1" => "SHIFT_LOCK", "7,2" => "NC", "7,3" => "NC", "7,4" => "NC", "7,5" => "NC", "7,6" => "NC", "7,7" => "NC" } shiftTable = { "0,0" => ",", "0,1" => "?", "0,2" => "!", "0,3" => "#", "0,4" => "&", "0,5" => "%", "0,6" => "_", "0,7" => "(", "1,0" => ".", "1,1" => "CIRCLE", "1,2" => "@", "1,3" => "$", "1,4" => "*", "1,5" => "CENT", "1,6" => "+", "1,7" => ")", "2,0" => "QUARTER", "2,1" => "Q", "2,2" => "E", "2,3" => "T", "2,4" => "O", "2,5" => "U", "2,6" => "N", "2,7" => "V", "3,0" => ":", "3,1" => "Z", "3,2" => "F", "3,3" => "H", "3,4" => "S", "3,5" => "K", "3,6" => "X", "3,7" => "C", "4,0" => "}", "4,1" => "W", "4,2" => "R", "4,3" => "Y", "4,4" => "P", "4,5" => "I", "4,6" => "M", "4,7" => "B", "5,0" => "\"", "5,1" => "A", "5,2" => "G", "5,3" => "J", "5,4" => "D", "5,5" => "L", "5,6" => "_SWITCH", "5,7" => "\t", "6,0" => " ", "6,1" => "\n", "6,2" => "W_OUT", "6,3" => "RELOC", "6,4" => "ALT", "6,5" => "\b", "6,6" => "CORRECT", "6,7" => "CODE", "7,0" => "SHIFT", "7,1" => "SHIFT_LOCK", "7,2" => "NC", "7,3" => "NC", "7,4" => "NC", "7,5" => "NC", "7,6" => "NC", "7,7" => "NC" } consecutive_enter_count = 0 $stdin.each do |io| if io == "6,1\n" if consecutive_enter_count >= 1 cursor.send_keys :return cursor.send_keys :return consecutive_enter_count = 0 else cursor.send_keys " " consecutive_enter_count += 1 end else cursor.send_keys io.include?("s") ? shiftTable[io.chomp.sub(/s/, '')] : table[io.chomp] consecutive_enter_count = 0 end end