Skip to content

Instantly share code, notes, and snippets.

@sli
Created April 28, 2011 17:21
Show Gist options
  • Save sli/946798 to your computer and use it in GitHub Desktop.
Save sli/946798 to your computer and use it in GitHub Desktop.
Simple Python Adf.ly API (old, use if you want)
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