Package etl :: Package component :: Package input :: Module gmail_in'
[hide private]
[frames] | no frames]

Source Code for Module etl.component.input.gmail_in'

 1  # -*- encoding: utf-8 -*- 
 2  ############################################################################## 
 3  # 
 4  #    ETL system- Extract Transfer Load system 
 5  #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved 
 6  #    $Id$ 
 7  # 
 8  #    This program is free software: you can redistribute it and/or modify 
 9  #    it under the terms of the GNU General Public License as published by 
10  #    the Free Software Foundation, either version 3 of the License, or 
11  #    (at your option) any later version. 
12  # 
13  #    This program is distributed in the hope that it will be useful, 
14  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  #    GNU General Public License for more details. 
17  # 
18  #    You should have received a copy of the GNU General Public License 
19  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
20  # 
21  ############################################################################## 
22   
23  from etl.component import component 
24   
25 -class gmail_in(component):
26
27 - def __init__(self, user, password, name='component.input.gmail_in', transformer=None, row_limit=0):
28 """ 29 Required Parameters 30 user : User name. 31 password : Password of the user. 32 33 Extra Parameters 34 name : Name of Component. 35 row_limit : Limited records are sent to destination if row limit is specified. If row limit is 0, all records are sent. 36 """ 37 super(gmail_in, self).__init__(name=name, transformer=transformer, row_limit=row_limit) 38 self._type = 'component.input.gmail_in' 39 self.user = user 40 self.pwd = password
41
42 - def __copy__(self):
43 res = gmail_in(self.user, self.password, self.name, self.transformer, self.row_limit) 44 return res
45
46 - def process(self):
47 import gdata.contacts.service 48 # super(gmail_in, self).action_start(key, singal_data, data) # to be checked for test. 49 connector = gdata.contacts.service.ContactsService() 50 connector.ClientLogin(self.user, self.pwd) 51 contacts_feed = connector.GetContactsFeed() 52 for feed in contacts_feed.entry: 53 emails = [] 54 phone_numbers = [] 55 postal_addresses = [] 56 for email in feed.email: 57 emails.append(email.address) 58 59 for phone_number in feed.phone_number: 60 phone_numbers.append(phone_number.text) 61 62 for postal_address in feed.postal_address: 63 postal_addresses.append(postal_address.text) 64 d={ 65 'title': feed.title and feed.title.text or False, 66 'emails': emails, 67 'phone_numbers': phone_numbers, 68 'postal_addresses': postal_addresses 69 } 70 yield d, 'main'
71
72 -def test():
73 from etl_test import etl_test 74 import etl 75 import getpass 76 user = raw_input('Enter gmail username: ') 77 user = user + '@gmail.com' 78 password = getpass.unix_getpass("Enter your password:") 79 test = etl_test.etl_component_test(gmail_in(user, password)) 80 test.check_output([{'phone_numbers': [''], 'postal_addresses': [''], 'emails': [''], 'title': ''}], 'main') 81 # here add the details of the contact in your gmail in the above mentioned format 82 res = test.output()
83 84 if __name__ == '__main__': 85 test() 86