Python Forum
Rewrite a function to make it work with 'bottle-pymysql'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rewrite a function to make it work with 'bottle-pymysql'
#1
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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 233 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  hi need help to make this code work correctly atulkul1985 5 702 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 626 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,258 May-22-2023, 10:39 PM
Last Post: ICanIBB
  I dont know why my function won't work? MehHz2526 3 1,150 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  Mysql Syntax error in pymysql ilknurg 4 2,290 May-18-2022, 06:50 AM
Last Post: ibreeden
  Make my py script work only on 1 compter tomtom 14 3,735 Feb-20-2022, 06:19 PM
Last Post: DPaul
  time function does not work tester_V 4 2,946 Oct-17-2021, 05:48 PM
Last Post: tester_V
  pymysql can't do SELECT * Pedroski55 3 2,902 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  write new function or change the old one to work "smartter? korenron 3 1,925 Aug-09-2021, 10:36 AM
Last Post: jamesaarr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020