473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

access abook addressbook with curses

Hi,

I want to get access to my abook address file with python.
Does anyone have some python lines to achive this using
curses? If not, maybe anybody has small python program doing
it with a gui!?

Greetings!
Fabian

Aug 5 '06 #1
6 1671
On 2006-08-05, Fabian Braennstroem <f.************@gmx.dewrote:
Hi,

I want to get access to my abook address file with python.
Does anyone have some python lines to achive this using
curses? If not, maybe anybody has small python program doing
it with a gui!?
You can just parse the abook addressbook with the ConfigParser, try
this:

import os
from ConfigParser import *

abook = ConfigParser()
abook.read(os.environ["HOME"] + "/.abook/addressbook")

for s in abook.sections():
print abook.items(s)
Aug 5 '06 #2
Hi Ben,

* Ben C <sp******@spam.eggswrote:
On 2006-08-05, Fabian Braennstroem <f.************@gmx.dewrote:
>Hi,

I want to get access to my abook address file with python.
Does anyone have some python lines to achive this using
curses? If not, maybe anybody has small python program doing
it with a gui!?

You can just parse the abook addressbook with the ConfigParser, try
this:

import os
from ConfigParser import *

abook = ConfigParser()
abook.read(os.environ["HOME"] + "/.abook/addressbook")

for s in abook.sections():
print abook.items(s)
Thanks! I found a different example too:

import ConfigParser
import string

config = ConfigParser.ConfigParser()

config.read("/home/fab/.abook/addressbook")

# print summary
print
for number in [2,200]:
print string.upper(config.get(str(number), "email"))
print string.upper(config.get(str(number), "name"))
print string.upper(config.get(str(number), "city"))
print string.upper(config.get(str(number), "address"))

but the problem seems to be that abook does not write every
field, so I get an exception when there is a field missing:

Traceback (most recent call last):
File "configparser-example-1.py", line 13, in ?
print string.upper(config.get(str(number), "city"))
File "/usr/lib/python2.4/ConfigParser.py", line 520, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'city' in section: '2'

Section 2 looks like:

[2]
name=Andrs Gzi
em***********@ik.e
nick=oz

Is there a workaround?
Greetings!
Fabian

Aug 6 '06 #3
On 2006-08-06, Fabian Braennstroem <f.************@gmx.dewrote:
Hi Ben,

* Ben C <sp******@spam.eggswrote:
>On 2006-08-05, Fabian Braennstroem <f.************@gmx.dewrote:
>>Hi,

I want to get access to my abook address file with python.
Does anyone have some python lines to achive this using
curses? If not, maybe anybody has small python program doing
it with a gui!?

You can just parse the abook addressbook with the ConfigParser, try
this:

import os
from ConfigParser import *

abook = ConfigParser()
abook.read(os.environ["HOME"] + "/.abook/addressbook")

for s in abook.sections():
print abook.items(s)

Thanks! I found a different example too:

import ConfigParser
import string

config = ConfigParser.ConfigParser()

config.read("/home/fab/.abook/addressbook")

# print summary
print
for number in [2,200]:
print string.upper(config.get(str(number), "email"))
print string.upper(config.get(str(number), "name"))
print string.upper(config.get(str(number), "city"))
print string.upper(config.get(str(number), "address"))

but the problem seems to be that abook does not write every
field, so I get an exception when there is a field missing:

Traceback (most recent call last):
File "configparser-example-1.py", line 13, in ?
print string.upper(config.get(str(number), "city"))
File "/usr/lib/python2.4/ConfigParser.py", line 520, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'city' in section: '2'

Section 2 looks like:

[2]
name=Andrs Gzi
em***********@ik.e
nick=oz

Is there a workaround?
You can construct the parser with a dictionary of defaults:

config = ConfigParser.ConfigParser({"city" : "unknown",
"zip" : "unknown"})

that kind of thing.

Or catch the exceptions. Or use config.options("2") to see what options
exist in section 2 before you try to read them.
Aug 6 '06 #4
Hi Ben,

* Ben C <sp******@spam.eggswrote:
On 2006-08-06, Fabian Braennstroem <f.************@gmx.dewrote:
>Hi Ben,

