Skip to content

Instantly share code, notes, and snippets.

@neofreko
Last active December 22, 2015 01:59
Show Gist options
  • Save neofreko/6400334 to your computer and use it in GitHub Desktop.
Save neofreko/6400334 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Akhmad Fathonih</author>
<description>URL 404 check</description>
<sampleQuery><![CDATA[
USE 'https://www.dropbox.com/s/n6xzivkwyfz3lhm/yql-404.xml?dl=1' AS mytable;select * from mytable where url = 'http://bit.ly/13uffkf']]></sampleQuery>
<documentationURL></documentationURL>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
<url>{url}</url>
</urls>
<inputs>
<key id="url" type="xs:string" required="true" paramType="variable" />
</inputs>
<execute><![CDATA[
var resp = y.rest(url).head();
var status = parseInt(resp.status);
var max_redirects = 1;
var redirects = 0;
while(status==301 || status==302 && redirects < max_redirects) {
redirects++;
resp = y.rest(resp.headers.location).head();
status = parseInt(resp.status);
}
response.object = {found: status==200?1:0/*, status: status, redirects: redirects, resp: resp*/ };
]]></execute>
</select>
</bindings>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment