Python Forum
Rewrite a function to make it work with 'bottle-pymysql' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Rewrite a function to make it work with 'bottle-pymysql' (/thread-16392.html)



Rewrite a function to make it work with 'bottle-pymysql' - nikos - Feb-26-2019

Hello,

Can you help me rewrite this function, which when iam using 'pymysql' conncector works normally, it does not when iam using 'bottle_pymysql'
- απόκρυψη αναφερόμενου κειμένου -

def coalesce( data ): 
        newdata = [] 
        seen = {} 
        for host, ref, location, useros, browser, visits, hits, downloads, authuser in data: 
                # Here i have to decide how to group the rows together 
                # I want an html row for every unique combination of (host) and that hits should be summed together 
                key = host 
                if key not in seen: 
                        newdata.append( [ [host], [ref], location, useros, browser, [visits], hits, [downloads], authuser ] ) 
                        seen[key] = len( newdata ) - 1      # Save index (for 'newdata') of this row 
                else:       # This row is a duplicate row with a different referrer & visit datetime & torrent download 
                        rowindex = seen[key] 
                        newdata[rowindex][0].append( host ) 
                        newdata[rowindex][1].append( ref ) 
                        newdata[rowindex][5].append( visits ) 
                        newdata[rowindex][6] += hits 
                        newdata[rowindex][7].append( downloads ) 
        return newdata 
For some reason in 'bottle-pymysql'

pagehit = cur.fetchone()[0] does not work

while reffering by name of the field

pagehit = cur.fetchone()['hits'] does work.

Please help me write the baove function in a similar way.


RE: Rewrite a function to make it work with 'bottle-pymysql' - nikos - Feb-26-2019

Actually i kust found it has a directive:

dictrows: Whether or not to support dict-like access to row objects (default: True).

so i just did:

plugin = bottle_pymysql.Plugin( dbuser='nikos', dbpass='*****', dbname='counters', dictrows=False )

and now it works with indexes as integers not as strings.