* Fixing GC support and applying it to GV
[gc-dialer] / src / gc_backend.py
index 53e6aa9..d5101f0 100644 (file)
@@ -44,7 +44,7 @@ class GCDialer(object):
        _accessTokenRe = re.compile(r"""<input type="hidden" name="a_t" [^>]*value="(.*)"/>""")
        _isLoginPageRe = re.compile(r"""<form method="post" action="https://www.grandcentral.com/mobile/account/login">""")
        _callbackRe = re.compile(r"""name="default_number" value="(\d+)" />\s+(.*)\s$""", re.M)
-       _accountNumRe = re.compile(r"""<img src="/images/mobile/inbox_logo.gif" alt="GrandCentral" />\s*(.{14})\s*&nbsp""", re.M)
+       _accountNumRe = re.compile(r"""<input type="hidden" name="gcentral_num" [^>]*value="(.*)"/>""")
        _inboxRe = re.compile(r"""<td>.*?(voicemail|received|missed|call return).*?</td>\s+<td>\s+<font size="2">\s+(.*?)\s+&nbsp;\|&nbsp;\s+<a href="/mobile/contacts/.*?">(.*?)\s?</a>\s+<br/>\s+(.*?)\s?<a href=""", re.S)
        _contactsRe = re.compile(r"""<a href="/mobile/contacts/detail/(\d+)">(.*?)</a>""", re.S)
        _contactsNextRe = re.compile(r""".*<a href="/mobile/contacts(\?page=\d+)">Next</a>""", re.S)
@@ -158,6 +158,9 @@ class GCDialer(object):
 
                return True
 
+       def send_sms(self, number, message):
+               raise NotImplementedError("SMS Is Not Supported by GrandCentral")
+
        def clear_caches(self):
                self.__contacts = None
 
@@ -317,6 +320,9 @@ class GCDialer(object):
                        phoneNumber = detail_match.group(2)
                        yield (phoneType, phoneNumber)
 
+       def get_messages(self):
+               return ()
+
        def _grab_token(self, data):
                "Pull the magic cookie from the datastream"
                atGroup = self._accessTokenRe.search(data)
@@ -325,9 +331,10 @@ class GCDialer(object):
                self._accessToken = atGroup.group(1)
 
                anGroup = self._accountNumRe.search(data)
-               if anGroup is None:
-                       raise RuntimeError("Could not extract account number from GrandCentral")
-               self._accountNum = anGroup.group(1)
+               if anGroup is not None:
+                       self._accountNum = anGroup.group(1)
+               else:
+                       warnings.warn("Could not extract account number from GrandCentral", UserWarning, 2)
 
                self._callbackNumbers = {}
                for match in self._callbackRe.finditer(data):
@@ -340,7 +347,7 @@ def test_backend(username, password):
        print "Authenticated: ", backend.is_authed()
        print "Login?: ", backend.login(username, password)
        print "Authenticated: ", backend.is_authed()
-       print "Token: ", backend._accessToken
+       # print "Token: ", backend._accessToken
        print "Account: ", backend.get_account_number()
        print "Callback: ", backend.get_callback_number()
        # print "All Callback: ",