I have a workflow that runs the following bash script
#!/bin/bash
source /Users/user123/Vault/TCPA/Scripts/'Link Scraper'/venv/bin/activate /Users/user123/Vault/TCPA/Scripts/'Link Scraper'/venv/bin/python3.9 /Users/usr123/Vault/TCPA/Scripts/'Link Scraper'/phone.py "{query}"
If I run the bash script from the terminal it works
If I run the python script from the terminal it works
the keyword passes the query to the bash script
but nothing seems to come out the other end of the python script.
I've tried having the python script create the file I want, no luck
I've tried having alfred create the file, no luck
the python script
import json
import requests
import pprint
import sys
import re
class IPQS:
key = 'gAZTc419da1PfKwjrIkjgZTPe1BmbKV7'
def phone_number_api(self, phonenumber: str, vars: dict = {}) -> dict:
url = 'https://www.ipqualityscore.com/api/json/phone/%s/%s' %(self.key, clean_phone_number(phonenumber))
x = requests.get(url, params = vars)
return (json.loads(x.text))
def clean_phone_number(phone_number):
# Remove the hyphens and parentheses from the phone number
stripped_phone_number = phone_number.replace("-", "").replace("(", "").replace(")", "")
return stripped_phone_number
def dirty_phone_number(phone_number):
# Extract the digits from the phone number
digits = re.sub(r'\D', '', phone_number)
# Format the phone number as (xxx) xxx-xxxx
formatted_phone_number = f"({digits[:3]}){digits[3:6]}-{digits[6:]}"
return formatted_phone_number
if __name__ == "__main__":
pp = pprint.PrettyPrinter(indent=4)
# Check if a phone number was passed as a command line argument
if len(sys.argv) < 2:
#print("Usage: python phone.py phone_number")
#sys.exit(1)
phone = input("Phone: ")
else:
# Get the phone number from the command line argument
phone = clean_phone_number(sys.argv[1])
#Retrieve additional (optional) data points which help us enhance fraud scores and ensure data is processed correctly.
countries = {'US', 'CA'};
#custom feilds
additional_params = {
'country' : countries
}
ipqs = IPQS()
result = ipqs.phone_number_api(phone, additional_params)
yaml = f"""---
carrier: {result["carrier"]}
---
"""
query = f"""
# Notes where this number appears:
```dataview
list
where contains(callerID, this.file.name)
```"""
# Check to see if our query was successful.
if 'success' in result and result['success']:
# Convert the result to a string
result_str = pprint.pformat(result)
# Set the save location
save_location = f'/Users/user123/Vault/TCPA/1 - Cases/51 - Phone Numbers/{dirty_phone_number(phone)}.md'
text = f"""{yaml}\n{result_str}\n{query}"""
sys.stdout.write(text)