* Ben C <sp******@spam.eggswrote:
>>On 2006-08-05, Fabian Braennstroem <f.************@gmx.dewrote:
Hi,

I want to get access to my abook address file with python.
Does anyone have some python lines to achive this using
curses? If not, maybe anybody has small python program doing
it with a gui!?

You can just parse the abook addressbook with the ConfigParser, try
this:

import os
from ConfigParser import *

abook = ConfigParser()
abook.read(os.environ["HOME"] + "/.abook/addressbook")

for s in abook.sections():
print abook.items(s)

Thanks! I found a different example too:

import ConfigParser
import string

config = ConfigParser.ConfigParser()

config.read("/home/fab/.abook/addressbook")

# print summary
print
for number in [2,200]:
print string.upper(config.get(str(number), "email"))
print string.upper(config.get(str(number), "name"))
print string.upper(config.get(str(number), "city"))
print string.upper(config.get(str(number), "address"))

but the problem seems to be that abook does not write every
field, so I get an exception when there is a field missing:

Traceback (most recent call last):
File "configparser-example-1.py", line 13, in ?
print string.upper(config.get(str(number), "city"))
File "/usr/lib/python2.4/ConfigParser.py", line 520, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'city' in section: '2'

Section 2 looks like:

[2]
name=Andrs Gzi
em***********@ik.e
nick=oz

Is there a workaround?

You can construct the parser with a dictionary of defaults:

config = ConfigParser.ConfigParser({"city" : "unknown",
"zip" : "unknown"})

that kind of thing.

Or catch the exceptions. Or use config.options("2") to see what options
exist in section 2 before you try to read them.
Thanks! I will try it out!

Greetings!
Fabian

Aug 8 '06 #5
On 2006-08-08, Fabian Braennstroem <f.************@gmx.dewrote:
Hi Ben,

* Ben C <sp******@spam.eggswrote:
>On 2006-08-06, Fabian Braennstroem <f.************@gmx.dewrote:
>>Hi Ben,

* Ben C <sp******@spam.eggswrote:
On 2006-08-05, Fabian Braennstroem <f.************@gmx.dewrote:
Hi,
>
I want to get access to my abook address file with python.
Does anyone have some python lines to achive this using
curses? If not, maybe anybody has small python program doing
it with a gui!?

You can just parse the abook addressbook with the ConfigParser, try
this:

import os
from ConfigParser import *

abook = ConfigParser()
abook.read(os.environ["HOME"] + "/.abook/addressbook")

for s in abook.sections():
print abook.items(s)

Thanks! I found a different example too:

import ConfigParser
import string

config = ConfigParser.ConfigParser()

config.read("/home/fab/.abook/addressbook")

# print summary
print
for number in [2,200]:
print string.upper(config.get(str(number), "email"))
print string.upper(config.get(str(number), "name"))
print string.upper(config.get(str(number), "city"))
print string.upper(config.get(str(number), "address"))

but the problem seems to be that abook does not write every
field, so I get an exception when there is a field missing:

Traceback (most recent call last):
File "configparser-example-1.py", line 13, in ?
print string.upper(config.get(str(number), "city"))
File "/usr/lib/python2.4/ConfigParser.py", line 520, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'city' in section: '2'

Section 2 looks like:

[2]
name=Andrs Gzi
em***********@ik.e
nick=oz

Is there a workaround?

You can construct the parser with a dictionary of defaults:

config = ConfigParser.ConfigParser({"city" : "unknown",
"zip" : "unknown"})

that kind of thing.

Or catch the exceptions. Or use config.options("2") to see what options
exist in section 2 before you try to read them.

Thanks! I will try it out!
Looking at the bigger picture here, though, I may be giving you the
wrong advice. Mutt just invokes abook to get the addresses I think,
that's why you put

set query_command="abook --mutt-query '%s'"

So you could do the same (if what you're trying to do is write a mutt
clone in Python):

import subprocess

name = "Andrs"
subprocess.Popen("abook --mutt-query " + name,
stdout=subprocess.PIPE, shell=True).communicate()[0]

The difference is that this "leverages" abook to do the search, not just
to store the data, which is a logical approach.

On the other hand, this way, you require that abook is installed on the
machine, which is no good if the object of the exercise is a portable
Python-only solution.
Aug 8 '06 #6
Hi Ben,
* Ben C <sp******@spam.eggswrote:
On 2006-08-08, Fabian Braennstroem <f.************@gmx.dewrote:
>Hi Ben,

* Ben C <sp******@spam.eggswrote:
>>On 2006-08-06, Fabian Braennstroem <f.************@gmx.dewrote:
Hi Ben,

* Ben C <sp******@spam.eggswrote:
On 2006-08-05, Fabian Braennstroem <f.************@gmx.dewrote:
>Hi,
>>
>I want to get access to my abook address file with python.
>Does anyone have some python lines to achive this using
>curses? If not, maybe anybody has small python program doing
>it with a gui!?
>
You can just parse the abook addressbook with the ConfigParser, try
this:
>
import os
from ConfigParser import *
>
abook = ConfigParser()
abook.read(os.environ["HOME"] + "/.abook/addressbook")
>
for s in abook.sections():
print abook.items(s)

Thanks! I found a different example too:

import ConfigParser
import string

config = ConfigParser.ConfigParser()

config.read("/home/fab/.abook/addressbook")

# print summary
print
for number in [2,200]:
print string.upper(config.get(str(number), "email"))
print string.upper(config.get(str(number), "name"))
print string.upper(config.get(str(number), "city"))
print string.upper(config.get(str(number), "address"))

but the problem seems to be that abook does not write every
field, so I get an exception when there is a field missing:

Traceback (most recent call last):
File "configparser-example-1.py", line 13, in ?
print string.upper(config.get(str(number), "city"))
File "/usr/lib/python2.4/ConfigParser.py", line 520, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'city' in section: '2'

Section 2 looks like:

[2]
name=Andrs Gzi
em***********@ik.e
nick=oz

Is there a workaround?

You can construct the parser with a dictionary of defaults:

config = ConfigParser.ConfigParser({"city" : "unknown",
"zip" : "unknown"})

that kind of thing.

Or catch the exceptions. Or use config.options("2") to see what options
exist in section 2 before you try to read them.

Thanks! I will try it out!

Looking at the bigger picture here, though, I may be giving you the
wrong advice. Mutt just invokes abook to get the addresses I think,
that's why you put

set query_command="abook --mutt-query '%s'"

So you could do the same (if what you're trying to do is write a mutt
clone in Python):

import subprocess

name = "Andrs"
subprocess.Popen("abook --mutt-query " + name,
stdout=subprocess.PIPE, shell=True).communicate()[0]

The difference is that this "leverages" abook to do the search, not just
to store the data, which is a logical approach.

On the other hand, this way, you require that abook is installed on the
machine, which is no good if the object of the exercise is a portable
Python-only solution.
The biggest problem is a missing and not allowed
abook installation. But thanks for your tips!

Greetings!
Fabian

Aug 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Edmond Ho | last post by:
Hi, I'm having trouble with a small curses program. I'm associate a pad with a panel. As I understand, a pad is supposed to be just a window with an arbitrary size. That seems to imply that a pad...
1
by: Riccardo Galli | last post by:
Hi, I'm writing some widgets in curses. Actually I'm trying to write a combobox. To do so, I need to create a pad inside a panel, so that I can hide/show it. I can't do it. I can create a...
0
by: Matthew Alton | last post by:
The appended program freaks python 2.2 & 2.3 completely out. To reproduce the wierdness: i) copy the source to a file called consarn.py ii) $ python consarn.py; iii) the program is now doing a...
0
by: Matt Garman | last post by:
I'd like to write a class or module in python that allows me to do on-the-fly color changing in the curses module. I'm thinking about something along the lines of this: addstr(y, x, 'hello',...
6
by: Kurt | last post by:
Hello. I am writing a C# program that uses CDO 1.21 to access the outlook addressbook as a contact management system The following code gives me the correct dialog box, but the "Show Names from...
1
by: Lauren Quantrell | last post by:
I know if I was using an Access MDB I could link to MS Outlook folders and the addressbook. But I'm using an Access Project (ADP) and want to figure out a way to link to the Outlook addressbook...
1
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
5
by: 7stud | last post by:
I can't see to get any y, x coordinates to work with curses. Here is an example: import curses def my_program(screen): while True: ch = screen.getch() if ch == ord("q"): break
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.