'Command-line script to process SMS messages' import script_process from auth.libraries import sms def run(settings): 'Connect to IMAP server and process messages' countByKey = sms.process(settings) return '\n'.join('%s: %s' % (key.capitalize(), count) for key, count in countByKey.iteritems()) # If we are running standalone, if __name__ == '__main__': # Parse optionParser = script_process.OptionParser() options = optionParser.parse_args()[0] # Run message = run(script_process.initialize(options)) # Say if options.verbose: print message
'patentInventors': patentInventors, 'patentStatuses': patentStatuses, 'patentTypes': patentTypes, 'phones': phones, 'technologies': technologies, } countByKey = { 'Companies': len(companies), 'Contacts': len(contacts), 'Countries': len(countries), 'Patents': len(patents), 'PatentInventors': len(patentInventors), 'PatentStatuses': len(patentStatuses), 'PatentTypes': len(patentTypes), 'Phones': len(phones), 'Technologies': len(technologies), } return payload, countByKey # If we are running standalone, if __name__ == '__main__': # Parse optionParser = script_process.OptionParser() options = optionParser.parse_args()[0] # Run message = run(script_process.initialize(options)) # Say if options.verbose: print message
# Get messageFromWhom = message.fromWhom.lower() try: personID = int(message.subject) except ValueError: return False # If personID == 0, then the sender is trying to unregister his or her phone if personID == 0: Session.query(model.SMSAddress).filter_by(email=messageFromWhom).delete() return True # Load person = Session.query(model.Person).options(orm.eagerload(model.Person.sms_addresses)).get(personID) # If the person doesn't exist or we have recorded the address already, if not person or messageFromWhom in (x.email.lower() for x in person.sms_addresses): return False # Add Session.add(model.SMSAddress(messageFromWhom, personID)) # Return return True # If we are running standalone, if __name__ == '__main__': # Parse optionParser = script_process.buildOptionParser() options = optionParser.parse_args()[0] # Initialize configuration = script_process.initialize(options) # Run print run()
for proj4Standard, srid in Session.execute('SELECT proj4text, srid FROM spatial_ref_sys'): # Skip empty proj4s if not proj4Standard.strip(): continue # If we have a match, if simplifyProj4(proj4Standard) == proj4Simplified: return srid # If we have no matches, raise exception raise model.GeoRegistryError('Could not recognize proj4 spatial reference') # If we are running standalone, if __name__ == '__main__': # Parse optionParser = script_process.buildOptionParser() options, arguments = optionParser.parse_args() # Load countryPackByAlpha3 countryPackByAlpha3 = {} countryPath = store.expandBasePath('utilities/countries.csv') for countryName, countryAlpha2, countryAlpha3 in csv.reader(open(countryPath, 'rt')): countryPackByAlpha3[countryAlpha3.upper()] = countryName, countryAlpha2.upper() # Initialize script_process.initialize(options) person = Session.query(model.Person).filter_by(username='******').first() personID = person.id folderPath = arguments[0] if arguments else '' # For each filePath, for filePath in sorted(glob.glob(os.path.join(folderPath, '*.shp'))): # Run print run(filePath)
personID = int(message.subject) except ValueError: return False # If personID == 0, then the sender is trying to unregister his or her phone if personID == 0: Session.query( model.SMSAddress).filter_by(email=messageFromWhom).delete() return True # Load person = Session.query(model.Person).options( orm.eagerload(model.Person.sms_addresses)).get(personID) # If the person doesn't exist or we have recorded the address already, if not person or messageFromWhom in (x.email.lower() for x in person.sms_addresses): return False # Add Session.add(model.SMSAddress(messageFromWhom, personID)) # Return return True # If we are running standalone, if __name__ == '__main__': # Parse optionParser = script_process.buildOptionParser() options = optionParser.parse_args()[0] # Initialize configuration = script_process.initialize(options) # Run print run()