Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'error:': 0.05; 'data:': 0.07; 'filename': 0.07; 'filenames': 0.07; 'host,': 0.07; 'try:': 0.07; 'inserted': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple': 0.09; 'stored': 0.10; '%s,': 0.16; '(%s,': 0.16; '(filename,': 0.16; 'file;': 0.16; 'losing': 0.16; 'os.walk': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:based': 0.16; 'subject:values': 0.16; 'wrote:': 0.17; 'skip:" 30': 0.20; 'trying': 0.21; 'skip:= 20': 0.22; 'insert': 0.23; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'values': 0.26; 'header:X-Complaints-To:1': 0.28; 'questions.': 0.29; 'unique,': 0.29; 'folder': 0.30; 'waste': 0.30; 'primary': 0.30; 'from:addr:yahoo.co.uk': 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'subject:data': 0.33; 'to:addr:python- list': 0.33; 'needed': 0.35; 'path': 0.35; 'received:org': 0.36; 'except': 0.36; 'but': 0.36; 'should': 0.36; 'thank': 0.36; 'display': 0.36; 'previous': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'files': 0.38; 'page': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'notice': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'you.': 0.61; 'containing': 0.61; 'world': 0.63; 'skip:= 30': 0.64; 'here': 0.65; 'our': 0.65; 'records': 0.68; 'refusing': 0.84; 'suits': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: sync databse table based on current directory data without losign previous values Date: Wed, 06 Mar 2013 11:52:00 +0000 References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: host-92-18-29-221.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 In-Reply-To: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> X-Antivirus: avast! (VPS 130306-0, 06/03/2013), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362570695 news.xs4all.nl 6928 [2001:888:2000:d::a6]:54466 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40629 On 06/03/2013 07:45, Νίκος Γκρ33κ wrote: > I'am using this snipper to read a current directory and insert all filenames into a databse and then display them. > > But what happens when files are get removed form the directory? > The inserted records into databse remain. > How can i update the databse to only contain the existing filenames without losing the previous stored data? > > Here is what i ahve so far: > > ================================== > path = "/home/nikos/public_html/data/files/" > > #read the containing folder and insert new filenames > for result in os.walk(path): You were told yesterday at least twice that os.walk returns a tuple but you still insist on refusing to take any notice of our replies when it suits you, preferring instead to waste everbody's time with these questions. Or are you trying to get into the Guinness Book of World Records for the laziest bastard on the planet? > for filename in result[2]: > try: > #find the needed counter for the page URL > cur.execute('''SELECT URL FROM files WHERE URL = %s''', (filename,) ) > data = cur.fetchone() #URL is unique, so should only be one > > 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, date) ) > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > ====================== > > Thank you. > -- Cheers. Mark Lawrence