예제 #1
0
파일: mentions.py 프로젝트: vrypan/bucket3
    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()
예제 #2
0
 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)
예제 #3
0
# 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)
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
# 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)
예제 #10
0
# 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))