def showMementosForURIRs(urir): urir = getCompleteURI(urir) if ipwbConfig.isLocalHosty(urir): urir = urir.split('/', 4)[4] s = surt.surt(urir, path_strip_trailing_slash_unless_empty=False) indexPath = ipwbConfig.getIPWBReplayIndexPath() print('Getting CDXJ Lines with the URI-R {0} from {1}'.format( urir, indexPath)) cdxjLinesWithURIR = getCDXJLinesWithURIR(urir, indexPath) if len(cdxjLinesWithURIR) == 1: fields = cdxjLinesWithURIR[0].split(' ', 2) redirectURI = '/{1}/{0}'.format(unsurt(fields[0]), fields[1]) return redirect(redirectURI, code=302) msg = '' if cdxjLinesWithURIR: msg += '<p>{0} capture(s) available:</p><ul>'.format( len(cdxjLinesWithURIR)) for line in cdxjLinesWithURIR: fields = line.split(' ', 2) dt14 = fields[1] dtrfc1123 = ipwbConfig.datetimeToRFC1123(fields[1]) msg += ('<li><a href="/{1}/{0}">{0} at {2}</a></li>'.format( unsurt(fields[0]), dt14, dtrfc1123)) msg += '</ul>' return Response(msg)
def resolveMemento(urir, datetime): """ Request a URI-R at a supplied datetime from the CDXJ """ urir = getCompleteURI(urir) if ipwbUtils.isLocalHosty(urir): urir = urir.split('/', 4)[4] s = surt.surt(urir, path_strip_trailing_slash_unless_empty=False) indexPath = ipwbUtils.getIPWBReplayIndexPath() print('Getting CDXJ Lines with the URI-R {0} from {1}'.format( urir, indexPath)) cdxjLinesWithURIR = getCDXJLinesWithURIR(urir, indexPath) closestLine = getCDXJLineClosestTo(datetime, cdxjLinesWithURIR) if closestLine is None: msg = '<h1>ERROR 404</h1>' msg += 'No capture found for {0} at {1}.'.format(urir, datetime) return Response(msg, status=404) uri = unsurt(closestLine.split(' ')[0]) newDatetime = closestLine.split(' ')[1] linkHeader = getLinkHeaderAbbreviatedTimeMap(urir, newDatetime) return (newDatetime, linkHeader, uri)
def showMemento(urir, datetime): """ Request a URI-R at a supplied datetime from the CDXJ """ urir = getCompleteURI(urir) if ipwbConfig.isLocalHosty(urir): urir = urir.split('/', 4)[4] s = surt.surt(urir, path_strip_trailing_slash_unless_empty=False) indexPath = ipwbConfig.getIPWBReplayIndexPath() print('Getting CDXJ Lines with the URI-R {0} from {1}'.format( urir, indexPath)) cdxjLinesWithURIR = getCDXJLinesWithURIR(urir, indexPath) closestLine = getCDXJLineClosestTo(datetime, cdxjLinesWithURIR) if closestLine is None: msg = '<h1>ERROR 404</h1>' msg += 'No capture found for {0} at {1}.'.format(urir, datetime) return Response(msg, status=404) uri = unsurt(closestLine.split(' ')[0]) newDatetime = closestLine.split(' ')[1] if newDatetime != datetime: return redirect('/memento/{0}/{1}'.format(newDatetime, urir), code=302) return show_uri(uri, newDatetime)