Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news.grnet.gr!news.ntua.gr!not-for-mail From: =?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?= Newsgroups: comp.lang.python Subject: Re: Turnign greek-iso filenames => utf-8 iso Date: Thu, 13 Jun 2013 17:28:38 +0300 Organization: National Technical University of Athens, Greece Lines: 117 Message-ID: <51B9D716.80207@superhost.gr> References: <51b83b6d$0$29998$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: 79.103.41.173.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 1371133719 74370 79.103.41.173 (13 Jun 2013 14:28:39 GMT) X-Complaints-To: usenet@news.ntua.gr NNTP-Posting-Date: Thu, 13 Jun 2013 14:28:39 +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:47971 On 13/6/2013 9:49 πμ, Νικόλαος Κούρας wrote: > On 12/6/2013 1:40 μμ, Νικόλαος Κούρας wrote: >> Thanks Steven , i made some alternations to the variables names and at >> the end of the way that i check a database filename against and hdd >> filename. Here is the code: >> >> # >> ================================================================================================================= >> >> >> # 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') ) >> >> >> # Switch filenames from utf8 bytestrings => unicode strings >> filenames = [] >> >> for utf8_filename in utf8_filenames: >> filenames.append( utf8_filename.decode('utf-8') ) >> >> # 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() >> >> for url in data: >> if url not in filenames: >> # Delete spurious >> cur.execute('''DELETE FROM files WHERE url = %s''', url ) >> ========================= >> >> Now 'http://superhost.gr/?page=files.py' is not erring out at all but >> also it doesn't display the big filename table for users to download. >> >> Here is how i try to print the filenames with button for the users: >> >> ================================================================================================================= >> >> >> #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) ) > > Steven, i can create a normal user account for you and copy files.py > into your home folder if you want to take a look from within. > > Since the code seems correct, cause its not erring out and you 've > helped me write it, then i dont knwo what else to try. > > Those files inside 'apps' dir ought to be printed in an html table fter > their utf-8 conversion. > > They still insist not to... Can you accept please? or suggest something i should try so for the files to be correctly viewed by my visitors?