accountingnerd
New Member
- Joined
- Mar 17, 2011
- Messages
- 6
- Reaction score
- 5
Here's a little python script that I hacked out to do automatic switches to Google Voice forwarding for my wife's smart phone. She wanted a smart phone so that she could run some apps, but didn't want to spend money on a data plan (or minutes for that matter) because she is mostly at home with a strong WiFi connection. Thus, I needed a solution that wouldn't depend on a data plan to make changes to her Google Voice settings (like Groove Forwarder), and came up with this. I scheduled this to run every five minutes, and so far, it's worked pretty well.
A couple of external dependencies make this possible. Her phone is set to always have the WiFi on, even when sleeping. We lose some battery life by doing that, but the inconvenience for us is minor. I'm also able to do this because her phone has a reserved IP address in the DHCP server, and so the phone always has the same IP address. Now when she's at home, the home phone rings, and when she's away, the cell phone rings.
A couple of external dependencies make this possible. Her phone is set to always have the WiFi on, even when sleeping. We lose some battery life by doing that, but the inconvenience for us is minor. I'm also able to do this because her phone has a reserved IP address in the DHCP server, and so the phone always has the same IP address. Now when she's at home, the home phone rings, and when she's away, the cell phone rings.
Code:
#!/usr/bin/env python
# Created by Aaron J. Clark, CPA.CITP.
# [email protected]
#
# License:
#
# This Package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# This package is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
#
from googlevoice import Voice
import os
voice = Voice()
#replace with your credentials. 2-factor authentication recommended
voice.login("[email protected]","password")
# ping her phone to see if she's home
response = os.system("ping -c1 192.168.X.X") #Change to the IP address of the device you are pinging
if response == 0: #means that she's connected to the WiFi at home
for phone in voice.phones:
if phone.name.strip() == "Cell": #Change to your phone's name in Google Voice
phone.disable()
elif phone.name.strip() == "Home Phone": #Ibid.
phone.enable()
else: #She's out, so forward calls to her cell, and stop forwarding to the house.
for phone in voice.phones:
if phone.name.strip() == "Cell":
phone.enable()
elif phone.name.strip() == "Home Phone":
phone.disable()