Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58526

Re: Help me with this code PLEASE

From Nick the Gr33k <nikos.gr33k@gmail.com>
Newsgroups comp.lang.python
Subject Re: Help me with this code PLEASE
Date 2013-11-05 23:26 +0200
Organization A noiseless patient Spider
Message-ID <l5bnpc$71v$1@dont-email.me> (permalink)
References <l5b8if$4k1$1@dont-email.me> <l5bjs6$84r$1@reader1.panix.com>

Show all headers | View raw


Στις 5/11/2013 10:19 μμ, ο/η John Gordon έγραψε:
> In <l5b8if$4k1$1@dont-email.me> Nick the Gr33k <nikos.gr33k@gmail.com> writes:
>
>> IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.
>
>> ALL I WANT IT TO DO IS JUST
>
>> 1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
>> 2. CONVERT LONG STRINGS TO LISTS
>> 3. ADD SOME CURRENT VALUES TO THOSE LISTS
>> 4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST
>> PYTHON DATATYPE TO MYSQL SCALAR STRING.
>
>> EVERYHTIGN I TRIED FAILED.
>
> How did it fail?
>
> Error message?
> No results at all?
> Different results than you wanted?  If so, how did they differ?
>


I know i'm close to solution, i can feel it but i have some issues.
The code we arr discussing is the following:


=================================================================================================================
# ~ DATABASE INSERTS ~
=================================================================================================================
if cookieID != 'nikos' and ( os.path.exists( path + page ) or 
os.path.exists( cgi_path + page ) ) and re.search( 
r'(amazon|google|proxy|cloud|reverse|fetch|msn|who|spider|crawl|ping)', 
host ) is None:

	try:
		# if first time for webpage; create new record( primary key is 
automatic, hit is defaulted ), if page exists then update record
		cur.execute('''INSERT INTO counters (url) VALUES (%s) ON DUPLICATE KEY 
UPDATE hits = hits + 1''', page )
		cID = cur.lastrowid

		# fetch those columns that act as lists but are stored as strings
		cur.execute('''SELECT refs, visits, downloads FROM visitors WHERE 
counterID = %s and host = %s''', (cID, host) )
		data = cur.fetchone()

		ref = visit = download = []
		if cur.rowcount:
			# unpack data into variables
			(ref, visit, download) = data
		
			# retrieve long strings and convert them into lists respectively
			ref = ref.split()
			visit = visit.split()
			download = download.split()
		else:
			# initiate these values
			ref = ref
			visit = lastvisit
			download = ''
		
		refs = visits = downloads = []
		# add current values to each list respectively
		refs.append( ref )
		visits.append( visit )
		downloads.append( download )
		
		# convert lists back to longstrings
		refs = ', '.join( refs )
		visits = ', '.join( visits )
		downloads = ', '.join( downloads )

		# save this visit as an entry into database
		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
						ON DUPLICATE KEY UPDATE refs = %s, visits = %s, hits = hits + 1, 
downloads = %s''',
						(cID, refs, host, city, useros, browser, visits, downloads, refs, 
visits, downloads) )

		con.commit()
	except pymysql.ProgrammingError as e:
		print( repr(e) )
		con.rollback()
		sys.exit(0)
===============================================


[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 274, in <module>
[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218]     visit = 
visit.split()
[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218] 
AttributeError: 'NoneType' object has no attribute 'split'

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help me with this code PLEASE Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 19:06 +0200
  Re: Help me with this code PLEASE Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-05 18:23 +0100
  Re: Help me with this code PLEASE mm0fmf <none@mailinator.com> - 2013-11-05 17:33 +0000
  Re: Help me with this code PLEASE Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-05 17:41 +0000
    Re: Help me with this code PLEASE Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-05 18:53 +0100
    Re: Help me with this code PLEASE Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 19:59 +0200
      Re: Help me with this code PLEASE Tobiah <toby@tobiah.org> - 2013-11-05 10:11 -0800
        Re: Help me with this code PLEASE Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-05 14:01 -0500
  Re: Help me with this code PLEASE Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-05 18:02 +0000
    Re: Help me with this code PLEASE Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 20:09 +0200
      Re: Help me with this code PLEASE Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-05 20:10 +0000
      Re: Help me with this code PLEASE Cameron Simpson <cs@zip.com.au> - 2013-11-06 09:31 +1100
      Re: Help me with this code PLEASE bob gailer <bgailer@gmail.com> - 2013-11-05 18:15 -0500
      Re: Help me with this code PLEASE Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-05 23:36 +0000
  Re: Help me with this code PLEASE John Gordon <gordon@panix.com> - 2013-11-05 20:19 +0000
    Re: Help me with this code PLEASE Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-05 21:17 +0000
    Re: Help me with this code PLEASE Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 23:26 +0200
      Re: Help me with this code PLEASE John Gordon <gordon@panix.com> - 2013-11-05 22:06 +0000
        Re: Help me with this code PLEASE Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-06 00:28 +0200
          Re: Help me with this code PLEASE Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-05 22:44 +0000
          Re: Help me with this code PLEASE John Gordon <gordon@panix.com> - 2013-11-05 22:54 +0000
            Re: Help me with this code PLEASE Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-06 03:14 +0200
              Re: Help me with this code PLEASE Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-06 08:49 +0000
              Re: Help me with this code PLEASE Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-06 08:57 -0500
      Re: Help me with this code PLEASE Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-06 09:27 +0100
    Re: Help me with this code PLEASE Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-05 21:42 +0000
    Re: Help me with this code PLEASE Chris Angelico <rosuav@gmail.com> - 2013-11-06 09:03 +1100
  Re: Help me with this code PLEASE Piet van Oostrum <piet@vanoostrum.org> - 2013-11-05 18:15 -0400
    Re: Help me with this code PLEASE Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-06 00:35 +0200
      Re: Help me with this code PLEASE Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-06 00:45 +0000
        Re: Help me with this code PLEASE Ben Finney <ben+python@benfinney.id.au> - 2013-11-06 12:46 +1100
        Re: Help me with this code PLEASE Grant Edwards <invalid@invalid.invalid> - 2013-11-06 14:50 +0000
    Re: Help me with this code PLEASE Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-05 19:32 -0500

csiph-web