Fighting Juno’s address book lock-in with Python

This week I helped a friend with an OS re-install (XP unfortunately). He used Juno for his email service, which refused to work properly when re-installed. I helped him switch to Gmail, but it turns out that Juno refused to implement an export feature for their contacts. After a little hunting around, I discovered the text file the software used to store contacts, somewhere in it’s Program Files folder. What follows is a quick bit of code I wrote to convert the contacts into a CSV file. Hopefully it will be useful to someone else in their efforts to fight lock-in.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
 
# import libraries
import csv
 
class entry():
    """A simple data structure for each contact."""
    Name = ''
    Phone = ''
    Birthday = ''
    Address = ''
 
 
class contacts():
    """This class will contain pure input from the Juno contacts file."""
 
    def __init__(self, input):
        # Open the input file
        readFile = open(input, 'r')
 
        # Put the header into list
        header = entry()
        header.Name = "Name"
        header.Email = 'Email'
        header.Phone = "Phone Number"
        header.Address = "Address"
 
        self.list = [header]
 
        # Put the input file into a list and close file
        self.rawContent = readFile.readlines()
        readFile.close()
 
    def parse(self):
        """Parse everything and put it in the list"""
 
        count = 0
        while(count < = len(self.rawContent) -1):
            person = entry()
            count += 1 # Skips over the field specifying the contact as an entry            
 
            # Get email address
            item = self.rawContent[count][6:-2]
            if (item == ''):
                person.Email = ''
            else:
                person.Email = item
            count += 1
 
            # Throw alias into bit-bucket
            count += 1
 
            # Get first and last name
            item = self.rawContent[count][5:-2]
            if (item == ''):
                person.Name = ''
            else:
                person.Name = item
            count += 1
 
            # Get the phone number
            item = self.rawContent[count][14:-2]
            if (item == ''):
                person.Phone = ''
            else:
                person.Phone = item
            count += 1
 
            # Throw birthday into bit-bucket
            count += 1
 
            # Get the address
            item = self.rawContent[count][8:-2]
            if (item == ''):
                person.Address = ''
            else:
                person.Address = item
 
            # incriment count by four to get to the beginning of next entry
            count += 4
 
            # add person to the list
            self.list += [person]
 
    def output(self):
        """Make a CSV file"""
 
        # Set up the output file
        outFile = open('output.txt', 'w')
        output = csv.writer(outFile, delimiter=',')
 
        # Iterate through self.list and write stuff
        for person in self.list:
            output.writerow([person.Name, person.Email, person.Phone, person.Address])
 
        # Close the file
        outFile.close()

Tags: , ,

Comments are closed.


AWSOM Powered