Package etl :: Package component :: Package output :: Module facebook_out
[hide private]
[frames] | no frames]

Source Code for Module etl.component.output.facebook_out

 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  This is an ETL Component that writes data to facebook. 
24  """ 
25   
26  from etl.component import component 
27   
28   
29 -class facebook_out(component):
30 """ 31 This is an ETL Component that writes data to facebook. 32 """ 33
34 - def __init__(self, facebook_connector, method, domain=[], fields=['name'], name='component.input.facebook_out', transformer=None, row_limit=0):
35 super(facebook_out, self).__init__(name=name, connector=facebook_connector, transformer=transformer, row_limit=row_limit) 36 self._type = 'component.output.facebook_out' 37 self.method = method 38 self.domain = domain 39 self.fields = fields
40
41 - def __copy__(self):
42 res = facebook_out(self.connector, self.name, self.transformer, self.row_limit) 43 return res
44
45 - def end(self):
46 super(facebook_out, self).end() 47 if self.facebook: 48 self.connector.close(self.facebook) 49 self.facebook = False
50 51
52 - def process(self):
53 self.facebook = False 54 for channel, trans in self.input_get().items(): 55 for iterator in trans: 56 for d in iterator: 57 if not self.facebook: 58 self.facebook = self.connector.open() 59 self.connector.execute(self.facebook, self.method, fields=self.fields) 60 yield d, 'main'
61 62 63
64 -def test():
65 from etl_test import etl_test 66 import etl 67 facebook_conn = etl.connector.facebook_connector('http://facebook.com', 'modiinfo@gmail.com') 68 test = etl_test.etl_component_test(facebook_out(facebook_conn, 'set_events', name='facebook test')) 69 test.check_output([{'id': 'event2', 'name': 'mustufa'}], 'main') 70 test.check_input({'main': [{'id': 'event2', 'name': 'mustufa'}]}) 71 res = test.output() 72 print res
73 74 if __name__ == '__main__': 75 test() 76