def getWebMentions(self): if 'webmention_io' not in self.conf: return False wio = WebmentionIO(self.conf['webmention_io']['token']) last_id = self.status['webmention_io']['last_id'] print 'last id = %s' % last_id ret = wio.linksToDomain(urlparse(self.conf['blog']['url'])[1]) #domain of blog url if not ret: print wio.error return False i = 1 for mention in ret['links']: if mention['id'] > self.status['webmention_io']['last_id']: self.status['webmention_io']['last_id'] = mention['id'] print print '%02d Webmention.io ID: %s' % (i, mention['id'] ) print ' Source: %s' % mention['source'] print ' Target: %s' % mention['target'] print ' Verification Date: %s' % mention['verified_date'] # Now use UrlInfo to get some more information about the source. # Most web apps showing webmentions, will probably do something # like this. info = UrlInfo(mention['source']) print ' Source URL info:' print ' Title: %s' % info.title() print ' Pub Date: %s' % info.pubDate() print ' in-reply-to: %s' % info.inReplyTo() print ' Author image: %s' % info.image() x = self.normalizeUrl(mention['target']) data = self.readUrlDb(x) data['webmention_io'][mention['id']] = { 'source': str(mention['source']), 'target': str(mention['target']), 'verified_date': str(mention['verified_date']), 'source_title': str(info.title()), 'source_pub_date': str(info.pubDate()), 'source_in_reply_to': str(info.inReplyTo()), 'source_image': str(info.image()), 'source_image_local': self.cacheImage(info.image()), 'source_snippet': info.snippetWithLink(mention['target']) } self.writeUrlDb(data) self.touchBucket3PostByURL(x) i += 1 self.writeInfoDb()
def test_linksTo(self): mock_links_to = 'https://http.cat/404' url_info = UrlInfo(mock_url) links_to = url_info.linksTo(mock_links_to) self.assertEqual(links_to, False)
# If you have an access token from webmention.io, # set it here. Some calls require it. webmention_io_token = None wio = WebmentionIO(webmention_io_token) # Get all links "mentioning" http://indiewebcamp.com/webmention target_url = "http://indiewebcamp.com/webmention" ret = wio.linksToURL(target_url) if not ret: print wio.error else: for link in ret["links"]: print print "Webmention.io ID: %s" % link["id"] print " Source: %s" % link["source"] print " Verification Date: %s" % link["verified_date"] # Now use UrlInfo to get some more information about the source. # Most web apps showing webmentions, will probably do something # like this. info = UrlInfo(link["source"]) print " Source URL info:" print " Title: %s" % info.title() print " Pub Date: %s" % info.pubDate() print " in-reply-to: %s" % info.inReplyTo() print " Author image: %s" % info.image() print " Snippet: %s" % info.snippetWithLink(target_url)
def test_image(self): mock_image = 'Look' url_info = UrlInfo(mock_url) url_info.data['image'] = mock_image image = url_info.image() self.assertEqual(image, mock_image)
def test_snippetWithLink(self): mock_url = 'https://http.cat/200' url_info = UrlInfo(mock_url) mock_snippet = url_info.snippetWithLink(mock_url) self.assertEqual(mock_snippet, None)
def test_title(self): mock_title = 'Hello, World!' url_info = UrlInfo(mock_url) url_info.data['title'] = mock_title title = url_info.title() self.assertEqual(title, mock_title)
def test_pubDate(self): mock_pubDate = 'now' url_info = UrlInfo(mock_url) url_info.data['pubDate'] = mock_pubDate pubDate = url_info.pubDate() self.assertEqual(pubDate, mock_pubDate)
def test_inReplyTo(self): mock_reply_to = 'http://in.reply/to' url_info = UrlInfo(mock_url) url_info.data['in_reply_to'] = mock_reply_to in_reply_to = url_info.inReplyTo() self.assertEqual(in_reply_to, mock_reply_to)
# If you have an access token from webmention.io, # set it here. Some calls require it. webmention_io_token = None wio = WebmentionIO(webmention_io_token) # Get all links "mentioning" http://indiewebcamp.com/webmention target_url = 'http://indiewebcamp.com/webmention' ret = wio.linksToURL(target_url) if not ret: print wio.error else: for link in ret['links']: print print 'Webmention.io ID: %s' % link['id'] print ' Source: %s' % link['source'] print ' Verification Date: %s' % link['verified_date'] # Now use UrlInfo to get some more information about the source. # Most web apps showing webmentions, will probably do something # like this. info = UrlInfo(link['source']) print ' Source URL info:' print ' Title: %s' % info.title() print ' Pub Date: %s' % info.pubDate() print ' in-reply-to: %s' % info.inReplyTo() print ' Author image: %s' % info.image() print ' Snippet: %s' % info.snippetWithLink(target_url)
# If you have an access token from webmention.io, # set it here. Some calls require it. webmention_io_token = None wio = WebmentionIO(webmention_io_token) # Get all links "mentioning" http://indiewebcamp.com/webmention target_url = 'http://indiewebcamp.com/webmention' ret = wio.linksToURL(target_url) if not ret: print(wio.error) else: for link in ret['links']: print('') print('Webmention.io ID: %s' % link['id']) print(' Source: %s' % link['source']) print(' Verification Date: %s' % link['verified_date']) # Now use UrlInfo to get some more information about the source. # Most web apps showing webmentions, will probably do something # like this. info = UrlInfo(link['source']) print(' Source URL info:') print(' Title: %s' % info.title()) print(' Pub Date: %s' % info.pubDate()) print(' in-reply-to: %s' % info.inReplyTo()) print(' Author image: %s' % info.image()) print(' Snippet: %s' % info.snippetWithLink(target_url))