[Wepg-devel] mythcond populate.py,NONE,1.1 serie.py,1.2,1.3
Brought to you by:
leonvs
|
From: Leon v. S. <le...@us...> - 2004-08-08 17:26:44
|
Update of /cvsroot/wepg/mythcond In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19515 Modified Files: serie.py Added Files: populate.py Log Message: ok Index: serie.py =================================================================== RCS file: /cvsroot/wepg/mythcond/serie.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** serie.py 8 Aug 2004 14:38:12 -0000 1.2 --- serie.py 8 Aug 2004 17:26:35 -0000 1.3 *************** *** 17,28 **** import MySQLdb - import random import string import time - import os.path - import socket import sys import mx import math # defines --- 17,26 ---- import MySQLdb import string import time import sys import mx import math + import getopt # defines *************** *** 33,43 **** - - def loadBroadcasts(mythdb, chanid, start_time, end_time, base_day_offset, day_offset, count, offsets): offsets.extend( range(base_day_offset, base_day_offset + count * day_offset, day_offset) ) ! # print "loading off",offsets bca = [] --- 31,39 ---- def loadBroadcasts(mythdb, chanid, start_time, end_time, base_day_offset, day_offset, count, offsets): offsets.extend( range(base_day_offset, base_day_offset + count * day_offset, day_offset) ) ! #if verbose: print "loading off",offsets bca = [] *************** *** 86,90 **** def saveSerie(mythdb, bc): ! global s_nextSeriesID # print "serie: ",len(bc) --- 82,86 ---- def saveSerie(mythdb, bc): ! global nextSeriesID # print "serie: ",len(bc) *************** *** 153,158 **** else: # instantiate new string of series ! sid = s_nextSeriesID ! s_nextSeriesID = s_nextSeriesID + 1 for i in bc: # print 'a', --- 149,154 ---- else: # instantiate new string of series ! sid = nextSeriesID ! nextSeriesID = nextSeriesID + 1 for i in bc: # print 'a', *************** *** 268,328 **** - mythdb = MySQLdb.connect(host="bender", user="mythtv", passwd="mythtv", db="mythconverg") ! cc=mythdb.cursor() ! cc.execute("SELECT MAX(id),MAX(starttime) FROM Serie") ! row = cc.fetchone() ! if row != None and row[0] != None: ! s_nextSeriesID = row[0] + 1 ! endtime = row[1] ! else: ! s_nextSeriesID = 1 ! endtime = mx.DateTime.today() - 14 ! cc.close() - cc=mythdb.cursor() - cc.execute("SELECT MAX(starttime) FROM program") - row = cc.fetchone() - if row != None and row[0] != None: - starttime = row[0] - else: - starttime = mx.DateTime.today() - cc.close() ! #day_offset = 0 ! #day_count = 5 ! #week_count = 4 ! #week_day_count = 1 ! #c1 = mx.DateTime.today() ! #c1 = c1 + day_offset * oneDay ! c1 = mx.DateTime.Date(starttime.year, starttime.month, starttime.day) ! c2 = c1 + oneDay ! day_count = (starttime - endtime).day + 1 ! if day_count < 4: ! day_count = 4 ! week_count = 4 ! week_day_count = day_count ! # print "daycount ",day_count, "c1",c1 ! cu=mythdb.cursor() ! cu.execute("SELECT chanid FROM channel WHERE visible=1") ! while 1: ! row = cu.fetchone() ! if row == None: ! break; ! chanid = row[0] ! print "processing channel ",chanid ! findSeries2(mythdb, chanid, c1, c2, day_count, week_count, week_day_count) ! cu.close() ! mythdb.close() ! print "done." --- 264,355 ---- ! def usage(): ! print "%s: [-h,--host=...] [-u,--user=...] [-p,--password=...] [-v] [-?]" % sys.argv[0] + def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "h:u:p:v?", ["host=", "user=", "password=", "help"]) + except getopt.GetoptError: + usage() + sys.exit(2) ! dbhost = "localhost" ! dbuser = "mythtv" ! dbpass = "mythtv" ! verbose = False ! for o, a in opts: ! if o == "-v": ! verbose = True ! if o in ("-?", "--help"): ! usage() ! sys.exit() ! if o in ("-h", "--host"): ! dbhost = a ! if o in ("-u", "--user"): ! dbuser = a ! if o in ("-p", "--password"): ! dbpass = a ! mythdb = MySQLdb.connect(host=dbhost, user=dbuser, passwd=dbpass, db="mythconverg") ! cc=mythdb.cursor() ! cc.execute("SELECT MAX(id),MAX(starttime) FROM Serie") ! row = cc.fetchone() ! if row != None and row[0] != None: ! nextSeriesID = row[0] + 1 ! endtime = row[1] ! else: ! nextSeriesID = 1 ! endtime = mx.DateTime.today() - 14 ! cc.close() ! cc=mythdb.cursor() ! cc.execute("SELECT MAX(starttime) FROM program") ! row = cc.fetchone() ! if row != None and row[0] != None: ! starttime = row[0] ! else: ! starttime = mx.DateTime.today() ! cc.close() ! #day_offset = 0 ! #day_count = 5 ! #week_count = 4 ! #week_day_count = 1 ! #c1 = mx.DateTime.today() ! #c1 = c1 + day_offset * oneDay ! c1 = mx.DateTime.Date(starttime.year, starttime.month, starttime.day) ! c2 = c1 + oneDay ! day_count = (starttime - endtime).day + 1 ! if day_count < 4: ! day_count = 4 ! week_count = 4 ! week_day_count = day_count ! if verbose: print "scanning back",day_count,"days for dayly's from",c1 ! if verbose: print "scanning back",week_day_count,"days for weekly's spanning",week_count,"weeks" + cu=mythdb.cursor() + cu.execute("SELECT chanid,callsign FROM channel WHERE visible=1") + while 1: + row = cu.fetchone() + if row == None: + break; + chanid = row[0] + name = row[1] + + if verbose: print "processing channel",chanid,name + findSeries2(mythdb, chanid, c1, c2, day_count, week_count, week_day_count) + cu.close() + + mythdb.close() + if verbose: print "done." + + if __name__ == "__main__": + main() --- NEW FILE: populate.py --- # populate.py - db filler for wepg # Copyright (C) 2004 Leon van Stuivenberg <l.v...@ch...> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import MySQLdb import sys import mx import getopt def mux(a,b,c): if a: return b else: return c # populate db with user-specific broadcast records; dups will be avoided by PK def populateUserBroadcast(mythdb, user_id, verbose): cu = mythdb.cursor() cu.execute("SELECT MAX(starttime) FROM UserBroadcast WHERE user_id=%s", (user_id)) row = cu.fetchone() limit = mux(row == None or row[0] == None, mx.DateTime.today(), row[0]) cu.close() if verbose: print "populate from",limit cu = mythdb.cursor() cu.execute("""INSERT INTO UserBroadcast (user_id,chanid,starttime,uid,orgtitle,category) SELECT %s,chanid,starttime,LEFT(LOWER(title),31),title,category FROM program WHERE starttime>%s""", (user_id, limit)) if verbose: print "populated nrows",cu.rowcount cu.close() if verbose: print "populate done." def usage(): print "%s: [-h,--host=...] [-u,--user=...] [-p,--password=...] [-v] [-?]" % sys.argv[0] def main(): try: opts, args = getopt.getopt(sys.argv[1:], "h:u:p:v?", ["host=", "user=", "password=", "help"]) except getopt.GetoptError: usage() sys.exit(2) dbhost = "localhost" dbuser = "mythtv" dbpass = "mythtv" verbose = False for o, a in opts: if o == "-v": verbose = True if o in ("-?", "--help"): usage() sys.exit() if o in ("-h", "--host"): dbhost = a if o in ("-u", "--user"): dbuser = a if o in ("-p", "--password"): dbpass = a mythdb = MySQLdb.connect(host=dbhost, user=dbuser, passwd=dbpass, db="mythconverg") cu=mythdb.cursor() cu.execute("SELECT id,name FROM User") while 1: row = cu.fetchone() if row == None: break; user_id = row[0] name = row[1] if verbose: print "processing user",user_id,name populateUserBroadcast(mythdb, user_id, verbose) cu.close() mythdb.close() if verbose: print "done." if __name__ == "__main__": main() |