Στις 5/11/2013 10:19 μμ, ο/η John Gordon έγραψε:
In <l5b8if$4k1$1...@dont-email.me> Nick the Gr33k <nikos.gr...@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'
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to