High Latency Life

High Latency Life

Coding/Research/Music/Gaming Blog by Stefano Giovanni Rizzo

Drop us a line...

Send Message
How to (really) fetch one row at a time with pymysql

I wasted some time today with python to find out how to create an unbuffered cursor for pymysql, which i use to connect to MySQL dbs instead of MySQLdb.

By default pymysql fetch all the rows of your SELECTs, even if you use fetchone instead of fetchall, because by default when you create a pymysql cursor with connection.cursor() the cursor is a buffered


The unbuffered cursor is really useful, and sometimes necessary, if you need to get a large amount of data. In order to do so:

conn = pymysql.connect(host= "localhost",user="youruser",passwd="xxxxx",db="mydb")

# get for example every row

query='SELECT * FROM names'

# create the unbuffered cursor with pymysql.cursors.SSCursor class

x = conn.cursor(pymysql.cursors.SSCursor)

# execute your query
# get one row at a time

row = x.fetchone()

while row is not None:

#...do your dirty things with the row

row = x.fetchone()

GDrive Backup tool to backup Google Drive including Google Docs
GDrive Backup Tool Mac OSX

GDrive Backup Tool Mac OSX

GDrive Backup is a tool for Mac i developed (dirty and quickly!) to automatically backup Google Drive & Google Docs files in a selected directory, exporting Google documents in MSOffice formats.

As you may know, Google Docs files have no content locally, instead have the resource-id reference in a JSON format. For this reason backup the whole Google Drive directory becomes difficult, because locally you still won’t have the Google Docs files content. The only way is to export the Google Docs document in a readable format. How can we do this automatically? Google’s APIs come in help! To make things easier, i used python and the PyDrive library, which makes the Google API OAuth2 steps very easy:

gauth = GoogleAuth()

GDrive Backup, as I named in a lack of creativity, check whether every file is a Google Docs file (gdoc,gdraw,gsheet,gslide) and if this is the case exports with a Microsoft Office mimetype (this can be done in other MimeTypes):

data = json.load(json_data)
pos = data['resource_id'].find(':') + 1
gdoc_id = data['resource_id'][pos:]
gfile = drive.CreateFile({'id': gdoc_id})
gfile.GetContentFile(dst_path, mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document')

In this snippet the resource ID of the Google Docs file is extracted (after the colon) and used to retrieve the Google Docs document with the PyDrive GetContentFile method. I used rumps to make a simple status bar interface on OSX, and py2app to build an .app from the python script. The tool is in a very beta version but it works!

Download the app below.

Download GDrive Backup 0.1
Accordi – Brunori Sas – Le Quattro Volte

I couldn’t find the chords of this song online, so here they are for everyone interested:

Note: if you don’t know this notation this is the coding table:

Do C
Re D
Mi E
Fa F
Sol G
La A
Si B


FA: 133211
FA7+: 003210
DO4: 032011
DO: 032010
SIb: 113331
SIb5b: x12330


Devo (FA)solo arriv(FA7+)are alla (FA)quinta element(FA7+)are
per (FA)diventare (FA7+)grande grande (FA)come mio (FA7+)padre
(DO4)metterò il gremì(DO)biule
e im(DO4)parerò a vol(DO)are
e (SIb5b)scriverò poesie (SIb)d’amore solt(SIb5b)anto per mia ma(FA)dre (FA7+)(FA)(FA7+)

devo (FA)solo arriv(FA7+)are agli es(FA)ami di maturi(FA7+)tà
(FA)prendermi sto dipl(FA7+)oma
e poi (FA)dopo si ved(FA7+)rà
non mi (DO4)piace la scu(DO)ola
non mi (DO4)piace studi(DO)are
voglio (SIb5b)solo suon(SIb)are
voglio (SIb5b)bere e fu(SIb)ma (FA)re(FA7+)(FA)(FA7+)

e un’(DO)altro capodanno
un’(LAm)altro carnevale
un’(SIb)altro ferragosto
e ancora un’altro Natale
la (DO)prima comunione
il (LAm)primo funerale
la (SIb)festa del paese
la morte del maiale

(DO)si può (LAm)nasce(SIb)re un’altra volta
(DO)poi rin(LAm)asce(SIb)re
ancora un’altra volta se ti (FA)va (FA7+)(FA)(FA7+)(FA)(FA7+)(FA)(FA7+)

devo (FA)solo arri(FA7+)vare
alla FA)fine del (FA7+)mese
(FA)prendere lo stip(FA7+)endio
e poi ba(FA)dare alle (FA7+)spese
con (DO4)quello che rim(DO)ane
programm(DO4)are le (DO)ferie
quest’(SIb5b)anno vado al (SIb)mare
che mi (SIb5b)voglio rilas(SIb)sa(FA)re (FA7+)(FA)(FA7+)

devo (FA)solo arriv(FA7+)are
a due (FA)passi dall’alt(FA7+)are
(FA)prendere una (FA7+)moglie
e poi (FA)essere un buon (FA7+)padre
e (DO4)dopo 40 (DO)anni forse (DO4)prendere la pens(DO)ione
con (SIb5b)l’orologio (SIb)d’oro al polso
e il (SIb5b)gelo dentro al (SIb)cuor(FA)e (FA7+)(FA)(FA7+)

e un’(DO)altro capodanno
un’(LAm)altro carnevale
un’(SIb)altro ferragosto
e ancora un’altro Natale
la (DO)prima comunione
il (LAm)primo funerale
la (SIb)festa del paese
la carne del maiale

(DO)si può (LAm)nasce(SIb)re un’altra volta
(DO)poi ri(LAm)nasce(SIb)re
ancora un’altra volta se ti (FA)va (FA7+)(FA)(FA7+)
(SIb5b)(SIb)(SIb5b)ancora un’(SIb)altra (FA)volta
se ti (SIb)va

i (DO)fiori dentro i vasi
i (LAm)fiumi dentro i mari
i (SIb)funghi sotto i rami secchi
i fumi dei camini
e (DO)passeranno i giorni
e (LAm)passeranno gli anni
e (SIb)brinderemmo ancora per 200 capodanni

(DO)si può (LAm)nasce(SIb)re un’altra volta
(DO)poi ri(LAm)nasce(SIb)re
ancora un’altra volta

(DO)si può (LAm)nasce(SIb)re un’altra volta
(DO)poi ri(LAm)nasce(SIb)re
ancora un’altra volta se ti va

A Day Out – Penisola Porto Cesareo

So i was alone today bothering with nothing to do, it was cloudy so the weather was not good enough to go on the beach to get a tan (i’m the whitest of all my friends at the moment), i decide to take a bike trip to the beautiful peninsula of Porto Cesareo and take some pictures with my new camera.
This is a nice and quiet place to take a break from the over populated beaches, where access to cars is not permitted.

buy active instagram followers buy facebook subscribers orlando seo