1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- encoding: utf-8 -*- |
3
|
|
|
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8: |
4
|
|
|
# Author: Binux<[email protected]> |
5
|
|
|
# http://binux.me |
6
|
|
|
# Created on 2014-10-11 18:40:03 |
7
|
|
|
|
8
|
|
|
# result schema |
9
|
|
|
{ |
10
|
|
|
'result': { |
11
|
|
|
'taskid': str, # new, not changeable |
12
|
|
|
'project': str, # new, not changeable |
13
|
|
|
'url': str, # new, not changeable |
14
|
|
|
'result': str, # json string |
15
|
|
|
'updatetime': int, |
16
|
|
|
} |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class ResultDB(object): |
21
|
|
|
|
22
|
|
|
""" |
23
|
|
|
database for result |
24
|
|
|
""" |
25
|
|
|
projects = set() # projects in resultdb |
26
|
|
|
|
27
|
|
|
def save(self, project, taskid, url, result): |
28
|
|
|
raise NotImplementedError |
29
|
|
|
|
30
|
|
|
def select(self, project, fields=None, offset=0, limit=None): |
31
|
|
|
raise NotImplementedError |
32
|
|
|
|
33
|
|
|
def count(self, project): |
34
|
|
|
raise NotImplementedError |
35
|
|
|
|
36
|
|
|
def get(self, project, taskid, fields=None): |
37
|
|
|
raise NotImplementedError |
38
|
|
|
|
39
|
|
|
def drop(self, project): |
40
|
|
|
raise NotImplementedError |
41
|
|
|
|
42
|
|
|
def copy(self): |
43
|
|
|
''' |
44
|
|
|
database should be able to copy itself to create new connection |
45
|
|
|
|
46
|
|
|
it's implemented automatically by pyspider.database.connect_database |
47
|
|
|
if you are not create database connection via connect_database method, |
48
|
|
|
you should implement this |
49
|
|
|
''' |
50
|
|
|
raise NotImplementedError |
51
|
|
|
|