Skip to content

Commit 11c736b

Browse files
committed
Updated README and added some more example calls
1 parent 44f4cd4 commit 11c736b

File tree

2 files changed

+121
-17
lines changed

2 files changed

+121
-17
lines changed

README.md

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
Python Diffbot API Client
2-
=========
1+
#Python Diffbot API Client
32

4-
Currently supports calls to the article endpoint.
3+
4+
##Preface
5+
Identify and extract the important parts of any web page in Python! This client currently supports calls to the automatic APIs.
56

67

78
Installation
8-
-----------
99
To install activate a new virtual environment and run the following command:
1010

1111
$ pip install -r requirements.txt
1212

13+
##Configuration
14+
1315
To run the example, you must first configure a working API token in config.py:
1416

1517
$ cp config.py.example config.py; vim config.py;
@@ -18,27 +20,75 @@ Then replace the string "SOME_TOKEN" with your API token. Finally, to run the e
1820

1921
$ python example.py
2022

21-
Example use
22-
--------------
23-
An example of how to use the client in your code:
23+
##Usage
24+
25+
###Article API
26+
An example call to the Article API:
2427

2528
```
2629
diffbot = DiffbotClient()
30+
token = "SOME_TOKEN"
31+
version = 2
2732
url = "http://shichuan.github.io/javascript-patterns/"
28-
token = "YOUR_TOKEN_HERE"
2933
api = "article"
34+
response = diffbot.request(url, token, api, version=2)
35+
```
36+
37+
###Frontpage API
38+
An example call to the Frontpage API:
39+
40+
```
41+
diffbot = DiffbotClient()
42+
token = "SOME_TOKEN"
3043
version = 2
44+
url = "http://www.huffingtonpost.com/"
45+
api = "frontpage"
46+
response = diffbot.request(url, token, api, version=version)
47+
```
48+
49+
###Product API
50+
An example call to the Product API:
3151

32-
response = diffbot.request(url, token, api, version=2)
3352
```
53+
diffbot = DiffbotClient()
54+
token = "SOME_TOKEN"
55+
version = 2
56+
url = "http://www.overstock.com/Home-Garden/iRobot-650-Roomba-Vacuuming-Robot/7886009/product.html"
57+
api = "product"
58+
response = diffbot.request(url, token, api, version=version)
59+
```
60+
61+
###Image API
62+
An example call to the Image API:
63+
64+
```
65+
diffbot = DiffbotClient()
66+
token = "SOME_TOKEN"
67+
version = 2
68+
url = "http://www.google.com/"
69+
api = "image"
70+
response = diffbot.request(url, token, api, version=version)
71+
```
72+
73+
###Classifier API
74+
An example call to the Classifier API:
75+
76+
```
77+
diffbot = DiffbotClient()
78+
token = "SOME_TOKEN"
79+
version = 2
80+
url = "http://www.twitter.com/"
81+
api = "analyze"
82+
response = diffbot.request(url, token, api, version=version)
83+
```
84+
3485

35-
Testing
36-
------------
86+
##Testing
3787

3888
First install the test requirements with the following command:
3989

4090
$ pip install -r test_requirements.txt
4191

42-
Unit and functional tests are configured to run using nose. From the project directory, simply run:
92+
Currently there are some simple unit tests that mock the API calls and return data from fixtures in the filesystem. From the project directory, simply run:
4393

44-
$ nosetests
94+
$ nosetests

example.py

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,74 @@
22
from config import API_TOKEN
33
import pprint
44

5+
6+
print "Calling article API endpoint on the url: http://shichuan.github.io/javascript-patterns/...\n"
57
diffbot = DiffbotClient()
6-
url = "http://shichuan.github.io/javascript-patterns/"
78
token = API_TOKEN
8-
api = "article"
99
version = 2
10-
11-
print "Calling article API endpoint on the url: http://shichuan.github.io/javascript-patterns/...\n"
10+
url = "http://shichuan.github.io/javascript-patterns/"
11+
api = "article"
1212
response = diffbot.request(url, token, api, version=2)
1313
print "\nPrinting response:\n"
1414
pp = pprint.PrettyPrinter(indent=4)
1515
print pp.pprint(response)
1616

17+
print
1718
print "Calling article API endpoint with fields specified on the url: http://shichuan.github.io/javascript-patterns/...\n"
19+
diffbot = DiffbotClient()
20+
token = API_TOKEN
21+
version = 2
22+
url = "http://shichuan.github.io/javascript-patterns/"
23+
api = "article"
1824
response = diffbot.request(url, token, api, fields=['title', 'type'], version=2)
1925
print "\nPrinting response:\n"
2026
pp = pprint.PrettyPrinter(indent=4)
2127
print pp.pprint(response)
28+
29+
print
30+
print "Calling frontpage API endpoint on the url: http://www.huffingtonpost.com/...\n"
31+
diffbot = DiffbotClient()
32+
token = API_TOKEN
33+
version = 2
34+
url = "http://www.huffingtonpost.com/"
35+
api = "frontpage"
36+
response = diffbot.request(url, token, api, version=version)
37+
print "\nPrinting response:\n"
38+
pp = pprint.PrettyPrinter(indent=4)
39+
print pp.pprint(response)
40+
41+
print
42+
print "Calling product API endpoint on the url: http://www.overstock.com/Home-Garden/iRobot-650-Roomba-Vacuuming-Robot/7886009/product.html...\n"
43+
diffbot = DiffbotClient()
44+
token = API_TOKEN
45+
version = 2
46+
url = "http://www.overstock.com/Home-Garden/iRobot-650-Roomba-Vacuuming-Robot/7886009/product.html"
47+
api = "product"
48+
response = diffbot.request(url, token, api, version=version)
49+
print "\nPrinting response:\n"
50+
pp = pprint.PrettyPrinter(indent=4)
51+
print pp.pprint(response)
52+
53+
print
54+
print "Calling image API endpoint on the url: http://www.google.com/...\n"
55+
diffbot = DiffbotClient()
56+
token = API_TOKEN
57+
version = 2
58+
url = "http://www.google.com/"
59+
api = "image"
60+
response = diffbot.request(url, token, api, version=version)
61+
print "\nPrinting response:\n"
62+
pp = pprint.PrettyPrinter(indent=4)
63+
print pp.pprint(response)
64+
65+
print
66+
print "Calling classifier API endpoint on the url: http://www.twitter.com/...\n"
67+
diffbot = DiffbotClient()
68+
token = API_TOKEN
69+
version = 2
70+
url = "http://www.twitter.com/"
71+
api = "analyze"
72+
response = diffbot.request(url, token, api, version=version)
73+
print "\nPrinting response:\n"
74+
pp = pprint.PrettyPrinter(indent=4)
75+
print pp.pprint(response)

0 commit comments

Comments
 (0)