Commit b9c5ed72 authored by mitshel's avatar mitshel
Browse files

Доделана выдача новинок (все наименования)

parent 424a5ecc
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -121,19 +121,22 @@ def new_menu():
   newinfo=opdsdb.getnewinfo(cfg.DUBLICATES_SHOW,cfg.NEW_PERIOD)
   enc_print('<entry>')
   enc_print('<title>Все новинки за %s суток</title>'%cfg.NEW_PERIOD)
   enc_print('<content type="text">Книг: %s.</content>'%newinfo[0][1])
   enc_print('<content type="text">Новых книг: %s.</content>'%newinfo[0][1])
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id='+am+'03&amp;news=1"/>')
   enc_print('<id>id:03:news</id></entry>')
   enc_print('<entry>')
   enc_print('<title>Новинки по авторам</title>')
   enc_print('<content type="text">Авторов новинок: %s.</content>'%newinfo[1][1])
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id='+am+'02&amp;news=1"/>')
   enc_print('<id>id:02:news</id></entry>')
   enc_print('<entry>')
   enc_print('<title>Новинки по Жанрам</title>')
   enc_print('<content type="text">Жанров новинок: %s.</content>'%newinfo[2][1])
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id=04&amp;news=1"/>')
   enc_print('<id>id:04:news</id></entry>')
   enc_print('<entry>')
   enc_print('<title>Новинки по Сериям</title>')
   enc_print('<content type="text">Серий новинок: %s.</content>'%newinfo[3][1])
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id='+am+'06&amp;news=1"/>')
   enc_print('<id>id:06:news</id></entry>')
   enc_print('<entry>')
@@ -149,7 +152,7 @@ def entry_head(e_title,e_date,e_id):

def entry_link_subsection(link_id):
#   enc_print('<link type="application/atom+xml" rel="alternate" href="'+cfg.CGI_PATH+'?id='+link_id+'"/>')
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="subsection" href="'+cfg.CGI_PATH+'?id='+link_id+'"/>')
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="subsection" href="'+cfg.CGI_PATH+'?id='+link_id+nl+'"/>')

def entry_link_book(link_id,format):
   str_id=str(link_id)
@@ -245,7 +248,7 @@ def page_control(db, page, link_id):
def alphabet_menu(iid_value):
   entry_start()
   entry_head('А..Я (РУС)', None, 'alpha:1')
   id=iid_value+'&amp;alpha=1'
   id=iid_value+'&amp;alpha=1'+nl
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id='+id+'"/>')
   entry_finish()
   entry_start()
@@ -275,6 +278,8 @@ slice_value=0
page_value=0
alpha=0
news=0
np=0
nl=''

form = cgi.FieldStorage()
if 'id' in form:
@@ -303,6 +308,8 @@ if 'alpha' in form:
   if salpha.isdigit(): alpha=int(salpha)
if 'news' in form:
   news=1
   nl='&amp;news=1'
   np=cfg.NEW_PERIOD

opdsdb=sopdsdb.opdsDatabase(cfg.DB_NAME,cfg.DB_USER,cfg.DB_PASS,cfg.DB_HOST,cfg.ROOT_LIB)
opdsdb.openDB()
@@ -411,7 +418,7 @@ elif type_value==3:
      i=i//10000

   header()
   for (letters,cnt) in opdsdb.gettitle_2letters(letter,cfg.DUBLICATES_SHOW,alpha,news):
   for (letters,cnt) in opdsdb.gettitle_2letters(letter,cfg.DUBLICATES_SHOW,alpha,np):
       id=""
       for i in range(len(letters)):
           id+='%04d'%(ord(letters[i]))
@@ -443,7 +450,7 @@ if type_value==13 or type_value==71:
      letter="%"+searchTerm

   header()
   for (book_id,book_name,book_path,reg_date,book_title,annotation,docdate,format,fsize,cover,cover_type) in opdsdb.getbooksfortitle(letter,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW):
   for (book_id,book_name,book_path,reg_date,book_title,annotation,docdate,format,fsize,cover,cover_type) in opdsdb.getbooksfortitle(letter,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW,np):
       id='90'+str(book_id)
       entry_start()
       entry_head(book_title, reg_date, id_value)
+25 −24
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ class opdsDatabase:
    return book_id

  def finddouble(self,title,format,file_size):
    sql_findbook=("select book_id from "+TBL_BOOKS+" where title=%s and format=%s and filesize=%s and doublicat=0 and avail!=0")
    sql_findbook=("select book_id from "+TBL_BOOKS+" where title=%s and format=%s and filesize=%s and avail!=0 and doublicat=0")
    data_findbook=(title,format,file_size)
    cursor=self.cnx.cursor()
    cursor.execute(sql_findbook,data_findbook)
