def popular(section_id = None): results = Configuration.query(Configuration.key == "OPHAN_API_KEY") if not results.iter().has_next(): return None ophan_api_key = results.iter().next().value logging.info(ophan_api_key) most_read_url = "http://api.ophan.co.uk/api/mostread" if section_id: most_read_url = most_read_url + "/" + section_id params = {'age' : FIFTEEN_MINUTES, 'api-key' : ophan_api_key} most_read_url = most_read_url + "?" + urllib.urlencode(params) logging.info(most_read_url) result = fetch(most_read_url) if result.status_code == 200: return result.content logging.error("Ophan read failed with status code %d" % result.status_code) return None
def popular_by_country(country_code="gb", hours="1", section_id=None, referrer=None): results = Configuration.query(Configuration.key == "OPHAN_API_KEY") if not results.iter().has_next(): return None ophan_api_key = results.iter().next().value #logging.info(ophan_api_key) most_read_url = "http://api.ophan.co.uk/api/mostread" if section_id: most_read_url = most_read_url + "/" + section_id params = {'hours' : hours, 'country' : country_code, 'api-key' : ophan_api_key, } if referrer: params['referrer'] = referrer most_read_url = most_read_url + "?" + urllib.urlencode(params) #logging.info(most_read_url) result = fetch(most_read_url) if result.status_code == 200: return result.content logging.error("Ophan read failed with status code %d" % result.status_code) return None
def lookup(key): results = Configuration.query(Configuration.key == key) if not results.iter().has_next(): return None key_value = results.iter().next().value return key_value
def get(self): template = jinja_environment.get_template('admin/configuration.html') template_values = {} template_values['configuration'] = Configuration.query() self.response.out.write(template.render(template_values))
def lookup(key, default): results = Configuration.query(Configuration.key == key) if not results.iter().has_next(): return default key_value = results.iter().next().value return key_value
def lookup(key, default=None): results = Configuration.query(Configuration.key == key) if not results.iter().has_next(): return default key_value = results.iter().next().value logging.info(key_value) return key_value