Why 'files.py' does not print the filenames into a table format?
Simpleton
support at superhost.gr
Mon Jun 17 06:26:01 EDT 2013
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('''<body background='/data/images/star.jpg'>
> <center><img src='/data/images/download.gif'><br><br>
> <table border=5 cellpadding=5 bgcolor=green>
> ''')
>
> 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('''
> <form method="get" action="/cgi-bin/files.py">
> <tr>
> <td> <center> <input type="submit" name="filename"
> value="%s"> </td>
> <td> <center> <font color=yellow size=5> %s </td>
> <td> <center> <font color=orange size=4> %s </td>
> <td> <center> <font color=silver size=4> %s </td>
> </tr>
> </form>
> ''' % (filename, hits, host, lastvisit) )
> print( '''</table><br><br>''' )
> 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!
More information about the Python-list
mailing list