Skip to content
This repository has been archived by the owner on Aug 14, 2019. It is now read-only.

JeremyGrosser/python-digg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Digg brand is no longer operated by the same company and the API this client serves hasn't existed for years. This repository is for historical purposes only.

Installing

# easy_install http://github.com/downloads/synack/python-digg/python-digg-1.2.tar.gz

easy_install will download and install python-digg and all of the required dependencies on it's own.

Required dependencies

Optional dependencies

Usage

Simple example

from digg.api import Digg
digg = Digg()

for story in digg.story.getPopular(count=20, topic='apple')['stories']:
	print story['title']
	print '%i diggs, %i comments' % (story['diggs'], story['comments'])

Caching example

from digg.api import Digg
import memcache

cache = memcache.Client(['127.0.0.1:11211'])
digg = Digg(cache=cache)

OAuth example

Digg's API requires an OAuth access token in order to authenticate a user with certain methods (eg. story.digg). Note that this procedure is subject to change in future releases, especially the ugly parse_qs nonsense.

from urlparse import parse_qs
import sys

from oauth2 import Consumer, Token
from digg.api import Digg

consumer = Consumer(key='myoauthconsumerkey', secret='myoauthconsumersecret')
digg = Digg(oauth_consumer=consumer)

response = digg.oauth.getRequestToken(oauth_callback='oob')
request_token = parse_qs(response)
print 'Please visit the following URL to authorize this application'
print 'http://digg.com/oauth/authorize?oauth_token=%s' % request_token['oauth_token'][0]

sys.stdout.write('Type the verification number: ')
verifier = sys.stdin.readline().rstrip('\r\n')

request_token = Token(request_token['oauth_token'][0], request_token['oauth_token_secret'][0])
request_token.set_verifier(verifier)

response = digg.oauth.getAccessToken(oauth_token=request_token)
response = parse_qs(response)

access_token = Token(response['oauth_token'][0], response['oauth_token_secret'][0])

print digg.oauth.verify(oauth_token=access_token)

print digg.story.digg(id=22091157, oauth_token=access_token)

About

Python client implementation for Digg's new writable API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages