I was searching the net for a way to get the gmail contact list and came across libgmail
The demo is pretty sweet, after untarring the package, just type >
python libgmail.py
and it will log you in and present you with your list of gmail folders to choose from.
Since there was no option for getting the contact list, i thought of putting that in by following the general mechanism used for getting the emails. But I was pleasantly surprised to find a getContacts() method in the lib that was not exposed in the demo.
So I added that as the last option to the package, so it looks like this:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STANDARD_FOLDERS = [U_INBOX_SEARCH, U_STARRED_SEARCH,
U_ALL_SEARCH, U_DRAFTS_SEARCH,
U_SENT_SEARCH, U_SPAM_SEARCH]
// add this right after STANDARD_FOLDERS def (around line 61 in libgmail.py)
CONTACT_LIST = ["contacts"]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// around line 1609
searches = STANDARD_FOLDERS + ga.getLabelNames() + CONTACT_LIST
name = None
while 1:
try:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// around line 1622
name = None
if name in STANDARD_FOLDERS:
result = ga.getMessagesByFolder(name, True)
elif name not in CONTACT_LIST:
result = ga.getMessagesByLabel(name, True)
else:
contacts = ga.getContacts()
print "No contacts: %d" % contacts.getCount()
for entry in contacts.getAllContacts():
print " %s %s" % (entry.getName(), entry.getEmail())
result = []
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This will print your contacts when you pick the last option (after the folder names)
I have submitted the change to libgmail folks - hope they put it in the official package.
There is also an alternate hack to get some script that has your contacts if you're already logged in. Just hit this url: http://video.google.com/data/contacts?out=js&max=500&psort=Affinity courtsey Garett Rogers.
Friday, September 07, 2007
Thursday, September 06, 2007
installing memcached on Ubuntu
Dependency:
1. get libevent src package libevent-1.3d.tar.gz from http://www.monkey.org/~provos/libevent
2. untar it - tar xvzf libevent-1.3d.tar.gz
3. build it by running these 2 commands:
./configure
make
4. install it by becoming root and running this command: (be sure to be in the same directory where the package was un-tarred)
make install
Memcached (the daemon):
1. get memcached from http://www.danga.com/memcached/
2. untar it - tar xvzf memcached-1.2.2.tar.gz
3. build it by running these 2 commands:
./configure
make
4. install it by becoming root and running this command: (be sure to be in the same directory where the package was un-tarred)
make install
Starting the daemon:
1. export LD_LIBRARY_PATH=/usr/local/lib
2. memcached -d -u root
Memcache (the client for php):
1. install pear package manager:
become root and run: apt-get install php-pear
2. as root, make a symlink as follows: (replace php5 with php4 if you're using php4)
ln -s /usr/include/php5 /usr/include/php
3. as root run this comand to install the client:
pecl install Memcache
4. edit your php.ini and add extension=memcache.so under extensions
5. restart apache
Use the cache in your php code:
$memcache = memcache_connect('localhost', 11211);
if ($memcache) {
$memcache->set("str_key", "String to store in memcached");
$memcache->set("num_key", 123);
$object = new StdClass;
$object->attribute = 'test';
$memcache->set("obj_key", $object);
$array = Array('assoc'=>123, 345, 567);
$memcache->set("arr_key", $array);
pr($memcache->get('str_key'));
var_dump($memcache->get('num_key'));
var_dump($memcache->get('obj_key'));
}
else {
echo "Connection to memcached failed";
}
1. get libevent src package libevent-1.3d.tar.gz from http://www.monkey.org/~provos/libevent
2. untar it - tar xvzf libevent-1.3d.tar.gz
3. build it by running these 2 commands:
./configure
make
4. install it by becoming root and running this command: (be sure to be in the same directory where the package was un-tarred)
make install
Memcached (the daemon):
1. get memcached from http://www.danga.com/memcached/
2. untar it - tar xvzf memcached-1.2.2.tar.gz
3. build it by running these 2 commands:
./configure
make
4. install it by becoming root and running this command: (be sure to be in the same directory where the package was un-tarred)
make install
Starting the daemon:
1. export LD_LIBRARY_PATH=/usr/local/lib
2. memcached -d -u root
Memcache (the client for php):
1. install pear package manager:
become root and run: apt-get install php-pear
2. as root, make a symlink as follows: (replace php5 with php4 if you're using php4)
ln -s /usr/include/php5 /usr/include/php
3. as root run this comand to install the client:
pecl install Memcache
4. edit your php.ini and add extension=memcache.so under extensions
5. restart apache
Use the cache in your php code:
$memcache = memcache_connect('localhost', 11211);
if ($memcache) {
$memcache->set("str_key", "String to store in memcached");
$memcache->set("num_key", 123);
$object = new StdClass;
$object->attribute = 'test';
$memcache->set("obj_key", $object);
$array = Array('assoc'=>123, 345, 567);
$memcache->set("arr_key", $array);
pr($memcache->get('str_key'));
var_dump($memcache->get('num_key'));
var_dump($memcache->get('obj_key'));
}
else {
echo "Connection to memcached failed";
}
Subscribe to:
Posts (Atom)