Last active
June 23, 2016 15:39
-
-
Save pdp7/7359910 to your computer and use it in GitHub Desktop.
beaglebone black with adafruit 7-segment facebook notifications display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
import datetime | |
import facebook | |
from Adafruit_7Segment import SevenSegment | |
# =========================================================================== | |
# title: beaglebone black with adafruit 7-segment facebook notifications display | |
# author: drew fustini (http://element14.com/fustini) | |
# blog: http://www.element14.com/community/community/knode/single-board_computers/next-gen_beaglebone/blog/2013/11/08/beaglebone-black-displays-facebook-notifications-on-adafruit-7-segment | |
# | |
# method 1: get short term (2 hour) access_token from: | |
# https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fnotifications | |
# method 2: get extended (60 days) access_token via instructions at: | |
# http://fearofcoding.blogspot.com/2012/10/python-script-to-fetch-messages-from.html | |
# note: install the needed python module with "pip install facepy" | |
# =========================================================================== | |
access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
segment = SevenSegment(address=0x70) | |
print "Press CTRL+C to exit" | |
# Continually update the current unseen notification count on a 4 char, 7-segment display | |
while(True): | |
segment.disp.setBufferRow(0, 0); | |
segment.disp.setBufferRow(1, 0); | |
segment.disp.setBufferRow(2, 0); | |
segment.disp.setBufferRow(3, 0); | |
segment.disp.setBufferRow(4, 0); | |
graph = facebook.GraphAPI(access_token) | |
notifications = graph.get_object("me/notifications") | |
print "notifications" | |
summary = notifications['summary'] | |
print "summary" | |
print summary | |
if summary: | |
num = summary['unseen_count'] | |
print num | |
print int(num / 10) | |
d0 = int(num / 1000) | |
d1 = int(num / 100) | |
d3 = int(num / 10) | |
d4 = num % 10 | |
if d0 != 0: | |
segment.writeDigit(0, int(num / 1000 )) | |
if d1 != 0 or num >= 1000: | |
segment.writeDigit(1, int(num / 100)) | |
if d3 != 0 or num >= 100: | |
segment.writeDigit(3, int(num / 10)) | |
if d4 != 0 or num >= 10: | |
segment.writeDigit(4, num % 10) | |
time.sleep(60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from: http://fearofcoding.blogspot.com/2012/10/python-script-to-fetch-messages-from.html | |
# Imports from facepy api | |
from facepy.utils import get_extended_access_token | |
#App key/APP ID and App_secret from https://developers.facebook.com/apps | |
app_id = 'xxxxxxxxxxxxxx' | |
app_secret = 'yyyyyyyyyyyy' | |
#Token got by selecting app_name from the drop-down list. | |
short_lived_access_token = "token" | |
long_lived_access_token, expires_at = get_extended_access_token( | |
short_lived_access_token, | |
app_id, app_secret) | |
print long_lived_access_token | |
print expires_at |
sir i tried to fetching facebook messages using python script which is mentioned in "http://fearofcoding.blogspot.com/2012/10/python-script-to-fetch-messages-from.html" but after i executed that script its shows error message "(#12) fql is deprecated for versions v2.1 and higher"
could u please help me .
sir this is my code
..?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get token from https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fnotifications
WARNING: it expires after a short period of time
TODO: find a way to automatically obtain a new token when expired