View Full Version : Reading contacts from command line?
jvesiluoma
2010-08-17, 11:43
Hi,
I'm trying to do a simple script that reads and lists contacts from osso-abook. So far I have found that the contacts are in /home/user/.osso-abook\db - file wich is a Berkley database file. But I haven't found any tool to read that, any suggestions how to do that? Is it possible to read contacts via dbus? If yes, then how? =)
I'm doing some nice little web interface to control N900, so far I have made a simple web interface (lighttpd + PHP) and I can read my messages and check calls via that web interface. I can also do everything that Phone_control (thanks to MohammadAG, made my scripts much simpler :D) does and some tricks more via that web interface. Oh, and of course that interface is heavily password protected :)
// Jarkko
ossipena
2010-08-17, 11:48
rtcom probably is just too much for a script:
http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Architecture/RTCOM
have you tried reading the db with sqlite?
jvesiluoma
2010-08-17, 15:13
rtcom probably is just too much for a script:
http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Architecture/RTCOM
have you tried reading the db with sqlite?
Dunno about rtcom, would have to read more about it, but sqlite won't read that db. But thanks anyway.
I found that there is a program called db4.7_dump that reads that db, but haven't found it for arm thought...
// Jarkko
is the tcl api available?
http://download.oracle.com/docs/cd/E17076_01/html/programmer_reference/tcl_using.html
jvesiluoma
2010-08-18, 11:27
is the tcl api available?
http://download.oracle.com/docs/cd/E17076_01/html/programmer_reference/tcl_using.html
Thanks, but I can't find a working version anywhere...
Here are some screenshots what have done so far with lighttpd + php:
http://www.jmv.fi/N900/
ossipena
2010-08-18, 11:53
in backup zip there are all the contacts within one backup.vcf -file.
don't know though if the backup thing can be run within command line.
but that would be one way to do it.
is the tcl api available?
Unfortunately not : (
Looks like the only way is to write a small C / C++ application using libdb or libebook to get at the contacts.
jvesiluoma
2010-08-19, 05:27
Unfortunately not : (
Looks like the only way is to write a small C / C++ application using libdb or libebook to get at the contacts.
Ok, have to do that then. Thanks.
gkuenning
2010-08-19, 05:42
Since I back up with rsync to my desktop and laptop, I have a copy of the DB on a machine that has db_dump. I found that "db_dump -p" gives a series of vcards encoded one per line. It wouldn't be hard to parse those further using a tool like awk or python.
Now that I think about it, Python has a Berkeley DB access library (bsddb), although I don't know if it's available for Maemo.
Jarkko, what kind of tool are you imagining? I.e., are you thinking "lookup_contact --home-phone Joe" would print out Joe's home phone number? (I'm thinking that if somebody writes a tool, it would be good to try to make it flexible so other people can use it in unanticipated ways.)
jvesiluoma
2010-08-19, 06:22
Since I back up with rsync to my desktop and laptop, I have a copy of the DB on a machine that has db_dump. I found that "db_dump -p" gives a series of vcards encoded one per line. It wouldn't be hard to parse those further using a tool like awk or python.
Now that I think about it, Python has a Berkeley DB access library (bsddb), although I don't know if it's available for Maemo.
Jarkko, what kind of tool are you imagining? I.e., are you thinking "lookup_contact --home-phone Joe" would print out Joe's home phone number? (I'm thinking that if somebody writes a tool, it would be good to try to make it flexible so other people can use it in unanticipated ways.)
Yeah, I found that I can make that dump on my desktop computer, but I would like to make this dynamic, so I can fetch contacts on the fly.
As far as I know, bsddb is not available for maemo. At least it is not included as default and quick search didn't give any results either.
Just simple export, like "dump_contacs -name -phonenumber -email -db addressbook.db" that exports contacts, for example "John Doe 123456789 john.doe@something.com". That way output could be parsed and maybe some other ppl would find some other use to that tool also.
If I have time, I'll start to write that kind of app...but I'll guess it will take some time. Busy at work nowdays...
Regards,
Jarkko
jvesiluoma
2010-08-19, 07:20
Ahh, found this ==> https://bugs.maemo.org/show_bug.cgi?id=9865 about bsddb, but can't find libdb4.2-dev , argh...
That bus is marked as fixed, but can't find libdb4.2 package for maemo(arm)?
Well, have to keep digging...
// Jarkko
jvesiluoma
2010-08-19, 07:44
Okay, got it working (bsddb I mean). :D
If anyone is interested, first update python2.5-minimal 2.5.4-1maemo6 and then python2.5_2.5.4-1maemo6.
After that you can import bsddb, now it's just a matter of coding a small python program that exports contacts.
Thanks for your help.
Regards,
Jarkko
sorry for bringing this thread back to the daylight ;)
but right now i'm in the same situation as the OP.
i need a solution for fetching the phonenumber of a contact from the cli.
something like: db_get -n name -o options
where "name" is the nickname (or complete name) of the contact and options could be "phone1" "phone2" (and so on) "email1" "address1" or something.
so... any news on this topic?
an (somehow) unsatisfying workaround is the vcf-method mentioned here before.
in the contacts app gui i export them into a folder as 3.0 vcfs.
(works perfectly within seconds)
then i open up xterm and cd into that folder where i can get the cellphone number via cat | grep | cut.
because this is really fast and easy my new question is:
can i export my contacts to vcf via cli? :)
Quick Python script
import evolution
import sys
from optparse import OptionParser
def search_contact(options):
ebook = evolution.ebook.open_addressbook("default")
if not options.contact is None:
contacts = ebook.search(options.contact)
elif not options.full_name is None:
contacts = []
for c in ebook.get_all_contacts():
if c.get_name() == options.full_name:
contacts.append(c)
elif not options.nick_name is None:
contacts = []
for c in ebook.get_all_contacts():
if c.get_property("nickname") == options.nick_name:
contacts.append(c)
if (not options.attributes is None) and (len(options.attributes) > 0):
for contact in contacts:
print contact.get_property("full-name")
for a in options.attributes:
print contact.get_property(a)
if options.list:
for contact in contacts:
for p in contact.props:
value = contact.get_property(p.name)
if not value is None:
print p.name, value
if options.export:
for contact in contacts:
print contact.get_vcard_string()
def main():
parser = OptionParser()
parser.add_option("-c", "--contact", help="contact name to search for", action="store", type="string", dest="contact")
parser.add_option("-f", "--full-name", help="select contact with this name", action="store", type="string", dest="full_name")
parser.add_option("-n", "--nickname", help="select contact with this nickname", action="store", type="string", dest="nick_name")
parser.add_option("-a", "--attribute", help="contact attributes -a attribute1 -a attribute2 ..", action="append", type="string", dest="attributes")
parser.add_option("-e", "--export", help="print vcard string", action="store_true", dest="export", default=False)
parser.add_option("-l", "--list-attributes", help="list vcard attributes", action="store_true", dest="list", default=False)
(options, args) = parser.parse_args(sys.argv)
if len(sys.argv) <= 1:
parser.print_help()
else:
search_contact(options)
if __name__ == "__main__":
main()
hi nicolai!
first of all: thanks for your work!
[ignore me]
but:
if i call your script with "python yourscript -c name" there is no output.
for name i tried nickname, last name, first name, first last, last first and even separated with commas and set in " ".
how do i use it correctly? :)
[/ignore me]
EDIT:
okay "python yourscript -c lastname -e" produces the vcf, cool! :)
but i would love to search for the nickname instead of the lastname.
EDIT2:
next problem is that -e makes the vcf for all contacts who contain the nickname-string.
example: search for "chris" matches "chris" but "christina" too. :/
and i'm struggeling with the -a attributes; what are they?
-a email is working.
but how do i get the cellphone number?
changed my script in the post above.
python yourscript -f "Pink Panther" -l
searches for the contact with the fullname Pink Panther
and prints all defined contact attributes (mobile-phone, email-1, ...)
python yourscript -n pinky -l
searches for the contact with the nickname pinky
Nicolai
Nicolai, how do i search for a name in ebook by given phone number? thanks
what i try to do is search for certain phone if it exist in the ebook and return a true or false.
gionni88
2011-04-17, 22:01
Try this, call it in terminal and give as argument the nickname you wanna get the number off. Nickname must exactly match, no more christina while looking for chris.
./contactretrieve Marco
gkuenning
2011-04-18, 02:13
Very cool, Nicolai. I hadn't known there was a Python interface to the databases. How did you learn about it?
hutchinsfairy
2011-05-26, 08:33
/home/user/scripts# python contact_search.py -f 'Firstname Lastname' -l
Traceback (most recent call last):
File "contact_search.py", line 55, in <module>
main()
File "contact_search.py", line 52, in main
search_contact(options)
File "contact_search.py", line 13, in search_contact
for c in ebook.get_all_contacts():
AttributeError: 'NoneType' object has no attribute 'get_all_contacts'
Am I missing a dependency?
python-evolution maybe?
http://maemo.org/packages/view/python-evolution/
Nicolai
hutchinsfairy
2011-05-26, 08:51
"python-evolution is already the newest version"...
Thanks for the quick response though!
hutchinsfairy
2011-05-26, 08:56
Embarrased now:
Was running as root....
Sorry for wasting your time!
woody14619
2011-07-13, 18:42
Ok, I know this is old, but I have a problem.
I recently added a jabber client to my N900 and it threw about 200 people into the contact list, some of which already had entries, but many didn't. The problem is, I can't find any of the new entries in the list!
I opened one to look at it, and it has only 2 fields in the contact page: The jabber account name, and the Nickname field with their full name. But when I look up the nickname with the python script here, I get no hits. If I edit a user, and just hit save (no changes, just edit/save), it then shows up!
Where are these contacts at? How can I get at them? I'd prefer to modify the script to find people in this "limbo" state (so as new people join in I can get at them), and "fix" their entries, so their names and a proper icon show up. I know how to fix it once there, but can't seem to figure out how to get them. :(
is it possible to list all numbers with a matching nickname? i use nickname to get around the missing group sms feature. possible via nicolai script?
unclouded
2012-12-17, 12:22
Here's a snippet for adding a contact from the command line:
#!/usr/bin/env python
#
# Please let me know if this works without python-gnome2 installed!
#
USE='Use: addressbook add_contact given-name=John family-name=Doe email-1=johndoe@example.com'
import os
import sys
import evolution
def quit( message):
sys.stderr.write("%s\n"% message)
exit( 1)
if 0 == os.getuid():
quit('Not as root please')
adb = evolution.ebook.open_addressbook('default')
# Not listing contact because already covered: http://maemo.cloud-7.de/maemo5/usr/local/bin/contact
#def list_contacts( args):
# for contact in adb.get_all_contacts():
# print [contact.get_property(ppt) for ppt in ['full-name', 'mobile-phone']]
if len( sys.argv) < 3 or sys.argv[1] != 'add_contact':
quit( USE)
ct = evolution.ebook.EContact()
for arg in sys.argv[2:]:
name, value = arg.split('=')
ct.set_property( name, value)
adb.add_contact( ct)
There's also a longer script (https://bitbucket.org/darkcloud/maemo-addressbook/src/f8f8ce4ef02ba46093b40c3f7abe24a64245bbc7/addressbook) that can list in YAML and VCARD and add and remove contacts.
danielbryan001
2013-11-21, 11:30
Hi man, so sorry i was not a programming student. I can't tell you anything related to this.
Locksmith Reading PA (http://www.PrimeReadingLocksmith.com)
vBulletin® v3.8.8, Copyright ©2000-2023, vBulletin Solutions, Inc.