Example #1
0
 def postEntry(self, entry, ctx):
     source_url = entry.url
     logger.debug("Finding mentions in: %s" % source_url)
     refs = ronkyuu.findMentions(source_url)
     for r in refs.get('refs', []):
         logger.debug("Sending webmention: %s -> %s" % (source_url, r))
         ronkyuu.sendWebmention(source_url, r)
Example #2
0
    def runTest(self):
        source = 'https://bear.im/bearlog/2017/245/checking-indieweb-code'
        target = 'https://webmention.rocks/test/23/page'

        resp = sendWebmention(source, target, test_urls=False)

        assert resp.status_code == 200
Example #3
0
    def runTest(self):
        status_code, webmention_url = ronkyuu.discoverEndpoint('http://localhost:9999')

        assert status_code == 200

        result = ronkyuu.sendWebmention('http://boathole.org/testing', 'http://localhost:9999/article2', webmention_url)

        assert result.status_code == 200
	def _send_mentions(self, mentions_set):
		# private method to send mentions to a set of urls
		result = []
		for link in mentions_set:
			try:
				result.append([link, ronkyuu.sendWebmention(self.source_url, link)])
			except:
				result.append([link, "Error"])
				pass

		return result
Example #5
0
def send_webmention(source_url, target_url):
    print('preparing to send webmention from ' + source_url + ' to ' +
          target_url)
    print('waiting for ' + source_url + ' to be accessible...')
    if not wait_for_url(source_url):
        print(source_url + ' is not accessible.  Skipping webmention')
        return None
    print('sending web mention from ' + source_url + " to " + target_url +
          " using " + BRIDGY_ENDPOINT)
    r = sendWebmention(source_url, target_url, BRIDGY_ENDPOINT)
    if r.status_code != requests.codes.created:
        print('Bridgy webmention failed with ' + str(r.status_code))
        print('Error information ' + str(r.json()))
    return r
Example #6
0
def send_webmention(site_url, source_url, target_url):
    abs_url = os.path.join(site_url, source_url)
    print(f'Sending webmention from {abs_url} to {target_url}')
    status, endpoint_url = discoverEndpoint(target_url)
    if status == requests.codes.ok and endpoint_url is not None:
        r = sendWebmention(abs_url, target_url, endpoint_url)
        if not r.ok:
            print(f'Webmention failed with {r.status_code}')
            print(f'Error information {r.json()}')
        return r
    else:
        print(f'Failed to discover endpoint: status: {status}, ' +
              f'endpoint: {endpoint_url}')
        return None
Example #7
0
    cfg = ronkyuu.discoverConfig(args.eventConfigFile)

    domains = []  # cfg.get('domains', [])
    sourceURL = args.sourceURL
    vouchDomain = args.vouch

    print('Scanning %s for mentions' % sourceURL)
    if vouchDomain is not None:
        print('vouch domain present and will be sent')

    mentions = ronkyuu.findMentions(sourceURL, domains)

    print(mentions['refs'])

    for href in mentions['refs']:
        if sourceURL != href:
            print(href)
            wmStatus, wmUrl = ronkyuu.discoverEndpoint(href, test_urls=False)
            if wmUrl is not None and wmStatus == 200:
                print('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                status_code = ronkyuu.sendWebmention(sourceURL,
                                                     href,
                                                     wmUrl,
                                                     vouchDomain=vouchDomain)

                if status_code == requests.codes.ok:
                    print('\twebmention sent successfully')
                else:
                    print('\twebmention send returned a status code of %s' %
                          status_code)
