-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
84 lines (65 loc) · 1.82 KB
/
Copy pathtest.py
File metadata and controls
84 lines (65 loc) · 1.82 KB
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
84
# -*- coding: utf-8 -*-
'''
Created on 2011-10-8
@author: qianmu.lxj
'''
from jobs.CyeFilterInc import JingdongFilter
from jobs.models import cyeTbReflector, CyeTbRow
from libs.cyetools import cyeDBpoool, testCyecursor
from twisted.enterprise import reflector
import random
import time
#from mypython.a import add_func
def onInsert(data):
print 'completed'
print data
def gotCye(datas):
for data in datas:
print "Got:", data.id
def getCyeData():
return
def printResult(l):
print 'printResult'
if l:
print l
else:
print "No such data"
def _insert(tx, item):
tx.exectue("select * from cye_db")
result = tx.fetchone()
print result
if result:
print result
def handle_error(e):
print e
def getData():
print 'getData'
query = cyeDBpoool.runInteraction(_insert)
query.addErrback(handle_error)
return query
if __name__ == '__main__':
'''
fp = open('detail.dat')
html = fp.read()
fp.close()
detail = JingdongFilter.handleDetail(html)
'''
#print detail
newItem = CyeTbRow()
newItem.assignKeyAttr('id', '')
newItem.key = 'test'+str(random.randint(1, 999))
newItem.title = 'test'
newItem.url = 'url'
newItem.product_img_url = 'product_img_url'
newItem.product_img = 'product_img'
newItem.detail = 'detail'
newItem.utime = time.strftime('%Y-%m-%d %X', time.localtime())
cyeTbReflector.insertRow(newItem).addCallback(onInsert)
d = cyeTbReflector.loadObjectsFrom("cye_tb")
d.addCallback(gotCye)
print 'hello'
cyeDBpoool.runQuery("SELECT * FROM cye_tb").addCallback(printResult)
count = testCyecursor.execute('SELECT * FROM cye_tb')
print count
getData().addBoth(printResult)
pass