Python 如何设置计算进度
我正在为xbmc媒体应用程序编写python脚本,将请求发送到url以获得响应,这样我就可以将数据存储在sqlite3数据库中 我想为label控件设置从0%到100%的计算进度,以查看当我将请求发送到url以获取响应,然后将数据存储在数据库中时,我将走多远 以下是我要使用的控件id:Python 如何设置计算进度,python,xbmc,Python,Xbmc,我正在为xbmc媒体应用程序编写python脚本,将请求发送到url以获得响应,这样我就可以将数据存储在sqlite3数据库中 我想为label控件设置从0%到100%的计算进度,以查看当我将请求发送到url以获取响应,然后将数据存储在数据库中时,我将走多远 以下是我要使用的控件id: main_loading_time_left = 4202 代码如下: #DOWNLOAD THE XML SOURCE HERE url = ADDON.getSetting('url') req = url
main_loading_time_left = 4202
代码如下:
#DOWNLOAD THE XML SOURCE HERE
url = ADDON.getSetting('url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
if os.path.exists(profilePath):
profilePath = profilePath + 'source.db'
con = database.connect(profilePath)
cur = con.cursor()
cur.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, stop_date TIMESTAMP, description TEXT)')
con.commit()
con.close
tv_elem = ElementTree.parse(StringIO.StringIO(data)).getroot()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
profilePath = profilePath + 'source.db'
con = sqlite3.connect(profilePath)
cur = con.cursor()
channels = OrderedDict()
# Get the loaded data
for channel in tv_elem.findall('channel'):
channel_name = channel.find('display-name').text
for program in channel.findall('programme'):
title = program.find('title').text
start_time = program.get("start")
stop_time = program.get("stop")
cur.execute("INSERT INTO programs(channel, title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, title, start_time, stop_time])
con.commit()
有人知道我如何使用控件id main_loading_time_left设置计算进度,当我将请求发送到url以获取响应,然后将数据存储到数据库中时,该进度从0%开始到100%。有人知道怎么做吗?要显示进度,您应该有两个点:开始、当前和结束。因此,0,当前处理数据和总数据 但是这里有两个昂贵的操作:http查询获取和导出到sqlite 为了跟踪http查询的进度,我建议查看以下问题和答案:和 要跟踪sql查询的进度,只需将tv_elem.findall'channel'的长度作为结束
elements = tv_elem.findall('channel')
total = len(elements)
for current, channel in enumerate(elements):
...
setProgressBar(main_loading_time_left, float(current)/total*100)