Commit 96c750a5 authored by mitshel's avatar mitshel
Browse files

Добавлена вывод новых книг по авторам и по сериям

parent b9c5ed72
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -103,6 +103,9 @@ title_as_filename = yes
# по умолчанию alphabet_menu=yes
alphabet_menu = yes

#new_period = N - количество суток в течении которых добавленные книги считаются новыми, по умолчанию 7 дней
new_period = 1

[site]
id=http://sopds.ru/
title=SOPDS.RU | OPDS Catalog
+2 −2
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ avail INT not null DEFAULT 0,
PRIMARY KEY(book_id),
KEY(filename),
KEY(title,format,filesize),
KEY(avail),
KEY(doublicat));
INDEX(avail,doublicat),
INDEX(registerdate));
commit;

drop table if exists catalogs;
+6 −6
Original line number Diff line number Diff line
@@ -361,7 +361,7 @@ elif type_value==2:
      i=i//10000

   header()
   for (letters,cnt) in opdsdb.getauthor_2letters(letter,alpha):
   for (letters,cnt) in opdsdb.getauthor_2letters(letter,alpha,np):
       id=""
       for i in range(len(letters)):
           id+='%04d'%(ord(letters[i]))
@@ -389,7 +389,7 @@ elif type_value==6:
      i=i//10000

   header()
   for (letters,cnt) in opdsdb.getseries_2letters(letter,alpha):
   for (letters,cnt) in opdsdb.getseries_2letters(letter,alpha,np):
       id=""
       for i in range(len(letters)):
           id+='%04d'%(ord(letters[i]))
@@ -571,7 +571,7 @@ if type_value==12 or type_value==72:
      letter="%"+searchTerm

   header()
   for (author_id,first_name, last_name,cnt) in opdsdb.getauthorsbyl(letter,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW):
   for (author_id,first_name, last_name,cnt) in opdsdb.getauthorsbyl(letter,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW,np):
       id='22'+str(author_id)
       entry_start()
       entry_head(last_name+' '+first_name, None, id_value)
@@ -597,7 +597,7 @@ if type_value==16 or type_value==73:
      letter="%"+searchTerm

   header()
   for (ser_id,ser,cnt) in opdsdb.getseriesbyl(letter,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW):
   for (ser_id,ser,cnt) in opdsdb.getseriesbyl(letter,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW,np):
       id='26'+str(ser_id)
       entry_start()
       entry_head(ser, None, id_value)
