diff --git a/Powerthesaurus-2.1.1.alfredworkflow b/Powerthesaurus-2.1.2.alfredworkflow similarity index 97% rename from Powerthesaurus-2.1.1.alfredworkflow rename to Powerthesaurus-2.1.2.alfredworkflow index a97599d..275f238 100644 Binary files a/Powerthesaurus-2.1.1.alfredworkflow and b/Powerthesaurus-2.1.2.alfredworkflow differ diff --git a/README.md b/README.md index 177725e..6a0cd82 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,28 @@ Resulting synonyms or antonyms will be sequentially listed according to user rat Use the `init.sh` script to install the required dependencies inside the `src` folder. When you're ready to test or export, copy the entire `src` folder to the existing workflow directory. +## Troubleshooting ## + +#### SSL Errors +If you're having SSL issues, try temporarily disabling it by setting the workflow environment variable `ALFRED_PT_SSL_VERIFICATION` to `False`. This will bypass SSL verification as a workaround while waiting for the SSL certificate to be rectified. You can check Power Thesaurus's SSL certificate status [here](https://www.sslshopper.com/ssl-checker.html#hostname=api.powerthesaurus.org). Be sure to set it back to `True` when all's green. + +#### Other Errors +For other errors, please open an issue describing how you got the error and together with the logs from `Alfred > Workflows > Debugging Mode` if possible. There's no proper error handling in place yet, so we'll have to troubleshoot things this way for now. + + +## Related Links ## + +[GitHub Repository](https://github.com/clarencecastillo/alfred-powerthesaurus) +[Alfred Forums](https://www.alfredforum.com/topic/10576-powerthesaurus-search/) +[Packal](http://www.packal.org/workflow/powerthesaurus-search) + ## Releases ## There's probably a smarter way to do this, but when preparing a new release, don't forget to: 1. Bump `version` file -2. Bump `user-agent` version inside `src/api.py` -3. Bump the exported workflow following the format `Powerthesaurus-x.x.x.alfredworkflow` -4. Bump `alfredworkflow.version` field in `metadata.json` or just re-export the entire `metadata.json` - +2. Bump the exported workflow following the format `Powerthesaurus-x.x.x.alfredworkflow` +3. Bump `alfredworkflow.version` field in `metadata.json` or just re-export the entire `metadata.json` from `Alfred > Workflows` ## Licensing ## diff --git a/metadata.json b/metadata.json index 152adbf..2082539 100644 --- a/metadata.json +++ b/metadata.json @@ -4,7 +4,7 @@ "readme" : "Search Powerthesaurus synonyms and antonyms from Alfred", "createdby" : "Clarence Castillo", "downloadurl" : "", - "version" : "2.1.1", + "version" : "2.1.2", "bundleid" : "me.clarencecastillo.alfred-powerthesaurus", "description" : "Search for synonyms and antonyms on powerthesaurus.org", "name" : "Powerthesaurus", diff --git a/src/api.py b/src/api.py index d7c51da..0ea9025 100644 --- a/src/api.py +++ b/src/api.py @@ -5,11 +5,12 @@ class PowerThesaurus: - USER_AGENT = "Alfred-Powerthesaurus/2.1.1" - GQL_THESAURUS_QUERY = "thesaurus_query" - GQL_SEARCH_QUERY = "search_query" + VERSION = open('./version').readline() + GQL_THESAURUS_QUERY = 'thesaurus_query' + GQL_SEARCH_QUERY = 'search_query' + VERIFY_SSL = bool(os.getenv('ALFRED_PT_SSL_VERIFICATION')) - def __init__(self, api_url, web_url, gql_queries_dir="./gql_queries/", pos_file_path="./pos.json", logger=logging): + def __init__(self, api_url, web_url, gql_queries_dir='./gql_queries/', pos_file_path='./pos.json', logger=logging): self.api_url = api_url self.web_url = web_url self.logger = logger @@ -22,8 +23,8 @@ def build_url(self, slug, query_type): def build_request_headers(self): return { - "user-agent": PowerThesaurus.USER_AGENT, - "content-type": "application/json" + 'user-agent': 'Alfred-PowerThesaurus/' + PowerThesaurus.VERSION, + 'content-type': 'application/json' } def read_pos_mapping(self, file_path): @@ -47,31 +48,31 @@ def read_gql_queries(self, dir): def build_search_query_params(self, query): return { - "operationName": "SEARCH_QUERY", - "variables": { - "query": query + 'operationName': 'SEARCH_QUERY', + 'variables': { + 'query': query }, - "query": self.gql_queries[PowerThesaurus.GQL_SEARCH_QUERY] + 'query': self.gql_queries[PowerThesaurus.GQL_SEARCH_QUERY] } def build_thesaurus_query_params(self, term_id, query_type): return { - "operationName": "THESAURUSES_QUERY", - "variables": { - "list": query_type.upper(), - "termID": term_id, - "sort": { - "field": "RATING", - "direction": "DESC" + 'operationName': 'THESAURUSES_QUERY', + 'variables': { + 'list': query_type.upper(), + 'termID': term_id, + 'sort': { + 'field': 'RATING', + 'direction': 'DESC' }, - "limit": 50, - "syllables": None, - "query": None, - "posID": None, - "first": 50, - "after": "" + 'limit': 50, + 'syllables': None, + 'query': None, + 'posID': None, + 'first': 50, + 'after': '' }, - "query": self.gql_queries[PowerThesaurus.GQL_THESAURUS_QUERY] + 'query': self.gql_queries[PowerThesaurus.GQL_THESAURUS_QUERY] } def parse_thesaurus_query_response(self, response): @@ -94,7 +95,7 @@ def thesaurus_query(self, term_id, query_type): if not term_id: return [] params = self.build_thesaurus_query_params(term_id, query_type) - r = requests.post(self.api_url, json=params, headers=self.request_headers, verify=False) + r = requests.post(self.api_url, json=params, headers=self.request_headers, verify=PowerThesaurus.VERIFY_SSL) self.logger.debug('thesaurus_query: {} {}'.format(r.status_code, r.url)) r.raise_for_status() return self.parse_thesaurus_query_response(r.json()) @@ -108,7 +109,7 @@ def parse_search_query_response(self, response): def search_query(self, query): params = self.build_search_query_params(query) - r = requests.post(self.api_url, json=params, headers=self.request_headers, verify=False) + r = requests.post(self.api_url, json=params, headers=self.request_headers, verify=PowerThesaurus.VERIFY_SSL) self.logger.debug('search_query: {} {}'.format(r.status_code, r.url)) r.raise_for_status() return self.parse_search_query_response(r.json()) diff --git a/src/version b/src/version index 3e3c2f1..eca07e4 100644 --- a/src/version +++ b/src/version @@ -1 +1 @@ -2.1.1 +2.1.2