def endpoint(self, request): logger.debug('client from %s requested: %s' % (request.remote_addr, request.params)) if 'api' not in request.GET: raise HTTPBadRequest() result = Struct({'api_version': API_VERSION, 'auth': 0}) if 'api_key' in request.POST: api_key = request.POST['api_key'] user = User.validate_api_key(api_key) if not user: logger.warn('unknown API key %s, unauthorized' % api_key) return self.respond_with_json(result) else: logger.warn('missing API key, unauthorized') return self.respond_with_json(result) # Authorized result.auth = 1 # It looks like client *can* send multiple commands at time for command, handler in COMMANDS: if command in request.params: handler(request, user, result) result.last_refreshed_on_time = get_last_refreshed_on_time() return self.respond_with_json(result)
def endpoint(self, request): logger.debug('client from %s requested: %s' % (request.remote_addr, request.params)) if 'api' not in request.GET: raise HTTPBadRequest() result = Struct({'api_version':API_VERSION, 'auth':0}) if 'api_key' in request.POST: api_key = request.POST['api_key'] user = User.validate_api_key(api_key) if not user: logger.warn('unknown API key %s, unauthorized' % api_key) return self.respond_with_json(result) else: logger.warn('missing API key, unauthorized') return self.respond_with_json(result) # Authorized result.auth = 1 # It looks like client *can* send multiple commands at time for command, handler in COMMANDS: if command in request.params: handler(request, user, result) result.last_refreshed_on_time = get_last_refreshed_on_time() return self.respond_with_json(result)
def google_fetcher(url): """ Fetch the favicon via Google services """ endpoint = "http://www.google.com/s2/favicons?domain=%s" % urlparse.urlparse(url).hostname # headers = { # 'User-Agent': config.get('fetcher', 'user_agent') # } try: result = requests.get(endpoint) except RequestException, exc: logger.warn("could not fetch favicon for %s (%s)" % (url, exc)) return DEFAULT_FAVICON
return q = Entry.select(Entry).join(Feed).join(Subscription).where( (Subscription.user == user) & (Subscription.feed == feed) & # Exclude entries already marked as read ~(Entry.id << Read.select(Read.entry).where(Read.user == user)) & # Exclude entries fetched after last sync (Entry.last_updated_on < before)).distinct().naive() with transaction(): for entry in q: try: Read.create(user=user, entry=entry) except IntegrityError: # Should not happen, due to the query above, log as warning logger.warn('entry %d already marked as read, ignored' % entry.id) continue logger.debug('marked feed %d as %s' % (object_id, status)) elif mark == 'group' and status == 'read': # Unix timestamp of the the local client’s 'last items' API request try: before = datetime.utcfromtimestamp(int(request.POST['before'])) except (KeyError, ValueError), ex: logger.debug('missing or invalid parameter (%s), ignored' % ex) return # Mark all as read? if object_id == 0:
q = Entry.select(Entry).join(Feed).join(Subscription).where( (Subscription.user == user) & (Subscription.feed == feed) & # Exclude entries already marked as read ~(Entry.id << Read.select(Read.entry).where(Read.user == user)) & # Exclude entries fetched after last sync (Entry.last_updated_on < before) ).distinct().naive() with transaction(): for entry in q: try: Read.create(user=user, entry=entry) except IntegrityError: # Should not happen, due to the query above, log as warning logger.warn('entry %d already marked as read, ignored' % entry.id) continue logger.debug('marked feed %d as %s' % (object_id, status)) elif mark == 'group' and status == 'read': # Unix timestamp of the the local client’s 'last items' API request try: before = datetime.utcfromtimestamp(int(request.POST['before'])) except (KeyError, ValueError), ex: logger.debug('missing or invalid parameter (%s), ignored' % ex) return # Mark all as read?