F
Ferrous Cranus
There is not newsgroup called 'python-greece'. i searched.Not valid in the same way that (e-mail address removed) is not valid?
There is not newsgroup called 'python-greece'. i searched.Not valid in the same way that (e-mail address removed) is not valid?
Not valid in the same way that (e-mail address removed) is not valid?
Then how those page entries found in the database Chris?
What happens if i write it like this?
cur.execute('''SELECT ID FROM counters WHERE url = "%s"''', page )
How quoting of %s helps here?
Yes iam using a comma and not a substitute operator, so input is mysql
validates.
Please explain what is an "out-of-band argument passing method"
What your idea of those entries made it to the counters database table?
TB behaves for me the same way. Any line > 80 chars gets a newline.
Why this is happening? Why not post up to 256 chars in a single line?
Actually i twas a short story since i have asked this already in 2
previous threads of mine, but here it is the whole thing pasted in
pastebin. Its not so biug and with your talent you could understand it
in aprox. 5 mins.
http://pastebin.com/XgWKuXUC
Congratulation. You have just entered an extremely exclusive club. See
you in a month.
*plonk*
So yours are the only pissy one-liner responses that shouldn't be
taken off-list?
Look, Nick,
A lot of people are frustrated by you. You should understand that. If
you cannot, you need to step back and consider, or you really are a
troll.
Now, obviously it's not going to get you any help to have half of the
forum angry at you. People have stopped helping, at least in large.
This is fine; people here are volunteers. But you want help.
So, Nick, listen. You need to learn how to ask *smart* questions. If
you do, I *guarantee* that people will respect you a lot more. I'll be
willing to give a bit of time to explain what I mean.
1) What is your problem. Not "I want to know why it doesn't print
anything." Here's an example, for some random idea:
2) What have you tried? What debugging have you done? For someone of
your skill level, it's also important to tell us what you think your
code is doing. Example:
3) If possible, give us an example we can run.
Do you see the difference?
Sure. Here I go:
What's the question?
Look, Nick,
A lot of people are frustrated by you. You should understand that. If
you cannot, you need to step back and consider, or you really are a
troll.
Now, obviously it's not going to get you any help to have half of the
forum angry at you. People have stopped helping, at least in large.
This is fine; people here are volunteers. But you want help.
So, Nick, listen. You need to learn how to ask *smart* questions. If
you do, I *guarantee* that people will respect you a lot more. I'll be
willing to give a bit of time to explain what I mean.
1) What is your problem. Not "I want to know why it doesn't print
anything." Here's an example, for some random idea:
2) What have you tried? What debugging have you done? For someone of
your skill level, it's also important to tell us what you think your
code is doing. Example:
3) If possible, give us an example we can run.
Do you see the difference?
Sure. Here I go:
What's the question?
I DID, I FINALLY DID IT JUST NOW!!
HERE ARE THE MODIFICATIONS THAT MADE IT HAPPEN!
==========================================================================================================
# Convert wrongly encoded filenames to utf-8
==========================================================================================================
path = b'/home/nikos/public_html/data/apps/'
filenames = os.listdir( path )
utf8_filenames = []
for filename in filenames:
# Compute 'path/to/filename'
filename_bytes = path + filename
encoding = guess_encoding( filename_bytes )
if encoding == 'utf-8':
# File name is valid UTF-8, so we can skip to the next file.
utf8_filenames.append( filename_bytes )
continue
elif encoding is None:
# No idea what the encoding is. Hit it with a hammer until it
stops moving.
filename = filename_bytes.decode( 'utf-8', 'xmlcharrefreplace' )
else:
filename = filename_bytes.decode( encoding )
# Rename the file to something which ought to be UTF-8 clean.
newname_bytes = filename.encode('utf-8')
os.rename( filename_bytes, newname_bytes )
utf8_filenames.append( newname_bytes )
# Once we get here, the file ought to be UTF-8 clean and the
Unicode name ought to exist:
assert os.path.exists( newname_bytes.decode('utf-8') )
================================
i SMASHED MY HEAD INTO THE WALL, BUT I MADE IT!!!!
FINALLY AFTER > 15 DAYS!!
FEEL FREE TO CONGRATULATE ME!
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) )
# 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) )
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.
The code is completely ready.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.