/[pac]/pac/PACDefault/PACTool.py
ViewVC logotype

Diff of /pac/PACDefault/PACTool.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by tvon, Wed Oct 8 00:44:40 2003 UTC revision 1.2 by tvon, Sun Oct 12 02:05:46 2003 UTC
# Line 17  import re Line 17  import re
17  import sys  import sys
18  import traceback  import traceback
19    
 from zLOG import LOG, INFO, WARNING  
   
 def log(summary='', text='', log_level=INFO):  
     LOG('PAC Debug', log_level, summary, text)  
   
20  class PACTool (UniqueObject, SimpleItem):  class PACTool (UniqueObject, SimpleItem):
21      id = 'pac_utils'      id = 'pac_tool'
22      meta_type= 'PAC Utility Tool'      meta_type= 'Public Action Center Tool'
23      security = ClassSecurityInfo()      security = ClassSecurityInfo()
24      plone_tool = 1      plone_tool = 1
25      #field_prefix = 'field_' # Formulator prefixes for forms      #field_prefix = 'field_' # Formulator prefixes for forms
26    
27        #security.declarePublic('getEligibility')
28        def getEligibility(self, member, r={}):
29            pass
30    
31    
32        def getMemberRepresentatives(self, member):
33            """Uh....yeah, so this is just for testing *g*.  Since the PAC is in its pre-release stages, please do me the favor of not using this perticular method if you happen to find this code somewhere.."""
34            import urllib
35            import re
36            try:
37                fullzip = '%s-%s' % (member.getProperty('zipcode'), member.getProperty('zip4'))
38             except:
39                 return None
40            result = urllib.urlopen('http://www.vote-smart.org/search_zipcode.php?type=zip&keyword=%s' % full_zip)
41    
42            lines = result.read().split('\n')
43    
44            matches = {}
45            matches['span'] = re.compile('.*span class="hed".*')
46            matches['bio_link'] = re.compile('.*href.*can_id.*')
47            matches['bio_id'] = re.compile(r'.*can_id=([A-Z]*).*')
48            matches['senate'] = re.compile('.*U\.S\. Senate.*')
49            matches['house'] = re.compile('.*U\.S\. House.*')
50            matches['state_senate'] = re.compile('.*House of Delegates.*')
51            matches['state_house'] = re.compile('.*Senate.*')
52            matches['state_offices'] = re.compile('.*State Offices.*')
53    
54            results = {}
55            results['span'] = []
56            results['bio_link'] = []
57            results['bio_id'] = []
58            results['senate'] = []
59            results['house'] = []
60            results['state_senate'] = []
61            results['state_house'] = []
62            results['state_offices'] = []
63    
64            section = 'dummy'
65    
66            for line in lines:
67                if matches['span'].match(line):
68                    if matches['senate'].match(line):
69                        section = 'senate'
70                    elif matches['house'].match(line):
71                        section = 'house'
72                    elif matches['state_senate'].match(line):
73                        section = 'state_senate'
74                    elif matches['state_house'].match(line):
75                        section = 'state_house'
76                    elif matches['state_offices'].match(line):
77                        section = 'state_offices'
78                else:
79                    if matches['bio_link'].match(line):
80                        if section != 'dummy':
81                            results[section].append(re.match('.*can_id=([A-Z0-9]{8}).*', line).group(1))
82                        
83            return results
84    
85    
86      #security.declarePublic('queryActionRecipients')      #security.declarePublic('queryActionRecipients')
87      def queryActionRecipients(self, REQUEST=None, **kw):      def queryActionRecipients(self, REQUEST=None, **kw):
88    
# Line 276  class PACTool (UniqueObject, SimpleItem) Line 330  class PACTool (UniqueObject, SimpleItem)
330    
331          return None          return None
332    
     security.declarePublic('sendto')  
     def sendto( self, variables = {} ):  
         """Sends a link of a page to someone"""  
         if not variables: return  
         mail_text = self.sendto_template( self  
                                         , send_from_address = variables['send_from_address']  
                                         , send_to_address = variables['send_to_address']  
                                         , url = variables['url']  
                                         , title = variables['title']  
                                         , description = variables['description']  
                                         , comment = variables['comment']  
                                         )  
         host = self.MailHost  
         host.send( mail_text )  
           
     # Enable scripts to get the string value of an exception  
     # even if the thrown exception is a string and not a  
     # subclass of Exception.  
     def exceptionString(self):  
         # don't assign the traceback to s (otherwise will generate a circular  
         # reference)  
         s = sys.exc_info()[:2]  
         if s[0] == None:  
             return None  
         if type(s[0]) == type(''):  
             return s[0]  
         return str(s[1])  
   
   
     # provide a way of dumping an exception to the log even if we  
     # catch it and otherwise ignore it  
     def logException(self):  
         """Dump an exception to the log"""  
         log(summary=self.exceptionString(),  
             text='\n'.join(traceback.format_exception(*sys.exc_info())),  
             log_level=WARNING)  
           
   
333  InitializeClass(PACTool)  InitializeClass(PACTool)
334    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26