本文整理汇总了Python中sql.sqlRun函数的典型用法代码示例。如果您正苦于以下问题:Python sqlRun函数的具体用法?Python sqlRun怎么用?Python sqlRun使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqlRun函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, row):
Thread.__init__(self)
self.id = row[0]
self.von = datetime.strptime(row[2],"%Y-%m-%d %H:%M:%S")
self.bis = datetime.strptime(row[3],"%Y-%m-%d %H:%M:%S")
self.name = row[5]
self.url = row[1].strip()
self.mask = row[6]
self.myrow = row
if config.cfg_retry_count.isdigit():
self.retry_count = int(config.cfg_retry_count)
if row[7]=='':
self.ext = config.cfg_file_extension
else:
self.ext = row[7]
if self.mask > 0:
w = self.von.isoweekday() if self.von.isoweekday()<7 else 0
if not (self.von>=datetime.now() and getWeekdays(self.mask)[w]):
delta = timedelta(days=1)
while not (self.von>=datetime.now() and getWeekdays(self.mask)[w]):
self.von = self.von + delta
self.bis = self.bis + delta
w = self.von.isoweekday() if self.von.isoweekday()<7 else 0
print ("Recurrent record '%s' moved to %s" % (self.name, self.von))
sqlRun("UPDATE records SET rvon='%s', rbis='%s' WHERE rowid=%d" % (datetime.strftime(self.von,"%Y-%m-%d %H:%M:%S"), datetime.strftime(self.bis,"%Y-%m-%d %H:%M:%S"), self.id ) )
示例2: create_p
def create_p():
prev = request.forms.prev
recname = request.forms.recname
sender = request.forms.Sender
von = request.forms.von
bis = request.forms.bis
am = request.forms.am
aktiv = getBool(request.forms.aktiv)
recurr = request.forms.recurr
d_von = datetime.strptime(am + " " + von, "%Y-%m-%d %H:%M")
d_bis = datetime.strptime(am + " " + bis, "%Y-%m-%d %H:%M")
# d_von = datetime.strptime(am + " " + von, "%d.%m.%Y %H:%M")
# d_bis = datetime.strptime(am + " " + bis, "%d.%m.%Y %H:%M")
delta = timedelta(days=1)
if d_bis < d_von:
d_bis = d_bis + delta
if prev=="":
sqlRun("INSERT INTO records VALUES (?, ?, ?, ?, ?, ?)", (recname, sender, d_von, d_bis, aktiv, recurr))
else:
sqlRun("UPDATE records SET recname=?, cid=?, rvon=?, rbis=?, renabled=?, rmask=? WHERE rowid=?", (recname, sender, d_von, d_bis, aktiv, recurr, prev))
setRecords()
return "null"
示例3: saveConfig
def saveConfig():
from sql import sqlRun
sql = ''
for var in getDict():
sql += "UPDATE config SET value='%s' WHERE param='%s';" % (globals()[var], var)
sqlRun(sql, -1, 1)
return
示例4: __init__
def __init__(self, row):
threading.Thread.__init__(self)
self.id = row[0]
self.von = datetime.strptime(row[2], "%Y-%m-%d %H:%M:%S")
self.bis = datetime.strptime(row[3], "%Y-%m-%d %H:%M:%S")
self.name = row[5]
self.url = row[1].strip()
self.mask = row[6]
self.myrow = row
if row[7] == "":
self.ext = config.cfg_file_extension
else:
self.ext = row[7]
if self.mask > 0:
w = self.bis.weekday()
if not (self.bis >= datetime.now() and getWeekdays(self.mask)[w]):
delta = timedelta(days=1)
while not (self.bis >= datetime.now() and getWeekdays(self.mask)[w]):
self.von = self.von + delta
self.bis = self.bis + delta
w = self.bis.weekday()
print "Recurrent record '%s' moved to %s" % (self.name, self.von)
sqlRun(
"UPDATE records SET rvon='%s', rbis='%s' WHERE rowid=%d"
% (
datetime.strftime(self.von, "%Y-%m-%d %H:%M:%S"),
datetime.strftime(self.bis, "%Y-%m-%d %H:%M:%S"),
self.id,
)
)
示例5: checkIP
def checkIP(ip):
sqlRun("DELETE FROM blacklist WHERE julianday('now', 'localtime')-julianday(lasttry)>=2;")
rows = sqlRun("SELECT trycount FROM blacklist WHERE ip=?", (ip, ))
if rows:
if rows[0][0]>=3:
return False
return True
示例6: getProg
def getProg(strp, channellist=[]):
deltaxmltv_txt = config.cfg_xmltvtimeshift
try:
deltaxmltv = timedelta(hours=float(config.cfg_xmltvtimeshift))
except:
deltaxmltv = timedelta(hours=0)
sqllist = []
for attr,innertxt in getList(strp, 'programme'):
dt1 = datetime.strptime(getAttr(attr, "start")[0:14],"%Y%m%d%H%M%S") + deltaxmltv
try:
dt2 = datetime.strptime(getAttr(attr, "stop")[0:14],"%Y%m%d%H%M%S") + deltaxmltv
except:
dt2 = datetime.strptime(getAttr(attr, "end")[0:14],"%Y%m%d%H%M%S") + deltaxmltv
p_id = getAttr(attr, "channel")
if len(channellist)==0 or p_id in channellist:
desc = ""
title = getFirst(innertxt, 'title')
sub_title = getFirst(innertxt, 'sub-title')
if not "http://" in sub_title and len(sub_title)>0: # fix for corrupted XML data
if title != "": title = title + " - "
title = title + sub_title
eplist = getFirst(innertxt, 'episode-num')
for epatt, epin in getList(eplist, 'system'):
if getAttr(epatt, 'system') == 'onscreen':
desc = epin + ". "
break
tmpdesc = getFirst(innertxt, 'desc')
desc = desc + tmpdesc
sqllist.append([p_id, title, datetime.strftime(dt1, "%Y-%m-%d %H:%M:%S"), datetime.strftime(dt2, "%Y-%m-%d %H:%M:%S"), desc])
sqlRun("INSERT OR IGNORE INTO guide VALUES (?, ?, ?, ?, ?)", sqllist, 1)
return len(sqllist)
示例7: getFile
def getFile(file_in, override=0):
rows=sqlRun("SELECT * FROM caching WHERE url='%s'" % file_in)
lastmod = ""
etag = ""
out = ""
if rows:
lastmod = rows[0][2]
etag = rows[0][3]
try:
#print lastmod, etag
httplib.HTTPConnection.debuglevel = 1
request = urllib2.Request(file_in)
request.add_header('User-Agent', 'tvstreamrecord/' + version)
if override==0:
request.add_header('If-Modified-Since', lastmod)
request.add_header('If-None-Match', etag)
opener = urllib2.build_opener()
response = opener.open(request)
feeddata = response.read()
if rows:
sqlRun("UPDATE caching SET crTime=datetime('now', 'localtime'), Last_Modified=?, ETag=? WHERE url='%s'" % file_in, (response.info().getheader('Last-Modified'), response.info().getheader('ETag')))
else:
sqlRun("INSERT INTO caching VALUES (datetime('now', 'localtime'), ?, ?, ?)", (file_in, response.info().getheader('Last-Modified'), response.info().getheader('ETag')))
d = zlib.decompressobj(16+zlib.MAX_WBITS)
out = d.decompress(feeddata)
print "XMLTV: reading URL %s" % file_in
except:
print "XMLTV: no new data, try again later"
pass
return out
示例8: createepg
def createepg():
sqlRun(
"INSERT INTO records SELECT guide.g_title, channels.cid, datetime(guide.g_start, '-%s minutes'), datetime(guide.g_stop, '+%s minutes'), 1, 0 FROM guide, guide_chan, channels WHERE guide.g_id = guide_chan.g_id AND channels.cname = guide_chan.g_name AND guide.rowid=%s GROUP BY datetime(guide.g_start, '-3 minutes')"
% (config.cfg_delta_for_epg, config.cfg_delta_for_epg, request.forms.ret)
)
setRecords()
redirect("/records")
return
示例9: banIP
def banIP(ip):
rows = sqlRun("SELECT trycount FROM blacklist WHERE ip=?", (ip, ))
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
if rows:
sqlRun("UPDATE blacklist SET trycount=?, lasttry=? WHERE ip=?", (rows[0][0]+1, now, ip))
if rows[0][0]+1==3:
print ("IP %s has been blacklisted for for three unsuccessful login attempts" % ip)
else:
sqlRun("INSERT INTO blacklist VALUES (?, ?, ?)", (ip, 1, now) )
示例10: getProg
def getProg(strp, channellist=[], keylist=[]):
deltaxmltv_txt = config.cfg_xmltvtimeshift
try:
deltaxmltv = timedelta(hours=float(config.cfg_xmltvtimeshift))
except:
deltaxmltv = timedelta(hours=0)
#2018-12-31 automatic recording
delta_b = timedelta(minutes=float(config.cfg_delta_after_epg))
delta_a = timedelta(minutes=float(config.cfg_delta_before_epg))
reclist = []
sqllist = []
for attr,innertxt in getList(strp, 'programme'):
dt1 = datetime.strptime(getAttr(attr, "start")[0:14],"%Y%m%d%H%M%S") + deltaxmltv
try:
dt2 = datetime.strptime(getAttr(attr, "stop")[0:14],"%Y%m%d%H%M%S") + deltaxmltv
except:
dt2 = datetime.strptime(getAttr(attr, "end")[0:14],"%Y%m%d%H%M%S") + deltaxmltv
p_id = getAttr(attr, "channel")
if len(channellist)==0 or p_id in channellist:
desc = ""
title = getFirst(innertxt, 'title')
sub_title = getFirst(innertxt, 'sub-title')
if not "http://" in sub_title and len(sub_title)>0: # fix for corrupted XML data
if title != "": title = title + " - "
title = title + sub_title
for epatt, epin in getList(innertxt, 'episode-num'):
if getAttr(epatt, 'system') == 'xmltv_ns':
e = epin.split(".")
if len(e)>1:
try:
episode = "E" + format(int(e[1].strip()) + 1, '02d')
if e[0].strip() != "":
episode = "S" + format(int(e[0].strip()) + 1, '02d') + episode
desc += episode + ". "
title += " (" + episode + ")"
break
except:
pass
elif getAttr(epatt, 'system') == 'onscreen':
desc = epin + ". "
break
tmpdesc = getFirst(innertxt, 'desc')
desc = desc + tmpdesc
sqllist.append([p_id, title, datetime.strftime(dt1, "%Y-%m-%d %H:%M:%S"), datetime.strftime(dt2, "%Y-%m-%d %H:%M:%S"), desc])
for key in keylist:
if key in title.lower():
print("XMLTV: Record '%s' is queued for autocreation" % (title, ))
reclist.append([title, datetime.strftime(dt1-delta_b, "%Y-%m-%d %H:%M:%S"), datetime.strftime(dt2+delta_a, "%Y-%m-%d %H:%M:%S"), p_id])
break
sqlRun("INSERT OR IGNORE INTO guide VALUES (?, ?, ?, ?, ?)", sqllist, 1)
return len(sqllist), reclist
示例11: getFile
def getFile(file_in, override=0, ver=""):
rows=sqlRun("SELECT * FROM caching WHERE url=?", (file_in, ))
lastmod = ""
etag = ""
out = ""
if rows:
lastmod = rows[0][2]
etag = rows[0][3]
try:
httplib.HTTPConnection.debuglevel = 0
request = urllib32.Request(file_in)
request.add_header('User-Agent', 'tvstreamrecord/' + ver)
if override==0:
request.add_header('If-Modified-Since', lastmod)
request.add_header('If-None-Match', etag)
opener = urllib32.build_opener()
try:
hresponse = opener.open(request, timeout=10)
except Exception as ex:
print ("XMLTV Warning: connection timeout detected, retry in 5 seconds")
sleep (5)
hresponse = opener.open(request, timeout=20)
feeddata = hresponse.read()
hr = hresponse.info()
lastmod = hr.get('Last-Modified')
etag = hr.get('ETag')
if rows and lastmod and etag:
sqlRun("UPDATE caching SET crTime=datetime('now', 'localtime'), Last_Modified=?, ETag=? WHERE url=?", (lastmod, etag, file_in))
elif lastmod and etag:
sqlRun("INSERT INTO caching VALUES (datetime('now', 'localtime'), ?, ?, ?)", (file_in, lastmod, etag))
try:
d = zlib.decompressobj(16+zlib.MAX_WBITS)
out = d.decompress(feeddata)
except:
out = feeddata
print ("XMLTV: reading URL %s with %s bytes" % (file_in, len(out)))
if not b"</tv>" in out[-1000:]:
print ("Possibly corrupted XML file, attempting to repair...")
pos = out.rfind(b"</programme>")
if pos != -1:
out = out[:pos+12] + b"</tv>"
else:
pos = out.rfind(b"</channel>")
if pos != -1:
out = out[:pos+10] + b"</tv>"
except Exception as ex:
print ("XMLTV: no new data / unknown error, try again later (%s)" % file_in)
pass
try:
out = out.decode("UTF-8")
except:
pass
return out
示例12: setRecords
def setRecords():
if shutdown:
return
rows=sqlRun("SELECT records.rowid, cpath, rvon, rbis, cname, records.recname, records.rmask, channels.cext, channels.cid, channels.cname FROM channels, records where channels.cid=records.cid AND (datetime(rbis)>=datetime('now', 'localtime') OR rmask>0) AND renabled = 1 ORDER BY datetime(rvon)")
for row in rows:
chk = False
for t in records:
if t.id == row[0]:
if t.myrow[1]!=row[1] or t.myrow[2]!=row[2] or t.myrow[3]!=row[3] or t.myrow[4]!=row[4] or t.myrow[5]!=row[5] or t.myrow[6]!=row[6] or t.myrow[7]!=row[7]:
t.stop()
chk = False
else:
chk = True
break
if chk == False:
thread = record(row)
thread.start()
records.append(thread)
for i in range(len(records)-1,-1,-1):
t = records[i]
chk = False
for row in rows:
if t.id == row[0]:
chk = True
break
if chk == False:
t.stop()
示例13: chanlist
def chanlist():
l = []
rows = sqlRun("SELECT channels.cid, cname, cpath, cext, epgscan, cenabled FROM channels")
for row in rows:
m3u = '<a href="live/' + str(row[0]) + '.m3u">' + row[1] + "</a>"
l.append([row[0], m3u, row[2], row[3], row[4], row[5]])
return json.dumps({"aaData": l})
示例14: server_static9
def server_static9(filename):
rows = sqlRun("SELECT * FROM channels WHERE cid=?", (filename.split(".")[0], ))
if rows:
write_m3u(rows[0][0], rows[0][1])
else:
return
return static_file("/live.m3u", root='', mimetype='video')
示例15: getrecordlist
def getrecordlist():
l = []
rows=sqlRun("SELECT recname, cname, rvon, rbis, rmask, renabled, 100*(strftime('%s','now', 'localtime')-strftime('%s',rvon)) / (strftime('%s',rbis)-strftime('%s',rvon)), records.rowid, rvon, rbis, channels.cid FROM channels, records where channels.cid=records.cid ORDER BY rvon")
for row in rows:
m3u = "<a href=\"live/" + str(row[10]) + ".m3u\">" + row[1] + "</a>"
l.append([row[0], m3u, row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9]])
return json.dumps({"aaData": l} )