Example #8
0
    parser.add_argument('--vouch',           default=None)
    parser.add_argument('--eventConfigFile', default=None)

    args = parser.parse_args()
    cfg  = ronkyuu.discoverConfig(args.eventConfigFile)

    domains     = []  # cfg.get('domains', [])
    sourceURL   = args.sourceURL
    vouchDomain = args.vouch

    print('Scanning %s for mentions' % sourceURL)
    if vouchDomain is not None:
        print('vouch domain present and will be sent')

    mentions = ronkyuu.findMentions(sourceURL, domains)

    print(mentions['refs'])

    for href in mentions['refs']:
        if sourceURL != href:
            print(href)
            wmStatus, wmUrl = ronkyuu.discoverEndpoint(href, test_urls=False)
            if wmUrl is not None and wmStatus == 200:
                print('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                status_code = ronkyuu.sendWebmention(sourceURL, href, wmUrl, vouchDomain=vouchDomain)

                if status_code == requests.codes.ok:
                    print('\twebmention sent successfully')
                else:
                    print('\twebmention send returned a status code of %s' % status_code)
Example #9
0
import argparse
import requests
import ronkyuu

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('sourceURL')
    parser.add_argument('--eventConfigFile', default=None)

    args = parser.parse_args()
    cfg  = ronkyuu.discoverConfig(args.eventConfigFile)

    domains   = [] #cfg.get('domains', [])
    sourceURL = args.sourceURL

    print('Scanning %s for mentions' % sourceURL)

    mentions = ronkyuu.findMentions(sourceURL, domains)
    for href in mentions:
        if sourceURL <> href:
            wmStatus, wmUrl = ronkyuu.discoverEndpoint(href)
            if wmUrl is not None and wmStatus == 200:
                print('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                status_code = ronkyuu.sendWebmention(sourceURL, href, wmUrl)

                if status_code == requests.codes.ok:
                    print('\twebmention sent successfully')
                else:
                    print('\twebmention send returned a status code of %s' % status_code)
Example #10
0
def checkOutboundWebmentions(sourceURL, html, targetFile, update=False):
    logger.info('checking for outbound webmentions [%s]' % sourceURL)
    try:
        cached = loadOutboundWebmentions(targetFile)
        found = ronkyuu.findMentions(sourceURL, content=html)
        mentions = {}

        # loop thru webmentions found in our post and
        # check if they are new/updated or already seen
        for href in found['refs']:
            if sourceURL != href:
                logger.info(href)
                key = 'webmention::%s::%s' % (sourceURL, href)
                keySeen = db.exists(key)
                if keySeen:
                    if update:
                        keySeen = False
                        s = 'update forced'
                    else:
                        s = 'already processed'
                else:
                    s = 'new mention'
                logger.info('\t%s [%s]' % (s, key))
                mentions[key] = {
                    'key': key,
                    'href': href,
                    'keySeen': keySeen,
                    'removed': False
                }
        # loop thru found webmentions and check against cache for any removed
        for key in cached:
            if key not in mentions:
                mentions[key] = cached[key]
                mentions[key]['removed'] = True
                if 'keySeen' not in mentions[key]:
                    mentions[key]['keySeen'] = False
        removed = []
        for key in mentions:
            mention = mentions[key]
            logger.info('seen: %(keySeen)s removed: %(removed)s [%(key)s]' %
                        mention)

            # send webmentions for new/updated or removed
            if mention['removed'] or not mention['keySeen']:
                if mention['removed']:
                    removed.append(key)

                href = mention['href']
                wmStatus, wmUrl, debug = ronkyuu.discoverEndpoint(
                    href, test_urls=False, debug=True)
                logger.info('webmention endpoint discovery: %s [%s]' %
                            (wmStatus, wmUrl))

                if len(debug) > 0:
                    logger.info('\n\tdebug: '.join(debug))
                if wmUrl is not None and wmStatus == 200:
                    logger.info('\tfound webmention endpoint %s for %s' %
                                (wmUrl, href))
                    resp, debug = ronkyuu.sendWebmention(sourceURL,
                                                         href,
                                                         wmUrl,
                                                         debug=True)
                    if len(debug) > 0:
                        logger.info('\n\tdebug: '.join(debug))
                    if resp.status_code == requests.codes.ok:
                        if key not in cached:
                            cached[key] = {
                                'key': key,
                                'href': href,
                                'wmUrl': wmUrl,
                                'status': resp.status_code
                            }
                        if len(resp.history) == 0:
                            db.set(key, resp.status_code)
                            logger.info('\twebmention sent successfully')
                        else:
                            logger.info('\twebmention POST was redirected')
                    else:
                        logger.info(
                            '\twebmention send returned a status code of %s' %
                            resp.status_code)
        for key in removed:
            del cached[key]
            db.delete(key)

        saveOutboundWebmentions(targetFile, cached)
    except:
        logger.exception('exception during checkOutboundWebmentions')
Example #11
0
def checkOutboundWebmentions(sourceURL, html, targetFile, update=False):
    logger.info('checking for outbound webmentions [%s]' % sourceURL)
    try:
        cached   = loadOutboundWebmentions(targetFile)
        found    = ronkyuu.findMentions(sourceURL, content=html)
        mentions = {}

        # loop thru webmentions found in our post and
        # check if they are new/updated or already seen
        for href in found['refs']:
            if sourceURL != href:
                logger.info(href)
                key     = 'webmention::%s::%s' % (sourceURL, href)
                keySeen = db.exists(key)
                if keySeen:
                    if update:
                        keySeen = False
                        s       = 'update forced'
                    else:
                        s = 'already processed'
                else:
                    s = 'new mention'
                logger.info('\t%s [%s]' % (s, key))
                mentions[key] = { 'key':     key,
                                  'href':   href,
                                  'keySeen': keySeen,
                                  'removed': False
                                }
        # loop thru found webmentions and check against cache for any removed
        for key in cached:
            if key not in mentions:
                mentions[key] = cached[key]
                mentions[key]['removed'] = True
                if 'keySeen' not in mentions[key]:
                    mentions[key]['keySeen'] = False
        removed = []
        for key in mentions:
            mention = mentions[key]
            logger.info('seen: %(keySeen)s removed: %(removed)s [%(key)s]' % mention)

            # send webmentions for new/updated or removed
            if mention['removed'] or not mention['keySeen']:
                if mention['removed']:
                    removed.append(key)

                href = mention['href']
                wmStatus, wmUrl, debug = ronkyuu.discoverEndpoint(href, test_urls=False, debug=True)
                logger.info('webmention endpoint discovery: %s [%s]' % (wmStatus, wmUrl))

                if len(debug) > 0:
                    logger.info('\n\tdebug: '.join(debug))
                if wmUrl is not None and wmStatus == 200:
                    logger.info('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                    resp, debug = ronkyuu.sendWebmention(sourceURL, href, wmUrl, debug=True)
                    if len(debug) > 0:
                        logger.info('\n\tdebug: '.join(debug))
                    if resp.status_code == requests.codes.ok:
                        if key not in cached:
                            cached[key] = { 'key':    key,
                                            'href':   href,
                                            'wmUrl':  wmUrl,
                                            'status': resp.status_code
                                          }
                        if len(resp.history) == 0:
                            db.set(key, resp.status_code)
                            logger.info('\twebmention sent successfully')
                        else:
                            logger.info('\twebmention POST was redirected')
                    else:
                        logger.info('\twebmention send returned a status code of %s' % resp.status_code)
        for key in removed:
            del cached[key]
            db.delete(key)

        saveOutboundWebmentions(targetFile, cached)
    except:
        logger.exception('exception during checkOutboundWebmentions')