Created
August 15, 2013 17:28
-
-
Save macolyte/6242784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from os.path import expanduser | |
from urllib import request | |
from urllib import parse | |
import json | |
import sys | |
API_URL = "https://feedwrangler.net/api/v2/" | |
EMAIL = "[email protected]" | |
PASS = "supersecretpassword" | |
KEY = "feedwranglerapikey" | |
def get_json(url): | |
req = request.urlopen(url) | |
encoding = req.headers.get_content_charset() | |
data = json.loads(req.read().decode(encoding)) | |
if data['result'] == 'success': | |
return data | |
else: | |
print("Something went wrong") | |
return | |
def get_auth(email=EMAIL, password=PASS, key=KEY): | |
email = parse.quote(email) | |
password = parse.quote(password) | |
auth_url = "%susers/authorize?email=%s&password=%s&client_key=%s" % (API_URL, email, password, key) | |
auth = get_json(auth_url) | |
if auth: | |
return auth['access_token'] | |
def list_unread_items(token): | |
feed_url = "%s/feed_items/list?access_token=%s&read=false" % (API_URL, token) | |
feeds = get_json(feed_url) | |
if feeds: | |
for feed in enumerate(feeds['feed_items']): | |
print("%d: %s\t%s" % (feed[0], feed[1]['feed_name'], feed[1]['title'])) | |
def get_unread_count(token): | |
feed_url = "%s/feed_items/list?access_token=%s&read=false" % (API_URL, token) | |
feeds = get_json(feed_url) | |
if feeds: | |
print(feeds['count']) | |
def mark_all_read(token): | |
read_url = "%s/feed_items/mark_all_read?access_token=%s" % (API_URL, token) | |
all_read = get_json(read_url) | |
if all_read: | |
print("All feeds marked as read") | |
def add_feed(token, feed_url): | |
feed_url = parse.quote(feed_url) | |
add_feed_url = "%ssubscriptions/add_feed?access_token=%s&feed_url=%s" % (API_URL, token, feed_url) | |
add_feed = get_json(add_feed_url) | |
if add_feed: | |
print("Feed added") | |
if __name__ == '__main__': | |
TOKEN = get_auth() | |
if sys.argv[1] == "mark": | |
mark_all_read(TOKEN) | |
elif sys.argv[1] == "list": | |
list_unread_items(TOKEN) | |
elif sys.argv[1] == "add": | |
add_feed(TOKEN, sys.argv[2]) | |
else: | |
get_unread_count(TOKEN) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment