Welcome, guest | Sign In | My Account | Store | Cart

gnokii is a tool allowing Nokia cellphone users to browse its content, when connected to a computer through a cable, IR or bluetooth. This simple script brings lots of automatization of this process.

Python, 43 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
from popen2 import popen3

class FetchPhotos:
    bin = "gnokii"
    dir = "A:\predefgallery\predefphotos\\"
    dest = "."
    file_list = []

    def __init__(self, **kwargs):
        if kwargs.has_key("bin"):
            self.bin = kwargs["bin"]
        if kwargs.has_key("dir"):
            self.dir = kwargs["dir"]
        if kwargs.has_key("dest"):
            self.dest = kwargs["dest"]

    def fetchList(self):
        (stdout, stdin, stderr) = popen3("%s --getfilelist '%s*.*'" % (self.bin, self.dir))
        list = stdout.readlines()
        # Useless gnokii prompt
        del list[0]
        # Get rid of whitespaces at the ends of the file name
        self.file_list = map(lambda x: x.strip(), list)

    def fetchPhoto(self, p):
        print "Fetching file %s..." % p
        (stdout, stdin, stderr) = popen3("%s --getfile '%s%s' '%s/%s'" % (self.bin,
                self.dir, p, self.dest, p))
        # Make it blocking, so the program will wait for gnokii
        stdout.read(1)

    def fetchAll(self):
        for i in self.file_list:
            self.fetchPhoto(i)

if __name__ == "__main__":
    if len(sys.argv) == 2:
        o = FetchPhotos(dest=sys.argv[1])
    else:
        o = FetchPhotos()
    o.fetchList()
    o.fetchAll()

This bunch of lines is only a germ of what one can do using gnokii. gnokii --help should explain everything.

A few words ad. paths: Nokia phones use drive letters A: for internal memory and B: for sim card memory. You can browse whole directory tree using --getfilelist: $ gnokii --getfilelist 'A:*.' GNOKII Version 0.6.12 Filelist for path A:*.: predefgallery predefhiddenfolder predefinfofolder predefomadm serviceapplication predeffilerecieved predeffiledownload predefmessages predefsyncml HTTP FIM_fixed_id FIM_perm_id

WARNING: No error checks is performed! If the connection with a phone is broken the program might fail during any read*() calls, but it also may not and continue with random values. If you require to check the connection status first, you may add a method for checking connection status by e.g. executing os.system("gnokii --identify") and analyze the return code (however it doesn't always work).

1 comment

j j 17 years, 12 months ago  # | flag

A python bind already exists. a couple of the Dev's on Gnokki didn't like their direction so they split and made "Gammu"

They then wrote python binds for it to make making the GUI very easy

http://cihar.com/gammu/python/

Created by Michal Chruszcz on Sat, 25 Mar 2006 (PSF)
Python recipes (4591)
Michal Chruszcz's recipes (1)

Required Modules

Other Information and Tasks