Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!news.grnet.gr!news.ntua.gr!not-for-mail From: Simpleton Newsgroups: comp.lang.python Subject: Re: Why 'files.py' does not print the filenames into a table format? Date: Mon, 17 Jun 2013 13:26:01 +0300 Organization: National Technical University of Athens, Greece Lines: 125 Message-ID: References: <51beb3f8$0$29872$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: 46.12.160.93.dsl.dyn.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.ntua.gr 1371464762 2061 46.12.160.93 (17 Jun 2013 10:26:02 GMT) X-Complaints-To: usenet@news.ntua.gr NNTP-Posting-Date: Mon, 17 Jun 2013 10:26:02 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Thunderbird/22.0 In-Reply-To: Xref: csiph.com comp.lang.python:48512 On 17/6/2013 12:07 μμ, Simpleton wrote: > On 17/6/2013 10:00 πμ, Steven D'Aprano wrote: >> On Mon, 17 Jun 2013 09:11:05 +0300, Νίκος wrote: >> >>> everything work as expected but not the part when the counter of a >>> filename gets increased when the file have been requested. >>> >>> I don't see how since: >>> >>> if filename: >>> #update file counter >>> cur.execute('''UPDATE files SET hits = hits + 1, host = %s, >>> lastvisit = %s WHERE url = %s''', (host, lastvisit, filename) ) >> >> > There isn'tmuch to say ehre. You already know the code that im using > inside files.pu and the question is that this execute never gets to > execute. > > # > ================================================================================================================= > > # Make sure that ALL database records are filenames in existance > # > ================================================================================================================= > > filenames = [] > > # Switch filenames from (utf8 bytestrings => unicode strings) and trim > them from their paths > for utf8_filename in utf8_filenames: > filenames.append( utf8_filename.decode('utf-8').replace( > '/home/nikos/public_html/data/apps/', '' ) ) > > # Check the presence of a database file against the dir files and delete > record if it doesn't exist > cur.execute('''SELECT url FROM files''') > data = cur.fetchall() > > # Delete spurious database records > for rec in data: > if rec not in filenames: > cur.execute('''DELETE FROM files WHERE url = %s''', rec ) > > # Load'em > for filename in filenames: > try: > # Check the presence of current filename against it's database > presence > cur.execute('''SELECT url FROM files WHERE url = %s''', filename ) > data = cur.fetchone() > > if not data: > # First time for file; primary key is automatic, hit is > defaulted > cur.execute('''INSERT INTO files (url, host, lastvisit) > VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) > except pymysql.ProgrammingError as e: > print( repr(e) ) > > > # > ================================================================================================================= > > # Display ALL files, each with its own download button > # > ================================================================================================================= > > print(''' >


> > ''') > > try: > cur.execute( '''SELECT * FROM files ORDER BY lastvisit DESC''' ) > data = cur.fetchall() > > for row in data: > (filename, hits, host, lastvisit) = row > lastvisit = lastvisit.strftime('%A %e %b, %H:%M') > > print(''' > > > > > > > > > ''' % (filename, hits, host, lastvisit) ) > print( '''
value="%s">
%s
%s
%s


''' ) > except pymysql.ProgrammingError as e: > print( repr(e) ) > > sys.exit(0) > > After a spcific file gets selected then files.py is reloading grabbign > the filename as a variable form and: > > # > ================================================================================================================= > > # If user downloaded a file, thank the user !!! > # > ================================================================================================================= > > if filename: > #update filename's counter if cookie does not exist > cur.execute('''UPDATE files SET hits = hits + 1, host = %s, > lastvisit = %s WHERE url = %s''', (host, lastvisit, filename) ) > > but the execute never happesn. > i ahve tested it > > if data: > print soemthing > > but data is always empty. So any ideas why the update statements never gets executed? -- What is now proved was at first only imagined!