@@ -613,7 +613,7 @@ if type_value==16 or type_value==73:
#
if type_value==22:
   header()
   for (book_id,book_name,book_path,reg_date,book_title,annotation,docdate,format,fsize,cover,cover_type) in opdsdb.getbooksforautor(slice_value,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.getbooksforautor(slice_value,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW,np):
       id='90'+str(book_id)
       entry_start()
       entry_head(book_title, reg_date, id_value)
@@ -632,7 +632,7 @@ if type_value==22:
#
if type_value==26:
   header()
   for (book_id,book_name,book_path,reg_date,book_title,annotation,docdate,format,fsize,cover,cover_type) in opdsdb.getbooksforser(slice_value,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.getbooksforser(slice_value,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW,np):
       id='90'+str(book_id)
       entry_start()
       entry_head(book_title, reg_date, id_value)
+47 −48
Original line number Diff line number Diff line
@@ -386,7 +386,7 @@ class opdsDatabase:
    cursor.close
    return rows

  def getauthor_2letters(self,letters,alpha=0):
  def getauthor_2letters(self,letters,alpha=0,new_period=0):
    lc=len(letters)+1
    having=''
    if lc==1:
@@ -394,10 +394,12 @@ 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!=''"

    sql="select UPPER(substring(CONCAT(TRIM(last_name),' ',trim(first_name)),1,"+str(lc)+")) as letters, count(*) as cnt from "+TBL_AUTHORS+" where substring(CONCAT(trim(last_name),' ',trim(first_name)),1,"+str(lc-1)+")='"+letters+"' group by 1"+having+" order by 1"
    if new_period==0: period=''
    else: period="and author_id in (select b.author_id from bauthors b left join books c on b.book_id=c.book_id where registerdate>now()-INTERVAL %s DAY group by b.author_id)"%new_period
    sql="select UPPER(substring(CONCAT(TRIM(last_name),' ',trim(first_name)),1,"+str(lc)+")) as letters, count(*) as cnt from "+TBL_AUTHORS+" where substring(CONCAT(trim(last_name),' ',trim(first_name)),1,"+str(lc-1)+")=%s "+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
@@ -423,7 +425,7 @@ class opdsDatabase:
    cursor.close
    return rows

  def getseries_2letters(self,letters,alpha=0):
  def getseries_2letters(self,letters,alpha=0,new_period=0):
    lc=len(letters)+1
    having=''
    if lc==1:
@@ -431,10 +433,13 @@ 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 new_period==0: period=''
    else: period="and ser_id in (select b.ser_id from bseries b left join books c on b.book_id=c.book_id where registerdate>now()-INTERVAL %s DAY group by b.ser_id)"%new_period

    sql="select UPPER(substring(TRIM(ser),1,"+str(lc)+")) as letters, count(*) as cnt from "+TBL_SERIES+" where substring(trim(ser),1,"+str(lc-1)+")='"+letters+"' group by 1"+having+" order by 1"
    sql="select UPPER(substring(TRIM(ser),1,"+str(lc)+")) as letters, count(*) as cnt from "+TBL_SERIES+" where substring(trim(ser),1,"+str(lc-1)+")=%s "+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
@@ -463,18 +468,18 @@ class opdsDatabase:
    cursor.close
    return rows

  def getauthorsbyl(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 c.doublicat=0 '
    sql="select SQL_CALC_FOUND_ROWS a.author_id, a.first_name, a.last_name, count(*) as cnt from "+TBL_AUTHORS+" a, "+TBL_BAUTHORS+" b, "+TBL_BOOKS+" c where a.author_id=b.author_id and b.book_id=c.book_id and CONCAT(TRIM(a.last_name),' ',TRIM(a.first_name)) like '"+letters+"%' "+dstr+" and c.avail!=0 group by 1,2,3 order by 3,2 "+limitstr
  def getauthorsbyl(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 c.doublicat=0 '
    if new_period==0: period=''
    else: period=" and (registerdate>now()-INTERVAL %s DAY) and a.author_id in (select b.author_id from bauthors b left join books c on b.book_id=c.book_id where registerdate>now()-INTERVAL %s DAY group by b.author_id)"%(new_period,new_period)

    sql="select SQL_CALC_FOUND_ROWS a.author_id, a.first_name, a.last_name, count(*) as cnt from "+TBL_AUTHORS+" a, "+TBL_BAUTHORS+" b, "+TBL_BOOKS+" c where a.author_id=b.author_id and b.book_id=c.book_id and CONCAT(TRIM(a.last_name),' ',TRIM(a.first_name)) like %s and c.avail!=0 "+dstr+period+" group by 1,2,3 order by 3,2 "+limitstr
    data=(letters+'%',)
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    cursor.execute(sql,data)
    rows=cursor.fetchall()

    cursor.execute("SELECT FOUND_ROWS()")
@@ -487,16 +492,14 @@ class opdsDatabase:
    cursor.close
    return rows

  def getbooksforautor(self,author_id,limit=0,page=0,doublicates=True):
    if limit==0:
       limitstr=""
    else:
       limitstr="limit "+str(limit*page)+","+str(limit)
    if doublicates:
       dstr=''
    else:
       dstr=' and a.doublicat=0 '
    sql="select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.annotation,a.docdate,a.format,a.filesize,a.cover,a.cover_type from "+TBL_BOOKS+" a, "+TBL_BAUTHORS+" b where a.book_id=b.book_id and b.author_id="+str(author_id)+dstr+" and a.avail!=0 order by a.title "+limitstr
  def getbooksforautor(self,author_id,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 a.doublicat=0 '
    if new_period==0: period=''
    else: period=" and (registerdate>now()-INTERVAL %s DAY)"%new_period
    sql="select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.annotation,a.docdate,a.format,a.filesize,a.cover,a.cover_type from "+TBL_BOOKS+" a, "+TBL_BAUTHORS+" b where a.book_id=b.book_id and b.author_id="+str(author_id)+" and a.avail!=0 "+dstr+period+" order by a.title "+limitstr
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    rows=cursor.fetchall()
@@ -511,16 +514,14 @@ class opdsDatabase:
    cursor.close
    return rows

  def getseriesbyl(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 c.doublicat=0 '
    sql="select SQL_CALC_FOUND_ROWS a.ser_id, a.ser, count(*) as cnt from "+TBL_SERIES+" a, "+TBL_BSERIES+" b, "+TBL_BOOKS+" c where a.ser_id=b.ser_id and b.book_id=c.book_id and TRIM(a.ser) like %s "+dstr+" and c.avail!=0 group by 1,2 order by 2 "+limitstr
  def getseriesbyl(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 c.doublicat=0 '
    if new_period==0: period=''
    else: period=" and (registerdate>now()-INTERVAL %s DAY) and a.ser_id in (select b.ser_id from bseries b left join books c on b.book_id=c.book_id where registerdate>now()-INTERVAL %s DAY group by b.ser_id)"%(new_period,new_period)
    sql="select SQL_CALC_FOUND_ROWS a.ser_id, a.ser, count(*) as cnt from "+TBL_SERIES+" a, "+TBL_BSERIES+" b, "+TBL_BOOKS+" c where a.ser_id=b.ser_id and b.book_id=c.book_id and TRIM(a.ser) like %s and c.avail!=0 "+dstr+period+" group by 1,2 order by 2 "+limitstr
    data=(letters+'%',)
    cursor=self.cnx.cursor()
    cursor.execute(sql,data)
@@ -536,16 +537,14 @@ class opdsDatabase:
    cursor.close
    return rows

  def getbooksforser(self,ser_id,limit=0,page=0,doublicates=True):
    if limit==0:
       limitstr=""
    else:
       limitstr="limit "+str(limit*page)+","+str(limit)
    if doublicates:
       dstr=''
    else:
       dstr=' and a.doublicat=0 '
    sql="select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.annotation,a.docdate,a.format,a.filesize,a.cover,a.cover_type from "+TBL_BOOKS+" a, "+TBL_BSERIES+" b where a.book_id=b.book_id and b.ser_id="+str(ser_id)+dstr+" and a.avail!=0 order by a.title "+limitstr
  def getbooksforser(self,ser_id,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 a.doublicat=0 '
    if new_period==0: period=''
    else: period=" and (registerdate>now()-INTERVAL %s DAY)"%new_period
    sql="select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.annotation,a.docdate,a.format,a.filesize,a.cover,a.cover_type from "+TBL_BOOKS+" a, "+TBL_BSERIES+" b where a.book_id=b.book_id and b.ser_id="+str(ser_id)+" and a.avail!=0 "+dstr+period+" order by a.title "+limitstr
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    rows=cursor.fetchall()