Commit 424a5ecc authored by mitshel's avatar mitshel
Browse files

Начата работа поиска новинок (Сделано в первом приближение вычислиене новинок по наименованиям)

parent e69dfa48
Loading
Loading
Loading
Loading
+40 −14
Original line number Diff line number Diff line
@@ -111,11 +111,33 @@ def main_menu():
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id='+am+'06"/>')
   enc_print('<id>id:06</id></entry>')
   enc_print('<entry>')
   enc_print('<title>Последние добавленные</title>')
   enc_print('<content type="text">Книг: %s.</content>'%(cfg.MAXITEMS))
   enc_print('<title>Новинки за %s суток</title>'%cfg.NEW_PERIOD)
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id=05"/>')
   enc_print('<id>id:05</id></entry>')

def new_menu():
   if cfg.ALPHA: am='30'
   else: am=''
   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('<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('<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('<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('<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>')

def entry_start():
   enc_print('<entry>')

@@ -252,6 +274,7 @@ type_value=0
slice_value=0
page_value=0
alpha=0
news=0

form = cgi.FieldStorage()
if 'id' in form:
@@ -278,6 +301,8 @@ if 'searchTerm' in form:
if 'alpha' in form:
   salpha=form.getvalue("alpha","").strip()
   if salpha.isdigit(): alpha=int(salpha)
if 'news' in form:
   news=1

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

   header()
   for (letters,cnt) in opdsdb.gettitle_2letters(letter,cfg.DUBLICATES_SHOW,alpha):
   for (letters,cnt) in opdsdb.gettitle_2letters(letter,cfg.DUBLICATES_SHOW,alpha,news):
       id=""
       for i in range(len(letters)):
           id+='%04d'%(ord(letters[i]))
@@ -485,17 +510,18 @@ if type_value==24:
#
elif type_value==5:
   header()
   for (book_id,book_name,book_path,reg_date,book_title,annotation,docdate,format,fsize,cover,cover_type) in opdsdb.getlastbooks(cfg.MAXITEMS):
       id='90'+str(book_id)
       entry_start()
       entry_head(book_title, reg_date, id_value)
       entry_link_book(book_id,format)
       entry_covers(cover,cover_type,book_id)
       authors=entry_authors(opdsdb,book_id,True)
       genres=entry_genres(opdsdb,book_id)
       series=entry_series(opdsdb,book_id)
       entry_content2(annotation,book_title,authors,genres,book_name,fsize,docdate,series)
       entry_finish()
   new_menu()
#   for (book_id,book_name,book_path,reg_date,book_title,annotation,docdate,format,fsize,cover,cover_type) in opdsdb.getlastbooks(cfg.MAXITEMS):
#       id='90'+str(book_id)
#       entry_start()
#       entry_head(book_title, reg_date, id_value)
#       entry_link_book(book_id,format)
#       entry_covers(cover,cover_type,book_id)
#       authors=entry_authors(opdsdb,book_id,True)
#       genres=entry_genres(opdsdb,book_id)
#       series=entry_series(opdsdb,book_id)
#       entry_content2(annotation,book_title,authors,genres,book_name,fsize,docdate,series)
#       entry_finish()
   footer()

#########################################################
+32 −50
Original line number Diff line number Diff line
@@ -21,20 +21,31 @@ NOCOVER_IMG='nocover.jpg'
import configparser

class ConfigParser_new(configparser.ConfigParser):
   def get_default(self,section,value,default_value):

   def getdefault(self,section,value,default_value):
     try:
       result=self.get(section,value)
     except:
       result=default_value
     return result

   def getboolean_default(self,section,value,default_value):
   def getdefault_bool(self,section,value,default_value):
     try:
       result=self.getboolean(section,value)
     except:
       result=default_value
     return result

   def getdefault_int(self,section,value,default_value):
     try:
       strval=self.get(section,value)
       if strval.isdigit(): result=int(strval)
       else: result=default_value
     except:
       result=default_value
     return result



class cfgreader:
   def __init__(self,configfile=CFG_PATH):
@@ -44,17 +55,17 @@ class cfgreader:
       config.readfp(codecs.open(self.CONFIGFILE,"r","utf-8"))
       CFG_S_GLOBAL='global'

       self.CGI_PATH=config.get_default(CFG_S_GLOBAL,'cgi_path','sopds.cgi')
       self.CGI_PATH=config.getdefault(CFG_S_GLOBAL,'cgi_path','sopds.cgi')
       self.CGI_PATH=os.path.normpath(self.CGI_PATH)
       self.SEARCHXML_PATH=os.path.join(os.path.dirname(self.CGI_PATH),'opds-opensearch.xml')

       self.COVER_PATH=config.get_default(CFG_S_GLOBAL,'cover_path','../covers')
       self.COVER_PATH=config.getdefault(CFG_S_GLOBAL,'cover_path','../covers')
       self.COVER_PATH=os.path.normpath(self.COVER_PATH)

       self.FB2TOEPUB_PATH=config.get_default(CFG_S_GLOBAL,'fb2toepub',None)
       self.FB2TOEPUB_PATH=config.getdefault(CFG_S_GLOBAL,'fb2toepub',None)
       self.FB2TOEPUB=self.FB2TOEPUB_PATH!=None and os.path.isfile(self.FB2TOEPUB_PATH)

       self.TEMP_DIR=config.get_default(CFG_S_GLOBAL,'temp_dir','/tmp')
       self.TEMP_DIR=config.getdefault(CFG_S_GLOBAL,'temp_dir','/tmp')
       self.TEMP_DIR=os.path.normpath(self.TEMP_DIR)
   
       self.DB_NAME=config.get(CFG_S_GLOBAL,'db_name')
@@ -71,51 +82,23 @@ class cfgreader:
       self.ZIPRESCAN=config.getboolean(CFG_S_GLOBAL,'ziprescan')
       self.COVER_EXTRACT=config.getboolean(CFG_S_GLOBAL,'cover_extract')
       self.DELETE_LOGICAL=config.getboolean(CFG_S_GLOBAL,'delete_logical')
       self.ZIPFILE_PATCH=config.getboolean_default(CFG_S_GLOBAL,'zipfile_patch',False)
       self.SINGLE_COMMIT=config.getboolean_default(CFG_S_GLOBAL,'single_commit',False)
       self.TITLE_AS_FN=config.getboolean_default(CFG_S_GLOBAL,'title_as_filename',False)
       self.ALPHA=config.getboolean_default(CFG_S_GLOBAL,'alphabet_menu',True)
       fb2hsize=config.get(CFG_S_GLOBAL,'fb2hsize')
       maxitems=config.get(CFG_S_GLOBAL,'maxitems')
       splitauthors=config.get(CFG_S_GLOBAL,'splitauthors')
       splittitles=config.get(CFG_S_GLOBAL,'splittitles')
       cover_show=config.get(CFG_S_GLOBAL,'cover_show')
       zip_codepage=config.get_default(CFG_S_GLOBAL,'zip_codepage','cp866')

       if maxitems.isdigit():
          self.MAXITEMS=int(maxitems)
       else:
          self.MAXITEMS=50

       if fb2hsize.isdigit():
          self.FB2HSIZE=int(fb2hsize)
       else:
          self.FB2HSIZE=0

       if self.COVER_EXTRACT:
          self.FB2SIZE=0

       if splitauthors.isdigit():
          self.SPLITAUTHORS=int(splitauthors)
       else:
          self.SPLITAUTHORS=0

       if splittitles.isdigit():
          self.SPLITTITLES=int(splittitles)
       else:
          self.SPLITTITLES=0

       if cover_show.isdigit():
          self.COVER_SHOW=int(cover_show)
       else:
          self.COVER_SHOW=0

       self.ZIPFILE_PATCH=config.getdefault_bool(CFG_S_GLOBAL,'zipfile_patch',False)
       self.SINGLE_COMMIT=config.getdefault_bool(CFG_S_GLOBAL,'single_commit',False)
       self.TITLE_AS_FN=config.getdefault_bool(CFG_S_GLOBAL,'title_as_filename',False)
       self.ALPHA=config.getdefault_bool(CFG_S_GLOBAL,'alphabet_menu',True)
       self.FB2HSIZE=config.getdefault_int(CFG_S_GLOBAL,'fb2hsize',0)
       self.MAXITEMS=config.getdefault_int(CFG_S_GLOBAL,'maxitems',50)
       self.SPLITAUTHORS=config.getdefault_int(CFG_S_GLOBAL,'splitauthors',0)
       self.SPLITTITLES=config.getdefault_int(CFG_S_GLOBAL,'splittitles',0)       
       self.COVER_SHOW=config.getdefault_int(CFG_S_GLOBAL,'cover_show',0)
       self.NEW_PERIOD=config.getdefault_int(CFG_S_GLOBAL,'new_period',7)
       zip_codepage=config.getdefault(CFG_S_GLOBAL,'zip_codepage','cp866')

       if self.COVER_EXTRACT: self.FB2SIZE=0
       self.EXT_LIST=self.FORMATS.lower().split()

       if zip_codepage.lower() in {'cp437','cp866','cp1251','utf-8'}:
          self.ZIP_CODEPAGE=zip_codepage.lower()
       else:
          self.ZIP_CODEPAGE='cp437'
       if zip_codepage.lower() in {'cp437','cp866','cp1251','utf-8'}: self.ZIP_CODEPAGE=zip_codepage.lower()
       else: self.ZIP_CODEPAGE='cp437'

       CFG_S_SITE='site'
       self.SITE_ID=config.get(CFG_S_SITE,'id')
@@ -125,4 +108,3 @@ class cfgreader:
       self.SITE_URL=config.get(CFG_S_SITE,'url')
       self.SITE_EMAIL=config.get(CFG_S_SITE,'email')
       self.SITE_MAINTITLE=config.get(CFG_S_SITE,'main_title')
+25 −9
Original line number Diff line number Diff line
@@ -402,11 +402,11 @@ class opdsDatabase:
    cursor.close
    return rows

  def gettitle_2letters(self,letters,doublicates=True,alpha=0):
    if doublicates:
       dstr=''
    else:
       dstr=' and doublicat=0 '
  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
    lc=len(letters)+1
    having=''
    if lc==1:
@@ -414,6 +414,8 @@ 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"
    cursor=self.cnx.cursor()
@@ -620,10 +622,9 @@ class opdsDatabase:
    return rows

  def getdbinfo(self,doublicates=True):
    if doublicates:
       dstr=''
    else:
       dstr='and doublicat=0'
    if doublicates: dstr=''
    else: dstr='and doublicat=0'

    sql="select 1 s, count(avail) from %s where avail!=0 %s union all select 2 s, count(author_id) from %s union all select 3 s, count(cat_id) from %s union all select 4 s, count(genre_id) from %s union all select 5 s, count(ser_id) from %s order by s"%(TBL_BOOKS,dstr,TBL_AUTHORS,TBL_CATALOGS,TBL_GENRES,TBL_SERIES)
    cursor=self.cnx.cursor()
    cursor.execute(sql)
@@ -631,6 +632,21 @@ class opdsDatabase:
    cursor.close
    return rows

  def getnewinfo(self,doublicates=True,new_period=0):
    if doublicates: dstr=''
    else: dstr='and doublicat=0'

    if new_period==0: period=''
    else: period='and registerdate-INTERVAL %s DAY'%new_period

    sql="select 1 s, count(avail) from %s where avail!=0 %s %s"%(TBL_BOOKS,dstr,period)
    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()