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
  Trying to Make Steganography Program Work For All Payload Types Stegosaurus 0 1,145 Sep-26-2024, 12:43 PM
Last Post: Stegosaurus
  How to make my Telegram bot stop working at 16:15 and not work on Fridays? hus73 2 1,352 Aug-10-2024, 12:06 PM
Last Post: hus73
  print doesnt work in a function ony 2 1,084 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  hi need help to make this code work correctly atulkul1985 5 1,946 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 1,541 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 2,911 May-22-2023, 10:39 PM
Last Post: ICanIBB
  I dont know why my function won't work? MehHz2526 3 2,025 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  Mysql Syntax error in pymysql ilknurg 4 3,696 May-18-2022, 06:50 AM
Last Post: ibreeden
  Make my py script work only on 1 compter tomtom 14 6,304 Feb-20-2022, 06:19 PM
Last Post: DPaul
  time function does not work tester_V 4 4,670 Oct-17-2021, 05:48 PM
Last Post: tester_V

Forum Jump:

User Panel Messages

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