예제 #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_linksToDomain(self):
     mock_domain = 'example.com'
     webmention_io = WebmentionIO()
     links = webmention_io.linksToDomain(mock_domain)
     self.assertEqual(links, False)
예제 #3
0
 def test_linksToURL(self):
     mock_url = 'http://example.com'
     webmention_io = WebmentionIO()
     links = webmention_io.linksToURL(mock_url)
     self.assertEqual(links, {'links': []})
예제 #4
0
 def test_api_links_req(self):
     mock_key = 'something'
     mock_value = 'different'
     webmention_io = WebmentionIO()
     content = webmention_io.api_links_req(mock_key, mock_value)
     self.assertEqual(content, False)
예제 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from webmentiontools.urlinfo import UrlInfo
from webmentiontools.webmentionio import WebmentionIO

# 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:"
예제 #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from webmentiontools.urlinfo import UrlInfo
from webmentiontools.webmentionio import WebmentionIO

# 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:'