def test_get(self): aliases = ['GuntersSpacePage', 'SETIInstitute'] url = 'https://graph.facebook.com/GuntersSpacePage/posts?' + FBStore.generate_token() response = urllib.urlopen(url) response = json.loads(response.read()) if 'error' not in response.keys(): print response print spot_urls(response['data'][0]['message']) else: print response['error']['message'], response['error']['type']
def store_fb_post(cls, alias, obj): """ Store a FB post, and its links :param obj: a post as a dict from the FB API """ from flankers.tools import spot_urls if 'message' in obj.keys(): title = obj['id'].split('_')[1] url = 'https://www.facebook.com/' + alias + '/posts/' + title if cls.query().filter(cls.url == url).count() == 0: published = str(obj['created_time'][0:19]) published = time.strptime(published, '%Y-%m-%dT%H:%M:%S') published = datetime(*published[:6]) # store id > title, created_time > published, message > abstract abstract = obj['message'].replace('\n', '') abstract = " ".join(abstract.strip().split()) w = WebResource(url=url, title=title, abstract=abstract, published=published, type_of='fb', in_graph=False) k = w.put() print "fb post stored" spotted = spot_urls(obj['message']) if spotted: for s in spotted: if cls.query().filter(cls.url == s).count() == 0: # store contained link as child l = WebResource(url=s, published=published, parent=k, title='', abstract='', type_of='link') l.put() print "link stored" return w