Created
February 16, 2015 17:11
-
-
Save noniq/6a080349efc26f5f1c62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "active_support" | |
require "highline/import" | |
require "mechanize" | |
# Wartezeit in Sekunden zwischen wiederholten Aufrufen der Formularseite, wenn sie gerade nicht verfügbar ist | |
FORM_RETRY_TIMEOUT = 30 | |
LINES = { | |
"Stefan" => "69910017787", | |
"Mo" => "69910017789", | |
"Bürohandy" => "69919971620" | |
} | |
KNOWN_LINES = LINES.merge({ | |
"Büro-Sprachbox" => "69939971620" | |
}) | |
############################################################################ | |
def info(msg) | |
puts "\n#{msg}\n\n" | |
end | |
def identify(number_to_identify) | |
KNOWN_LINES.each_pair do |name, number| | |
return name if number_to_identify.match(/#{number}/) | |
end | |
return number_to_identify # Fallback für unbekannte Nummern | |
end | |
def login | |
info "Einloggen auf der Orange-Website ..." | |
page = @agent.get("https://www.orange.at/Content.Node/login/index.php") | |
loginform = page.forms.last | |
loginform.username = "*REMOVED*" | |
loginform.password = "*REMOVED*" | |
@agent.submit(loginform, loginform.buttons.first) | |
@agent.page.link_with(:text => "Anrufeinstellungen").click | |
end | |
def select_line(phonenumber) | |
@agent.page.link_with(:text => /#{phonenumber}/).click | |
until form = @agent.page.form_with(:name => "form3") | |
puts " nicht verfügbar, nächster Versuch in #{FORM_RETRY_TIMEOUT} Sekunden ..." | |
sleep FORM_RETRY_TIMEOUT | |
@agent.page.link_with(:text => /#{phonenumber}/).click | |
end | |
form | |
end | |
def print_forwards_for(name) | |
puts "#{name}:" | |
form = select_line(LINES[name]) | |
%w{Unconditional NoAnswer OnSubscriberBusy NotReachable}.each do |type| | |
state = form.radiobutton_with(:name => "CallForwarding#{type}_T11", :checked => true).value | |
number = form.field_with(:name => "CallForwarding#{type}_Number_T11").value | |
next if state == "0" | |
info = case state | |
when "on" then identify(number) | |
when "VoiceBox" then "Sprachbox" | |
else "UNBEKANNT: #{state}" | |
end | |
puts "%20s => #{info}" % type | |
end | |
end | |
def set_forwards_for(name, unconditional, other) | |
puts "Setze Weiterleitungen: #{name} ..." | |
form = select_line(LINES[name]) | |
set_forward(form, "Unconditional", unconditional) | |
set_forward(form, "NoAnswer", other) | |
set_forward(form, "OnSubscriberBusy", other) | |
set_forward(form, "NotReachable", other) | |
form.radiobutton_with(:name => "CallingLines", :value => "T11").check | |
@agent.submit(form, form.buttons.first) | |
end | |
def set_forward(form, type, target) | |
name ="CallForwarding#{type}_T11" | |
case target | |
when :off then form.radiobutton_with(:name => name, :value => "0").check | |
when :voicemail then form.radiobutton_with(:name => name, :value => "VoiceBox").check | |
else | |
form.radiobutton_with(:name => name, :value => "on").check | |
form.field_with(:name => "CallForwarding#{type}_Number_T11").value = "43" + target | |
end | |
end | |
def print_status | |
info "Status der Rufumleitungen wird abgefragt ..." | |
LINES.each_key do |name| | |
print_forwards_for name | |
puts | |
end | |
end | |
def activate_defaults | |
info "Standard-Rufumleitungen werden aktiviert ..." | |
set_forwards_for("Stefan" , :off, LINES["Bürohandy"]) | |
set_forwards_for("Mo" , :off, LINES["Bürohandy"]) | |
set_forwards_for("Bürohandy", :off, :voicemail) | |
end | |
def activate_stefan | |
info "Rufumleitung zu Stefan wird aktiviert ..." | |
set_forwards_for("Stefan" , :off, KNOWN_LINES["Büro-Sprachbox"]) | |
set_forwards_for("Mo" , LINES["Stefan"], :off) | |
set_forwards_for("Bürohandy", LINES["Stefan"], :off) | |
end | |
def activate_mo | |
info "Rufumleitung zu Mo wird aktiviert ..." | |
set_forwards_for("Stefan" , LINES["Mo"], :off) | |
set_forwards_for("Mo" , :off, KNOWN_LINES["Büro-Sprachbox"]) | |
set_forwards_for("Bürohandy", LINES["Mo"], :off) | |
end | |
def reset_to_default(name) | |
info "Standard-Rufumleitungen für #{name} werden aktiviert ..." | |
set_forwards_for(name, :off, LINES["Bürohandy"]) | |
end | |
def forward_to_office(name) | |
info "Rufumleitung von #{name} zu Bürohandy wird aktiviert ..." | |
set_forwards_for(name, LINES["Bürohandy"], :off) | |
end | |
########################################################################### | |
HighLine.track_eof = false # Funktioniert sonst nicht gemeinsam mit mechanize ... | |
@agent = Mechanize.new | |
login | |
loop do | |
puts "\n" | |
choose do |menu| | |
menu.index = :number | |
menu.choice("Aktuelle Rufumleitungen anzeigen") { print_status } | |
menu.choice("Insgesamt: Standard-Rufumleitungen aktivieren") { activate_defaults } | |
menu.choice("Insgesamt: Alles zu Stefan") { activate_stefan } | |
menu.choice("Insgesamt: Alles zu Mo") { activate_mo } | |
menu.choice("Stefan: Standard-Rufumleitungen") { forward_to_office("Stefan") } | |
menu.choice("Stefan: Alles zu Bürohandy") { forward_to_office("Stefan") } | |
menu.choice("Mo: Standard-Rufumleitungen") { reset_to_default("Mo") } | |
menu.choice("Mo: Alles zu Bürohandy") { forward_to_office("Mo") } | |
menu.choice("Beenden") { exit } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment