Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Pythonista script to pull the first 50 items from your First Kindling Group from Fever RSS and display them in a nice format. Also allows for importing to Instapaper app, if you've got it. Original code courtesy Thomas Allen (look for the FeverBuddy git repo). Please note, there is a lot of redundant code here. Please don't worry. Pythonista d…
#!/usr/bin/env python
# encoding: utf-8
Created by Thomas Allen on 2010-06-04.
Copyright (c) 2010 __telega.org__. All rights reserved.
FeverBuddy for Pythonista
Modified by Nitin Khanna on 2013-01-04
No Copyrights. This is Github. I'll be sad if you don't steal this script.
import sys
import os
import getopt
import json
import hashlib
import urllib
import time
import webbrowser
import SimpleHTTPServer
import SocketServer
class FeverBuddy(Exception):
def __init__(self, msg):
self.msg = msg
def setEndpoint(self,endpoint):
#sets the endpoint of the fever installation ie. base directory
self.endpoint = "http://"+endpoint+"/?api"
#print "end point set to "+self.endpoint
def getEndpoint(self):
return self.endpoint
def setEmail(self,email): = email
#print "Email set to "
def getEmail(self):
def setPassword(self,password):
self.password = password
#print "password set to "+self.password
def getPassword(self):
return self.password
def setApiKey(self):
#creates the md5 hash from the email and password for POSTing to fever. Requried for Authentication.
self.apikey = {"api_key":hashlib.md5(str(self.getEmail())+':'+str(self.getPassword())).hexdigest()}
def getApiKey(self):
return self.apikey
def setParams(self,*params):
self.params = ""
for elem in params:
self.params = self.params + str(elem)
#print self.params
def getParams(self):
return self.params
def setDays(self,days):
self.days = days
def getDays(self):
return self.days
def setUrl(self):
self.url = str(self.getEndpoint())+str(self.getParams())
def getUrl(self):
return self.url
def getJson(self):
self.feverJson = json.load(urllib.urlopen(self.getUrl(),urllib.urlencode(self.getApiKey())))
#print self.feverJson
return self.feverJson
def getHotItems(self):
"get Hot Items from fever, returns a list"
storyque = []
myJson = self.getJson()
print myJson
x = 0
for links in myJson['links']:
temperature = str(round(myJson['links'][x]['temperature'],1))
#print temperature
ct = storyque.count(temperature)
#print ct
if ct > 0:
storyque.insert((storyque.index(temperature)+2),myJson['links'][x]['title']) #this is the line that inserts Title for items, need to include URL here
elif ct == 0:
storyque.append(myJson['links'][x]['title']) #this is the line that inserts Title for items, need to include URL here
return storyque
def printHotItems(self,storyque=[]):
"should be called in conjunction with getHotItems()"
for item in storyque:
print item.encode('utf8')
def getOneGroup(self):
"get Group One Items from fever"
myJson = self.getJson()
#print myJson
f=open('workfile.txt', 'w+')
json.dump(myJson, f)
indexfile = open('index.html', 'w+')
print >>indexfile, """<html><head><style>h1 {font-size:1em;} img {float:right;}</style><link href="//" rel="stylesheet"><script src="//"></script><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Group1</title></head><body><table border="1">"""
for item in myJson['items']:
print >>indexfile, """<tr><td><h1><a href=\"\">%s</a><a href=\"i%s\"><img src=''></a></h1></td></tr>""" % (item['url'].encode('utf8'), item['title'].encode('utf8'), item['url'].encode('utf8'))
print >>indexfile, """</table></body></html>"""
#Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
#httpd = SocketServer.TCPServer(("",8000), Handler)
#print os.path.abspath('index.html')'file:///'+os.path.abspath('index.html'))
def getGroups(self):
"get Hot Items from fever, returns a list"
storyque = []
myJson = self.getJson()
print myJson
for group in myJson['groups']:
# Insert a row of data
return storyque
def printGroups(self,storyque=[]):
"should be called in conjunction with getHotItems()"
for item in storyque:
print str(storyque.index(item))+": "+item.encode('utf8')
def getAllItems(self):
myJson = self.getJson()
lastMaxId = 0
print myJson
for item in myJson['items']:
lastMaxId = item['id']
while lastMaxId != 0:
myJson = self.getJson()
for item in myJson['items']:
lastMaxId = item['id']
def getLastRefresh(self):
myJson = self.getJson()
#time of last refresh
rtime = time.localtime(int(myJson["last_refreshed_on_time"]))
#current time
ntime = time.localtime()
#figure out roughly how many minutes ago
self.lastRefresh = ((ntime[0]-rtime[0])*525948) + ((ntime[3]-rtime[3])*60) +(ntime[4]-rtime[4])
return self.lastRefresh
def printLastRefresh(self):
print "Last Refresh: %d minutes ago" %self.getLastRefresh()
def main():
#default values for some options
verbose = False
hotitems = False
lastrefresh = False
groups = False
group1 = False
#create a fb item
fb = FeverBuddy("FeverBuddy")
#Edit the Endpoint, email and password
group1 = True
#take action
if hotitems == True:
elif lastrefresh == True:
elif groups == True:
elif group1 == True:
#set the group ID to some other number for other Kindling Groups
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
except FeverBuddy, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, "\t for help use --help"
return 2
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment