Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'error:': 0.05; 'data:': 0.07; 'filename': 0.07; 'subject:file': 0.07; 'subject:form': 0.07; 'try:': 0.07; 'indication': 0.09; 'cc:addr :python-list': 0.10; '(%s,': 0.16; '(filename,': 0.16; 'hits': 0.16; 'traceback.': 0.16; 'wrote:': 0.17; 'code,': 0.18; 'email addr:gmail.com>': 0.20; 'skip:" 30': 0.20; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'values': 0.26; 'am,': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; 'correct': 0.28; 'record': 0.28; 'unique,': 0.29; 'url:mailman': 0.29; 'primary': 0.30; 'url:python': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'skip:s 30': 0.33; 'received:google.com': 0.34; 'needed': 0.35; 'path': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'except': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'page': 0.38; 'where': 0.40; 'help': 0.40; 'url:mail': 0.40; 'save': 0.61; 'hours': 0.66; '2013': 0.84; 'cid': 0.84; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=p4dPucEfHT2ZoGnUEUbOw6cWzVHxf1m78HWeVG++ZBw=; b=jLNECpGFbog4P2QtKah1q50H0NhNaRGGF6dDJ8LoZOtW0gwpXcsvxtcrv9mx+yORrl KLV0ltwQCuSMCwJ6grM4oZqHb/8DueaT/H22u2YbF2sCJq44Nc3XPvFOqWaL0wNVac3i a41P+veO9uZ/SH/H1vr/+RTLNqwP2JmhoDWEyoYGtGuyvDHBM+z6HjkZekC1o2CcFob4 /9knRXcANfVXsK5kmcAqpOCpbtuu4uwAhue7QTu7kBchbOtGeZ5KzJybcbrcX640Xg+c 7gCAnonHNKN8qxlXeaQMGEh8v23WKbABChklmICeA33YGD784Q81bjutXaEy9rQtd69h ZuVA== MIME-Version: 1.0 X-Received: by 10.52.155.5 with SMTP id vs5mr5246560vdb.24.1362490708808; Tue, 05 Mar 2013 05:38:28 -0800 (PST) In-Reply-To: References: Date: Tue, 5 Mar 2013 08:38:28 -0500 Subject: Re: Downloading a file form a displayed table From: Joel Goldstick To: =?UTF-8?B?zp3Or866zr/PgiDOk866z4EzM866?= Content-Type: multipart/alternative; boundary=089e01633a94b59ab004d72d9648 Cc: "python-list@python.org" 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: 115 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362490712 news.xs4all.nl 6849 [2001:888:2000:d::a6]:33084 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40526 --089e01633a94b59ab004d72d9648 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Mar 5, 2013 at 8:01 AM, =CE=9D=CE=AF=CE=BA=CE=BF=CF=82 =CE=93=CE=BA= =CF=8133=CE=BA wrote: > Please help me correct thois code, iam tryign ti for hours and i cant see= m > to get it working....it irritates me.... > There is no question here. No indication of what isn't working as you like. No traceback. > > path =3D "/home/nikos/public_html/data/files/" > for filename in os.walk(path): > try: > #find the needed counter for the page URL > cur.execute('''SELECT ID FROM files WHERE URL =3D %s''', > (filename,) ) > data =3D cur.fetchone() #URL is unique, so should > only be one > > if not data: > #first time for page; primary key is automatic, > hit is defaulted > cur.execute('''INSERT INTO files (URL, lastvisit) > VALUES (%s, %s)''', (filename, date) ) > cID =3D cur.lastrowid #get the primary key > value of the new record > else: > #found the page, save primary key and use it to > issue hit UPDATE > cID =3D data[0] > cur.execute('''UPDATE files SET hits =3D hits + 1= , > lastvisit =3D %s WHERE ID =3D %s''', (date, cID) > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2]= ) > -- > http://mail.python.org/mailman/listinfo/python-list > --=20 Joel Goldstick http://joelgoldstick.com --089e01633a94b59ab004d72d9648 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Tue, Mar 5, 2013 at 8:01 AM, =CE=9D=CE=AF=CE=BA=CE=BF=CF=82 =CE= =93=CE=BA=CF=8133=CE=BA <nikos.gr33k@gmail.com> wrote:
Please help me correct thois code, iam tryig= n ti for hours and i cant seem to get it working....it irritates me....

There is no question here.=C2=A0 No indica= tion of what isn't working as you like.=C2=A0 No traceback.=C2=A0=C2=A0=

path =3D "/home/nikos/public_html/data/files/"
for filename in os.walk(path):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 try:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 #find the needed co= unter for the page URL
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cur.execute('&#= 39;'SELECT ID FROM files WHERE URL =3D %s''', (filename,) )=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 data =3D cur.fetcho= ne() =C2=A0 =C2=A0 =C2=A0 =C2=A0#URL is unique, so should only be one

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if not data:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 #first time for page; primary key is automatic, hit is defaulted=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 cur.execute('''INSERT INTO files (URL, lastvisit) VA= LUES (%s, %s)''', (filename, date) )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 cID =3D cur.lastrowid =C2=A0 =C2=A0 =C2=A0 =C2=A0#get the primar= y key value of the new record
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 #found the page, save primary key and use it to issue hit UPDATE=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 cID =3D data[0]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 cur.execute('''UPDATE files SET hits =3D hits + 1, l= astvisit =3D %s WHERE ID =3D %s''', (date, cID)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 except MySQLdb.Error, e:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 print ( "Query= Error: ", sys.exc_info()[1].excepinfo()[2] )
--
http://mail.python.org/mailman/listinfo/python-list



--
--089e01633a94b59ab004d72d9648--