def main(): client = DiscourseClient(discourse_powered_site, api_username=API_USERNAME, api_key=API_KEY) user = client.user(API_USERNAME) notification_count = int(user.get('notification_count')) print notification_count if path.isfile(file_path): # open the existing file and update the value if it has changed with open(file_path, 'r+') as notification_file: previous_count = int(notification_file.read().strip()) print "Previous count: %d" % previous_count if notification_count > previous_count: notification_file.seek(0) notification_file.write(str(notification_count)) notification_file.truncate() new_notification = notification_count - previous_count # send system notification system("notify-send -t 0 'FSFTN Discussion' \ 'You have %d new notification\n<a href='http://discuss.fsftn.org'>View discussions</a>" % new_notification) else: # create the file for the first time with open(file_path, 'w') as notification_file: notification_file.write(str(notification_count))