So i'm checking for new notifications on my facebook using a python script. The script suns perfectly when there are unread notifications, but when there are no notifications the "except" clause gets executed even though I have entered an if else clause before to try to solve this issue.
Code:
while (True):
try:
graph = facebook.GraphAPI(access_token)
notifications = graph.get_object("me/notifications")
print "notifications"
if len(notifications['summary']) != 0:
unseen_notifications = notifications['summary']['unseen_count']
if(int(unseen_notifications) > 0):
print("> You have " + str(unseen_notifications) + " unseen Facebook notifications!")
ser.write("1")
print "Wrote to Arduino :D"
else:
print "No New Notifications"
ser.write("0")
except:
print "Notifications are null!"
ser.write("0")
time.sleep(5)
So every time there are no new notifications the code enters the except clause which is not what I need. Any help is much appreciated :D