add hooks in code for shell commands
This commit is contained in:
		
							parent
							
								
									eca8619153
								
							
						
					
					
						commit
						e88d545955
					
				
							
								
								
									
										13
									
								
								gps_data.py
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								gps_data.py
									
									
									
									
									
								
							| @ -61,6 +61,10 @@ import codecs | |||||||
| #Needed for working with NMEA | #Needed for working with NMEA | ||||||
| import pynmea2 | import pynmea2 | ||||||
| 
 | 
 | ||||||
|  | # Modules for executing commands/scripts | ||||||
|  | import os | ||||||
|  | from gps_functions import cmd_list | ||||||
|  | 
 | ||||||
| # Does anybody read this stuff? There's a PEP somewhere that says I should do this. | # Does anybody read this stuff? There's a PEP somewhere that says I should do this. | ||||||
| __author__     = 'Cortney T. Buffington, N0MJS; Eric Craw, KF7EEL' | __author__     = 'Cortney T. Buffington, N0MJS; Eric Craw, KF7EEL' | ||||||
| __copyright__  = 'Copyright (c) 2020 Cortney T. Buffington' | __copyright__  = 'Copyright (c) 2020 Cortney T. Buffington' | ||||||
| @ -122,7 +126,14 @@ def process_sms(from_id, sms): | |||||||
|     if sms == 'ID': |     if sms == 'ID': | ||||||
|         logger.info(str(get_alias(int_id(from_id), subscriber_ids)) + ' - ' + str(int_id(from_id))) |         logger.info(str(get_alias(int_id(from_id), subscriber_ids)) + ' - ' + str(int_id(from_id))) | ||||||
|     if sms == 'TEST': |     if sms == 'TEST': | ||||||
|         logger.info('This is a really cool function.') |         logger.info('It works!') | ||||||
|  |     try: | ||||||
|  |         if sms in cmd_list: | ||||||
|  |             logger.info('Executing command/script.') | ||||||
|  |             os.popen(cmd_list[sms]).read() | ||||||
|  |     except: | ||||||
|  |         logger.info('Exception. Command possibly not in list, or other error.') | ||||||
|  |      | ||||||
|     else: |     else: | ||||||
|         pass |         pass | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										9
									
								
								gps_functions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								gps_functions.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | # Various configurable options used in the GPS/Data application. | ||||||
|  | 
 | ||||||
|  | # SMS message that triggers command | ||||||
|  | cmd_list = { | ||||||
|  | 
 | ||||||
|  |     'LS' : 'ls -lsh', | ||||||
|  |     'UPTIME' : 'uptime' | ||||||
|  | 
 | ||||||
|  |     } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user