代码拉取完成,页面将自动刷新
同步操作将从 元谷/pydht 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# -*- coding: cp936 -*-
import time
import psycopg2
import Queue,threading
from seedAnalyse import SeedAnalyse
def btInfoSave(hash_id):
conn= psycopg2.connect(host="localhost",user="postgres",password="123456",dbname="dht")
cursor = conn.cursor()
sql = "select * from bt where hash= '" + hash_id + "'"
#param = (hash_id)
try:
cursor.execute(sql)
except Exception,ex:
print Exception,":",ex
return
if cursor.fetchone(): return #存在数据
#分析数据
s = SeedAnalyse()
seed = s.analyse(hash_id)
if not seed: return
info = seed['info']
name = info['name']
sql = "INSERT INTO bt(hash,name) values (%s,%s)"
param = (hash_id, name )
try:
cursor.execute(sql,param)
except Exception,ex:
print Exception,":",ex
return
conn.commit()
sql = "select * from bt where hash='" + hash_id + "'"
cursor.execute(sql)
nid = cursor.fetchone()[0]
lenght = 0
if 'files' in info:
for nfile in info['files']:
lenght = nfile['length']
name = nfile['path']
sql = "INSERT INTO file(name,size,btid) values (%s,%s,%s)"
param = ( name, str(lenght), str(nid))
try:
cursor.execute(sql,param)
except Exception,ex:
print Exception,":",ex
return
else:
lenght = info['length']
sql = "INSERT INTO file(name,size,btid) values (%s,%s,%s)"
param = ( name, str(lenght), str(nid))
try:
cursor.execute(sql,param)
except Exception,ex:
print Exception,":",ex
return
conn.commit()
conn.close()
class DbThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.conn= psycopg2.connect(host="localhost",user="postgres",password="123456",dbname="dht")
self.cursor = self.conn.cursor()
self.queue = Queue.Queue()
def run(self):
while True:
if self.queue.qsize()> 0:
hash_id = self.queue.get()
btInfoSave(hash_id)
else:
time.sleep(1)
def put(self, hash_id):
self.queue.put(hash_id)
def __btInfoSave(self, hash_id):
sql = "select * from bt where hash= '" + hash_id + "'"
cursor = self.cursor
conn = self.conn
try:
cursor.execute(sql)
except Exception,ex:
print Exception,"line86:",ex
return
if cursor.fetchone(): return #存在数据
#分析数据
s = SeedAnalyse()
seed = s.analyse(hash_id)
if not seed: return
info = seed['info']
name = info['name']
sql = "INSERT INTO bt(hash,name) values (%s,%s)"
param = (hash_id, name )
try:
cursor.execute(sql,param)
conn.commit()
except Exception,ex:
print Exception,":",ex
return
sql = "select * from bt where hash='" + hash_id + "'"
cursor.execute(sql)
nid = cursor.fetchone()[0]
conn.commit()
lenght = 0
if 'files' in info:
for nfile in info['files']:
lenght = nfile['length']
name = nfile['path']
sql = "INSERT INTO file(name,size,btid) values (%s,%s,%s)"
param = ( name, str(lenght), str(nid))
try:
cursor.execute(sql,param)
conn.commit()
except Exception,ex:
print Exception,":",ex
return
else:
lenght = info['length']
sql = "INSERT INTO file(name,size,btid) values (%s,%s,%s)"
param = ( name, str(lenght), str(nid))
try:
cursor.execute(sql,param)
conn.commit()
except Exception,ex:
print Exception,":",ex
return
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。