Re: Printing a gnomecard
- From: "Stuart D. Gathman" <stuart bmsi com>
- To: Roman Klesel <rupa firemail de>
- Cc: gnome-list gnome org
- Subject: Re: Printing a gnomecard
- Date: Sat Dec 28 21:28:01 2002
On Sat, 28 Dec 2002, Roman Klesel wrote:
> I was wandering what might be a good way to print my addresses from gnomecard?
> One way of cause would be to install evolution - import and print. But just
> for that purpose I would prefere not to install evolution. Is there a way to
> convert a vcard file to html,pdf,ps or someting like that?
I am not sure what you mean by "print". I use the glabels program:
http://snaught.com/glabels/
to print Inkjet labels from Avery and other manufacturers. I convert
gnome-cards to glabel mailing list form with a python script. I used to use a
perl script for labels, PostScript::MailLabels, before converting to glabels.
So please pardon the conversion code cluttering up things.
#!/usr/bin/env python2
# Stuart D. Gathman
# This code deals with "cards" such as used by an address book or Rolodex.
# The primary storage format for cards is 'VCARD' as used by netscape
# and GCard.
# A card is represented as a Python dictionary
# A label is the 4 line ':' separated format used by homed.pl
# homed.pl is in Perl so it can use PostScript::MailLabels
def parseLabel(list):
"Parse a label into a card"
card = {}
n = list[0].split(':')
card['FN'] = [' '.join(n)]
n.reverse()
card['N'] = n
csz = list[2].split(':')
card['ADR;HOME'] = ['','',list[1]] + csz
if list[3] == 'T':
card['CATEGORIES;QUOTED-PRINTABLE'] = ['Truro']
return card
def parseLabels(file):
"Parse a file of labels into a list of Gcard objects"
card = []
list = []
for line in file.readlines():
card.append(line.strip())
if len(card) == 4:
list.append(parseLabel(card))
card = []
return list
def parseCards(file):
"Parse a file of Gcards into a list of Gcard objects"
card = None
list = []
for line in file.readlines():
line = line.strip()
if line == 'BEGIN:VCARD':
card = {}
continue
if list == '' or card == None: continue
if line == 'END:VCARD':
list.append(card)
card = None
continue
(key,val) = line.split(':',1)
card[key] = val.split(';')
return list
def writeCard(card):
"Write a card in VCARD format."
print 'BEGIN:VCARD'
for (key,val) in card.items():
print '%s:%s' % (key,';'.join(val))
print 'END:VCARD'
print
def writeLabel(card):
"Write a card in MailLabel format."
n = card['N']
n.reverse()
a = card['ADR;HOME']
c = ''
if card.has_key('CATEGORIES;QUOTED-PRINTABLE'):
if 'Truro' in card['CATEGORIES;QUOTED-PRINTABLE']: c = 'T'
print ':'.join(n)
print a[2]
print ':'.join(a[3:6])
print c
def write_glabel(card):
"Write a card in glabel format."
print '\t'.join(card['N'] + card['ADR;HOME'])
def cardKey(card): return card['FN'][0]
def merge(card1,card2):
"Merge fields from card2 into card1."
for (key,val) in card2.items():
card1[key] = val
return card1
def convertLabels(f1,f2):
"Incorporate MailLabel data into a VCARD file."
import sys
cards = parseLabels(open(f1,"r"))
ocards = parseCards(open(f2,"r"))
d = {}
for i in ocards: d[cardKey(i)] = i
for i in cards:
fn = cardKey(i)
if d.has_key(fn): merge(d[fn],i)
else: d[fn] = i
return d.values()
if __name__ == "__main__":
import sys
if len(sys.argv) > 2:
# Merge labels in Postscript::MailLabels format with Gnome-cards
cards = convertLabels(sys.argv[1],sys.argv[2])
for c in cards: writeCard(c)
elif len(sys.argv) > 1:
# Output glabels from Gnome-cards
f = open(sys.argv[1],"r")
cards = parseCards(f)
#for c in cards: writeLabel(c)
for c in cards: write_glabel(c)
else:
print "Usage: gcrd.py file.gcrd >file.glabels"
print " gcrd.py maillabels.mlbl file.gcrd >newfile.gcrd"
--
Stuart D. Gathman <stuart bmsi com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"[Microsoft] products are even less buggy than others, in terms of
per capita usage." - Steve Balmer, Microsoft Corporation
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]