Created
April 28, 2011 17:21
-
-
Save sli/946798 to your computer and use it in GitHub Desktop.
Simple Python Adf.ly API (old, use if you want)
This file contains hidden or 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
import urllib | |
class Adfly: | |
def __init__(self, api_key, uid): | |
self.api_key = api_key | |
self.uid = uid | |
self.domain = 'adf.ly' | |
self.ad_type = 'int' | |
def get_url(self, url, domain=None, ad_type=None): | |
if domain is not None and domain not in ('adf.ly','9.bb'): | |
raise ValueError, 'domain must be \'adf.ly\' or \'9.bb\'' | |
else: | |
self.domain = domain | |
if ad_type is not None and ad_type not in ('int','banner'): | |
raise ValueError, 'ad type must be \'int\' or \'banner\'' | |
else: | |
self.ad_type = ad_type | |
url = urllib.quote_plus(url) | |
s = urllib.urlopen('http://api.adf.ly/api.php?key=%s&uid=%s&advert_type=%s&domain=%s&url=%s' % (self.api_key, self.uid, self.ad_type, self.domain, url)) | |
res = s.read() | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment