9 from backends import gv_backend
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)
72 def create_backend(config):
73 gvCookiePath = os.path.join(constants._data_path_, "gv_cookies.txt")
74 backend = gv_backend.GVDialer(gvCookiePath)
79 loggedIn = backend.is_authed()
85 config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
89 base64.b64decode(blob)
92 username, password = tuple(creds)
93 loggedIn = backend.login(username, password)
94 except ConfigParser.NoOptionError, e:
96 except ConfigParser.NoSectionError, e:
103 def is_changed(config, backend):
105 notifyOnMissed = config.getboolean("2 - Account Info", "notifyOnMissed")
106 notifyOnVoicemail = config.getboolean("2 - Account Info", "notifyOnVoicemail")
107 notifyOnSms = config.getboolean("2 - Account Info", "notifyOnSms")
108 except ConfigParser.NoOptionError, e:
109 notifyOnMissed = False
110 notifyOnVoicemail = False
112 except ConfigParser.NoSectionError, e:
113 notifyOnMissed = False
114 notifyOnVoicemail = False
119 notifySources.append(("missed", get_missed))
120 if notifyOnVoicemail:
121 notifySources.append(("voicemail", get_voicemail))
123 notifySources.append(("sms", get_sms))
126 for type, get_material in notifySources:
127 if is_type_changed(backend, type, get_material):
132 def notify_on_change():
133 config = ConfigParser.SafeConfigParser()
134 config.read(constants._user_settings_)
135 backend = create_backend(config)
136 notifyUser = is_changed(config, backend)
140 led = led_handler.LedHandler()
144 print "Nothing to report"
147 if __name__ == "__main__":
149 logging.basicConfig(level=logging.DEBUG)