12 def get_missed(backend):
13 missedPage = backend._browser.download(backend._missedCallsURL)
14 missedJson = backend._grab_json(missedPage)
18 def get_voicemail(backend):
19 voicemailPage = backend._browser.download(backend._voicemailURL)
20 voicemailJson = backend._grab_json(voicemailPage)
25 smsPage = backend._browser.download(backend._smsURL)
26 smsJson = backend._grab_json(smsPage)
30 def remove_reltime(data):
31 for messageData in data["messages"].itervalues():
32 del messageData["relativeStartTime"]
35 def is_type_changed(backend, type, get_material):
36 jsonMaterial = get_material(backend)
37 unreadCount = jsonMaterial["unreadCounts"][type]
39 previousSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.old.json" % type)
40 currentSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.json" % type)
43 os.remove(previousSnapshotPath)
45 # check if failed purely because the old file didn't exist, which is fine
49 os.rename(currentSnapshotPath, previousSnapshotPath)
52 # check if failed purely because the new old file didn't exist, which is fine
55 previousExists = False
57 remove_reltime(jsonMaterial)
58 textMaterial = pprint.pformat(jsonMaterial)
59 currentSnapshot = file(currentSnapshotPath, "w")
61 currentSnapshot.write(textMaterial)
63 currentSnapshot.close()
65 if unreadCount == 0 or not previousExists:
68 seemEqual = filecmp.cmp(previousSnapshotPath, currentSnapshotPath)
73 gvCookiePath = os.path.join(constants._data_path_, "gv_cookies.txt")
74 backend = gv_backend.GVDialer(gvCookiePath)
79 loggedIn = backend.is_authed()
81 config = ConfigParser.SafeConfigParser()
82 config.read(constants._user_settings_)
87 config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
91 base64.b64decode(blob)
94 username, password = tuple(creds)
95 loggedIn = backend.login(username, password)
96 except ConfigParser.NoOptionError, e:
98 except ConfigParser.NoSectionError, e:
102 notifyOnMissed = config.getboolean("2 - Account Info", "notifyOnMissed")
103 notifyOnVoicemail = config.getboolean("2 - Account Info", "notifyOnVoicemail")
104 notifyOnSms = config.getboolean("2 - Account Info", "notifyOnSms")
105 except ConfigParser.NoOptionError, e:
106 notifyOnMissed = False
107 notifyOnVoicemail = False
109 except ConfigParser.NoSectionError, e:
110 notifyOnMissed = False
111 notifyOnVoicemail = False
117 notifySources.append(("missed", get_missed))
118 if notifyOnVoicemail:
119 notifySources.append(("voicemail", get_voicemail))
121 notifySources.append(("sms", get_sms))
124 for type, get_material in notifySources:
125 if is_type_changed(backend, type, get_material):
130 def notify_on_change():
131 notifyUser = is_changed()
135 led = led_handler.LedHandler()
139 if __name__ == "__main__":