@@ -402,11 +402,11 @@ class opdsDatabase:
    cursor.close
    return rows

  def gettitle_2letters(self,letters,doublicates=True,alpha=0,news=0):
    if doublicates: dstr=''
    else: dstr=' and doublicat=0 '
    if news==0: period=''
    else: period="and (registerdate>now()-INTERVAL %s DAY)"%cfg.NEW_PERIOD
  def gettitle_2letters(self,letters,doublicates=True,alpha=0,new_period=0):
    if doublicates: dstr=""
    else: dstr=" and doublicat=0 "
    if new_period==0: period=''
    else: period=" and (registerdate>now()-INTERVAL %s DAY)"%new_period
    lc=len(letters)+1
    having=''
    if lc==1:
@@ -414,12 +414,11 @@ class opdsDatabase:
       elif alpha==2: having=" having INSTR('0123456789',letters)>0 and letters!=''"
       elif alpha==3: having=" having INSTR('ABCDEFGHIJKLMNOPQRSTUVWXYZ',letters)>0 and letters!=''"
       elif alpha==4: having=" having INSTR('ABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ0123456789',letters)=0 and letters!=''"
    if having=="": having=" having "+period
    else: having=having+" "+period

    sql="select UPPER(substring(trim(title),1,"+str(lc)+")) as letters, count(*) as cnt from "+TBL_BOOKS+" where substring(trim(title),1,"+str(lc-1)+")='"+letters+"' "+dstr+"  and avail!=0 group by 1"+having+" order by 1"
    sql="select UPPER(substring(trim(title),1,"+str(lc)+")) as letters, count(*) as cnt from "+TBL_BOOKS+" where substring(trim(title),1,"+str(lc-1)+")=%s and avail!=0 "+dstr+period+" group by 1"+having+" order by 1"
    data=(letters,)
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    cursor.execute(sql,data)
    rows=cursor.fetchall()
    cursor.close
    return rows
@@ -441,18 +440,17 @@ class opdsDatabase:
    return rows


  def getbooksfortitle(self,letters,limit=0,page=0,doublicates=True):
    if limit==0:
       limitstr=""
    else:
       limitstr="limit "+str(limit*page)+","+str(limit)
    if doublicates:
       dstr=''
    else:
       dstr=' and doublicat=0 '
    sql="select SQL_CALC_FOUND_ROWS book_id,filename,path,registerdate,title,annotation,docdate,format,filesize,cover,cover_type from "+TBL_BOOKS+" where title like '"+letters+"%' "+dstr+" and avail!=0 order by title "+limitstr
  def getbooksfortitle(self,letters,limit=0,page=0,doublicates=True,new_period=0):
    if limit==0: limitstr=""
    else: limitstr="limit "+str(limit*page)+","+str(limit)
    if doublicates: dstr=''
    else: dstr=' and doublicat=0'
    if new_period==0: period=''
    else: period=" and (registerdate>now()-INTERVAL %s DAY)"%new_period
    sql="select SQL_CALC_FOUND_ROWS book_id,filename,path,registerdate,title,annotation,docdate,format,filesize,cover,cover_type from "+TBL_BOOKS+" where title like %s and avail!=0"+dstr+period+" order by title "+limitstr
    data=(letters+'%',)
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    cursor.execute(sql,data)
    rows=cursor.fetchall()

    cursor.execute("SELECT FOUND_ROWS()")
@@ -637,16 +635,19 @@ class opdsDatabase:
    else: dstr='and doublicat=0'

    if new_period==0: period=''
    else: period='and registerdate-INTERVAL %s DAY'%new_period
    else: period='and registerdate>now()-INTERVAL %s DAY'%new_period

    sql="select 1 s, count(avail) from %s where avail!=0 %s %s"%(TBL_BOOKS,dstr,period)
    sql1="select 1 s, count(avail) from %s where avail!=0 %s %s"%(TBL_BOOKS,dstr,period)
    sql2="select 2 s, count(*) from (select b.author_id from %s b left join %s c on b.book_id=c.book_id where c.avail!=0 %s group by b.author_id) a1"%(TBL_BAUTHORS, TBL_BOOKS, period)
    sql3="select 3 s, count(*) from (select b.genre_id from %s b left join %s c on b.book_id=c.book_id where c.avail!=0 %s group by b.genre_id) a2"%(TBL_BGENRES, TBL_BOOKS, period)
    sql4="select 4 s, count(*) from (select b.ser_id from %s b left join %s c on b.book_id=c.book_id where c.avail!=0 %s group by b.ser_id) a3"%(TBL_BSERIES, TBL_BOOKS, period)
    sql=sql1+" union all "+sql2+" union all "+sql3+" union all "+sql4+" order by s"
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    rows=cursor.fetchall()
    cursor.close
    return rows
  
  
  def zipisscanned(self,zipname,setavail=0):
    sql='select cat_id from '+TBL_BOOKS+' where path="'+zipname+'" limit 1'
    cursor=self.cnx.cursor()