Created
November 20, 2012 19:10
-
-
Save nicksloan/4120305 to your computer and use it in GitHub Desktop.
Subclass AWSQueryConnection and define a _required_auth_capability(self) function returns a list which includes the unique capability of the desired auth handler plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AWISQueryConnection(AWSQueryConnection): | |
def _required_auth_capability(self): | |
return ['sign-v2'] | |
def alexa_rank(url): | |
conn = AWISQueryConnection( | |
aws_access_key_id=config.aws['key'], | |
aws_secret_access_key=config.aws['secret'], | |
host='awis.amazonaws.com', | |
is_secure=False, | |
debug=1) | |
conn.APIVersion = '2005-07-11' | |
conn.SignatureVersion = '2' | |
response = conn.make_request('UrlInfo', params={ | |
'Url': url, | |
'ResponseGroup': 'ContactInfo,Rank,LinksInCount' | |
}) | |
res = response.read() | |
dom = xml.dom.minidom.parseString(res) | |
od = {} | |
od['links'] = self._get_text(dom, "aws:LinksInCount") | |
od['rank'] = self._get_text(dom, "aws:Rank") | |
od['phone'] = self._get_text(dom, "aws:PhoneNumber") | |
od['email'] = self._get_text(dom, "aws:Email") | |
od['rank'] = self._get_text(dom, "aws:Rank") | |
od['name'] = self._get_text(dom, "aws:OwnerName") | |
od['street'] = self._get_text(dom, "aws:Street") | |
od['city'] = self._get_text(dom, "aws:City") | |
od['state'] = self._get_text(dom, "aws:State") | |
od['zip'] = self._get_text(dom, "aws:PostalCode") | |
od['country'] = self._get_text(dom, "aws:Country") | |
if od['rank'] is None: | |
return 0 | |
return int(od['rank']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment