def get_next_ad(self): if len(self._adList) > 0: entry = self._adList.pop() self._adList.insert(0,entry) evt = AdImpressionEvent(entry=entry, demographics=self.demographics) wx.PostEvent(self, evt) adlink = entry.get('link', '') if hasattr(self,'demographics') and hasattr(self.demographics,'location'): # We have the demographics, so pop it into the # current query, if it exists. adlink = urlutil.addQueryParamsToUri( adlink, {'o' : self.demographics.location } ) desc = None for cont in entry.get('content', []): desc = cont.get('value', None) if desc: break if desc is None: desc = entry.get('summary', '') return { 'title': entry.get('title', ''), 'description': desc, 'link': adlink } else: return defaultads.selectAd(defaultads.defaultAdList)
def update_ads_worker(self, input): print "updating ads" feedUrl, locUri, demographics, lat, lng = input if lat and lng: feedUrl = urlutil.addQueryParamsToUri( feedUrl, {'lat' : lat, 'lng' : lng } ) elif demographics and demographics.has_key('affiliations'): # use demographics to find the lat & lng # and set the lat and lng for affiliation in demographics['affiliations']: try: nid, name, type = affiliation tmp_uri = urlutil.addQueryParamsToUri(locUri, { 'nid': nid, 'name': name, 'type': type }) resp = urllib2.urlopen(tmp_uri) body = resp.read() lat, lng = body.split(',') feedUrl = urlutil.addQueryParamsToUri( feedUrl, {'lat' : lat, 'lng' : lng } ) break except Exception, e: # urlopen throws exception on 404, or any problems print e