Simple python wrapper for alfred5 workflow / snippets
Project description
🎩 AlfredClient
Simplest Alfred Client that I use my own projects.
Usage
pip install alfred5
- Projects dir structure
- Put your codes and
requirements.txttosrcfolders - Install
alfred5viapip install alfred5 --target=src/libs
- Add the top of the
main.pyimport sys sys.path.insert(0, "src/libs")
- If u want to use different
--targetfor ex.useWorkflowClient.run(packagedir=".") - Sample of default structure:
- If u install all of requirements, dont need to create
requirements.txtfile insrc - If you use
vscode, add the code that below to.vscode/settings.jsonto debug your file{ "python.analysis.extraPaths": [ "./src/libs" ], "python.analysis.exclude": [ "./src/libs" ] }
- Put your codes and
- Via
SnippetsClientAPI create custom snippets programmaically - Via
WorkflowClientAPI create custom alfred workflow- Craete
requirements.txtfile for your python project to letalfred5installs them if needed 🙃 - To install
from requirements.txtdo all import packages insidemain- Useglobalkeyword to access imported packages globallyclient.queryis the query stringclient.page_countis the page count for pagination results
- Dont need to add
alfred5torequirements.txt
- Craete
- Use
WorkflowClient.logto log your message to alfred debugger - Use
WorkflowClient(main, cache=True)method to use caching system- Just do it for static (not timebased nor any dynamic stuff) response
- Db path is
db/results.ymlalso you can see it from workflow debug panel
⭐️ Example Project
from re import sub
from urllib.parse import quote_plus
import sys
sys.path.insert(0, "src/libs")
from alfred5 import WorkflowClient
async def main(client: WorkflowClient):
# To auto install requirements all import operation must be in here
global get
from requests import get
query = client.query
client.log(f"my query: {query}") # use it to see your log in workflow debug panel
# (use cache=True) Use cache system to quick response instead of old style that below
# if client.load_cached_response():
# return
char_count = str(len( query))
word_count = str(len(query.split(" ")))
line_count = str(len(query.split("\n")))
encoded_string = quote_plus(query)
remove_dublication = " ".join(dict.fromkeys(query.split(" ")))
upper_case = query.upper()
lower_case = query.lower()
capitalized = query.capitalize()
template = sub(r"[a-zA-Z0-9]", "X", query)
client.add_result(encoded_string, "Encoded", arg=encoded_string)
client.add_result(remove_dublication, "Remove dublication", arg=remove_dublication)
client.add_result(upper_case, "Upper Case", arg=upper_case)
client.add_result(lower_case, "Lower Case", arg=lower_case)
client.add_result(capitalized, "Capitalized", arg=capitalized)
client.add_result(template, "Template", arg=template)
client.add_result(char_count, "Characters", arg=char_count)
client.add_result(word_count, "Words", arg=word_count)
client.add_result(line_count, "Lines", arg=line_count)
# (use cache=True) to cache result for query instead of old style that below
# if u work with static results (not dynamic; coin price etc.)
# client.cache_response()
if __name__ == "__main__":
WorkflowClient.run(main) # WorkflowClient.run(main, cache=True)
🔰 How to Create Workflow
🪪 License
Copyright 2023 Yunus Emre Ak ~ YEmreAk.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
alfred5-1.1.6.tar.gz
(64.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
alfred5-1.1.6-py3-none-any.whl
(62.2 kB
view details)
File details
Details for the file alfred5-1.1.6.tar.gz.
File metadata
- Download URL: alfred5-1.1.6.tar.gz
- Upload date:
- Size: 64.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33849f1306a84cdd2aec486f250a03be5914fa11bfd0ec3bb5cb0cf94c750b62
|
|
| MD5 |
50c629a397a4ca3b7dfa556281fe0138
|
|
| BLAKE2b-256 |
a124749a20e80d13183d2de68dbbdb3edded900addc81abebcb3c7d7edcf8b13
|
File details
Details for the file alfred5-1.1.6-py3-none-any.whl.
File metadata
- Download URL: alfred5-1.1.6-py3-none-any.whl
- Upload date:
- Size: 62.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e95dd9ada5fcf68f96356ba49cc845b2500f9686b36ebbfcd12cbdaae02e829f
|
|
| MD5 |
2c25a3d8a9ba61da6f60be790543b566
|
|
| BLAKE2b-256 |
4645e799e1a75dcee70dbfd98f3a1e50db6bc48c5def5d74dd7a1a61fe54579d
|