usestudiodatabase.py 934 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. __author__ = 'cwh'
  3. # 使用DBUtils连接数据库的方法,比twisted简单很多。
  4. import MySQLdb
  5. from DBUtils.PooledDB import PooledDB
  6. #api.1473.cn在数据库中的站点地图数据
  7. class ApiSitemapData(object):
  8. def __init__(self):
  9. self.pool = PooledDB(MySQLdb,5,host='10.20.5.88',user='root',passwd='usestudio-1',db='US_Crawler',port=14062,charset="utf8")
  10. def selectData(self):
  11. conn = self.pool.connection()
  12. cur = conn.cursor()
  13. # 调用存储过程示例
  14. #cur.callproc('InsertAPIData', ('1000','张三'))
  15. # 存储过程传递参数
  16. #cur.callproc('InsertAPIData', (item['name'],item['name']))
  17. cur.callproc('SiteMapData',())
  18. _tuples= cur._cursor._rows
  19. #for t in _tuples:
  20. # print(t)
  21. # print out the result
  22. cur.close()
  23. conn.commit()
  24. conn.close()
  25. return _tuples