Created
May 6, 2024 18:07
-
-
Save 0xOsprey/4b0ed14dfa2866c6294b53b118a0c069 to your computer and use it in GitHub Desktop.
Raycast Python script for parsing clipboard and opening a link
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 characters
#!/usr/bin/python3 | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title Parse and Open | |
# @raycast.mode silent | |
# Optional parameters: | |
# @raycast.icon 🔍 | |
# @raycast.packageName Developer Util | |
# Documentation: | |
# @raycast.author Joe Coll | |
# @raycast.authorURL https://github.com/0xOsprey | |
import re, webbrowser, pyperclip | |
regex_list = { | |
"eth_address": {"regex": "^0x[a-fA-F0-9]{40}$", "url": "https://etherscan.io/address/{}"}, | |
"eth_txn": {"regex": "^0x([A-Fa-f0-9]{64})$", "url": "https://etherscan.io/tx/{}"}, | |
"sol_address": {"regex": "(^[1-9A-HJ-NP-Za-km-z]{32,44}$)", "url": "https://solscan.io/account/{}"}, | |
"sol_txn": {"regex": "^[1-9A-Za-z]{128}$", "url": "https://solscan.io/tx/{}"}, | |
"twitter_handle": {"regex": "^@?(\w){1,15}$", "url": "https://twitter.com/{}"}, | |
"ipfs": {"regex": "^Qm[1-9A-Za-z]{44}$", "url": "https://ipfsexplorer.online/ipfs/{}"}, | |
"url": {"regex": "^http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", "url": "{}"} | |
} | |
if __name__ == "__main__": | |
if pyperclip.paste() != "": | |
for key in regex_list: | |
if re.search(regex_list[key]["regex"], pyperclip.paste()): | |
print("Opening {}".format(regex_list[key]["url"].format(pyperclip.paste()))) | |
webbrowser.open(regex_list[key]["url"].format(pyperclip.paste())) | |
exit() | |
print("Error: No match for {}".format(pyperclip.paste())) | |
else: | |
print("Error: Clipboard is empty") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment