#!/usr/bin/python # Copyright (C) 2013 Jeff Epler # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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 program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, os, re, traceback, time, getpass import BeautifulSoup as bs import mechanize from urllib2 import HTTPError start = time.time() ting_mail = ting_password = ting_phones = None try: execfile(os.path.expanduser("~/.tingrc")) except: traceback.print_exc() if not ting_mail: mail = raw_input("Ting e-mail: ") if not ting_password: mail = getpass.getpass() mech = mechanize.Browser() mech.open("https://ting.com/account/login") mech.select_form(nr=0) mech['email'] = ting_mail mech['password'] = ting_password mech.submit() mech.open("https://ting.com/account/devices") b = bs.BeautifulSoup(mech.response()) t = b.find('table') for row in t.findAll('tr'): cols = row.findAll('td') if not cols or not cols[0].find('a'): continue phone = str(cols[0].find('a').contents[0]) if not ting_phones or phone in ting_phones: print "Phone: %s\n\tMinutes %s\n\tMessages %s\n\tMegabytes %s" % ( phone, cols[3].contents[0], cols[4].contents[0], cols[5].contents[0]) print print "Generated in %.1f seconds" % (time.time() - start) print time.asctime()