Skip to content

Instantly share code, notes, and snippets.

@ahmadkakarr
Forked from scturtle/feedly.py
Created June 16, 2017 19:49
Show Gist options
  • Save ahmadkakarr/68d8aea42d02f31bf5719e93a79e8b1c to your computer and use it in GitHub Desktop.
Save ahmadkakarr/68d8aea42d02f31bf5719e93a79e8b1c to your computer and use it in GitHub Desktop.
python scripts for feedly
import re
import json
import requests
URL_TO_SAVE = ('https://feedly.com/v3/streams/contents?'
'streamId=user%2F{}%2Ftag%2Fglobal.saved&count=100')
HEADERS = dict(l.strip().split(': ') for l in open('headers.txt').readlines()
if len(l.strip()))
USERID = re.search(r'"feedlyId":"([^"]+)"', HEADERS['Cookie']).group(1)
def get_saved(c=None):
URL = URL_TO_SAVE.format(USERID)
if c:
URL += '&continuation=' + c
data = requests.get(URL, headers=HEADERS).json()
assert 'items' in data, 'ERROR in fatching data.'
return data['items'], data.get('continuation', None)
def get_all_saved():
items, c = get_saved()
while c:
more, c = get_saved(c)
items += more
return items
if __name__ == '__main__':
items = get_all_saved()
json.dump(items, open('stared.json', 'w'), indent=2)
# for i, item in enumerate(items):
# print i, item['title'].replace('\n', '')[:20].encode('utf8')
Authorization: OAuth XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:feedly
Cookie: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# coding: utf-8
import json
from Tkinter import *
import tkFileDialog
from bs4 import BeautifulSoup
root = Tk()
e = StringVar()
li, te, data, items = [None] * 4
sanitize_all_html = lambda value: BeautifulSoup(value).get_text()
def selectFile():
global data, items
filename = tkFileDialog.askopenfilename(parent=root, initialdir='.',
filetypes=[('data', '.json')])
data = json.load(open(filename))
items = data['items'] if 'items' in data else data
items = [i for i in items if 'title' in i]
filterItems()
def filterItems(event=None):
li.delete(0, END)
s = e.get()
for i in items:
title = i['title']
content = (('summary' in i and i['summary']['content']) or
('content' in i and i['content']['content']) or '')
if s in title or s in content:
li.insert(END, title)
def showItemInfo(event=None):
te.delete(1.0, END)
title = li.get(li.curselection())
item = (i for i in items if i['title'] == title).next()
te.insert(1.0, item['title'] + '\n')
te.insert(2.0, ('author' in item and item['author'] or 'NO AUTHOR') + '\n')
te.insert(3.0, item['origin']['title'] + '\n')
te.insert(4.0, item['origin']['htmlUrl'] + '\n')
te.insert(5.0, ('alternate' in item and item['alternate'][0]['href']
or 'NO URL') + '\n\n')
content = (('summary' in item and item['summary']['content']) or
('content' in item and item['content']['content']) or '')
te.insert(7.0, sanitize_all_html(content) + '\n')
f = Frame(root)
lf = Frame(f)
rf = Frame(f)
f.pack(fill='both', expand=1)
lf.pack(side='left', fill='both')
rf.pack(side='left', fill='both', expand=1)
fbt = Button(lf, text="Select file", height=1, command=selectFile)
fbt.pack(side='top', fill=X)
en = Entry(lf, textvariable=e, width=30)
en.bind('<Return>', filterItems)
en.pack(side='top', fill=X)
liy = Scrollbar(lf, orient=VERTICAL)
li = Listbox(lf, yscrollcommand=liy.set)
li.bind('<<ListboxSelect>>', showItemInfo)
liy['command'] = li.yview
li.pack(side='left', fill='both', expand=1)
liy.pack(side='left', fill=Y)
tey = Scrollbar(rf, orient=VERTICAL)
te = Text(rf, yscrollcommand=tey.set, height=30,
font=('Microsoft Yahei', '12'))
tey['command'] = te.yview
te.pack(side='left', fill='both', expand=1)
tey.pack(side='left', fill=Y)
root.title('JSON viewer')
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment