Skip to content

Instantly share code, notes, and snippets.

@oparrish
Created February 10, 2015 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oparrish/5f718ce97fd389fcf29c to your computer and use it in GitHub Desktop.
Save oparrish/5f718ce97fd389fcf29c to your computer and use it in GitHub Desktop.
Outputs current unread count, feed title, and publish date of last read item in your Feed Wrangler account
import requests
import json
import time
import sys
def get_feed(access_token, feed_id, offset=0, limit=1000, read='false', published_since='1'):
feed_payload = {'access_token': access_token, 'read': read, 'feed_id': feed_id, 'offset': offset, 'published_since': published_since, 'limit': limit}
feed_r = requests.get('https://feedwrangler.net/api/v2/feed_items/list_ids', params=feed_payload)
feed_data = json.loads(feed_r.text)
return feed_data
email = sys.argv[1]
password = sys.argv[2]
client_key = sys.argv[3] # Get yours here: https://feedwrangler.net/developers/clients
# Get the access token and feeds
auth_payload = {'email': email, 'password': password, 'client_key': client_key}
auth_r = requests.get('https://feedwrangler.net/api/v2/users/authorize', params=auth_payload)
auth_data = json.loads(auth_r.text)
access_token = auth_data['access_token']
feeds = auth_data['feeds']
for feed in feeds:
title = feed['title']
feed_id = feed['feed_id']
total_unread_count = 0
current_page_count = 0
offset = 0
feed_data = get_feed(access_token, feed_id, offset)
current_page_count = feed_data['count']
total_unread_count = total_unread_count + current_page_count
while current_page_count >= 1000:
offset = offset + current_page_count
feed_data = get_feed(access_token, feed_id, offset)
current_page_count = feed_data['count']
total_unread_count = total_unread_count + current_page_count
# Get the last read item's published data
feed_data = get_feed(access_token=access_token, feed_id=feed_id, offset=0, limit=1, read='true')
for feed_item in feed_data['feed_items']:
published_date_of_last_read_item = feed_item['published_at']
# Pipe delimited output:
# Unread count|Feed title|Publish date of last read item
print "{}|{}|{}".format(total_unread_count, title.encode('utf-8'), time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(published_date_of_last_read_item)))
logout_payload = {'access_token': access_token}
logout_r = requests.get('https://feedwrangler.net/api/v2/users/logout', params=logout_payload)
# Sort output by last read item, oldest at bottom: sort -t\| -k3.1,3.4rn -k3.6,3.7rn -k3.9,3.10rn -k1rn
# Sort output by number unread, most at bottom: sort -t\| -k1rn -k3.1,3.4rn -k3.6,3.7rn -k3.9,3.10rn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment