-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathexample.py
83 lines (76 loc) · 2.65 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from client import DiffbotClient,DiffbotCrawl
from config import API_TOKEN
import pprint
import time
print("Calling article API endpoint on the url: http://shichuan.github.io/javascript-patterns/...\n")
diffbot = DiffbotClient()
token = API_TOKEN
url = "http://shichuan.github.io/javascript-patterns/"
api = "article"
response = diffbot.request(url, token, api)
print("\nPrinting response:\n")
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(response))
print()
print("Calling article API endpoint with fields specified on the url: http://shichuan.github.io/javascript-patterns/...\n")
diffbot = DiffbotClient()
token = API_TOKEN
url = "http://shichuan.github.io/javascript-patterns/"
api = "article"
response = diffbot.request(url, token, api, fields=['title', 'type'])
print("\nPrinting response:\n")
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(response))
print()
print("Calling frontpage API endpoint on the url: http://www.huffingtonpost.com/...\n")
diffbot = DiffbotClient()
token = API_TOKEN
url = "http://www.huffingtonpost.com/"
api = "frontpage"
response = diffbot.request(url, token, api)
print("\nPrinting response:\n")
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(response))
print()
print("Calling product API endpoint on the url: http://www.overstock.com/Home-Garden/iRobot-650-Roomba-Vacuuming-Robot/7886009/product.html...\n")
diffbot = DiffbotClient()
token = API_TOKEN
url = "http://www.overstock.com/Home-Garden/iRobot-650-Roomba-Vacuuming-Robot/7886009/product.html"
api = "product"
response = diffbot.request(url, token, api)
print("\nPrinting response:\n")
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(response))
print()
print("Calling image API endpoint on the url: http://www.google.com/...\n")
diffbot = DiffbotClient()
token = API_TOKEN
url = "http://www.google.com/"
api = "image"
response = diffbot.request(url, token, api)
print("\nPrinting response:\n")
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(response))
print()
print("Calling classifier API endpoint on the url: http://www.twitter.com/...\n")
diffbot = DiffbotClient()
token = API_TOKEN
url = "http://www.twitter.com/"
api = "analyze"
response = diffbot.request(url, token, api)
print("\nPrinting response:\n")
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(response))
print("Create a new crawl of http://support.diffbot.com/ using the Article API...\n")
token = API_TOKEN
seeds = "http://support.diffbot.com"
api = "article"
name = "testCrawl"
diffbot = DiffbotCrawl(token, name, seeds=seeds, api=api)
time.sleep(5)
status = diffbot.status()
print("\nPrinting status:\n")
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(status))
print("\nDeleting test crawl.\n")
diffbot.delete()