Created
October 13, 2024 18:49
-
-
Save morsine/4b4530ef5cf0df6f11d540d0b3c475b2 to your computer and use it in GitHub Desktop.
Revisions
-
morsine created this gist
Oct 13, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #!/usr/bin/env python3 # this is an example python code to be used as an eventhandler for smstools (smsd) under linux # script output will be logged along with smsd enteries under smsd.log import sys def extract_number(file_path): phone_number = None with open(file_path, 'r', errors='ignore', encoding='iso-8859-1') as file: for line in file: if line.startswith('From:'): phone_number = line.split(':')[1].strip() break return phone_number def extract_text(file_path): text = "" with open(file_path, 'r', errors='ignore', encoding='iso-8859-1') as file: for i, line in enumerate(file): if i >= 13: # Start from the 14th line (index 13) text += line return text def main(): global file_path global text if len(sys.argv) < 2: print("Usage: python script.py <func> <file location>") sys.exit(1) if sys.argv[1] == "RECEIVED": file_path = sys.argv[2] phone_number = extract_number(file_path) text = extract_text(file_path) print("Phone number:", phone_number) print("Text:", text) else: print("not doing anything") sys.exit(0) if __name__ == "__main__": main()