Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Number Extractor plugin #507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PluginDirectories/1/number-extractor.bundle/README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Number extractor

Extracts only the numbers of a given string and saves it to the clipboard
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions PluginDirectories/1/number-extractor.bundle/examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
number ~message(12.3.42.4.2-32 2)
ne ~message(1 2 3 )
numbers ~message(['23', '232', '3232'])
number ~message(123.323.423-94)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions PluginDirectories/1/number-extractor.bundle/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"categories" : [
"Utilities"
],
"displayName" : "Number Extractor",
"name" : "number-extractor",
"description" : "Extracts only the numbers of a given string and sends the result to the clipboard",
"examples" : [
"number 123.42.3424-3423",
"ne 92 342 5432 2",
"numbers a2b3d4d2d2"
],
"creator_name" : "Psidium",
"creator_url" : "http://github.com/Psidium"
}
52 changes: 52 additions & 0 deletions PluginDirectories/1/number-extractor.bundle/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
def appearance(): #using from emoji.bundle
import Foundation
dark_mode = Foundation.NSUserDefaults.standardUserDefaults().persistentDomainForName_(Foundation.NSGlobalDomain).objectForKey_("AppleInterfaceStyle") == "Dark"
return "dark" if dark_mode else "light"

def extract_number(numbers_and_things):
import re
return re.sub(r"[^0-9]", '', numbers_and_things)

def make_html(number):
#using styles found in emoji.bundle
html = """
<head>
<style>
body{
padding: 10px 12px;
font: 15px/1.4 'Helvetica Neue';
font-weight: 300;
}
h1 {
font-size: 20px;
font-weight: 300;
}
.dark {
color: rgb(224,224,224);
}
</style>
</head>
<body class="{{appearance}}">
<h1>
{{number}}
</h1>
</body>
"""
html = html.replace("{{appearance}}", appearance())
html = html.replace("{{number}}", number)
return html


def results(fields, original_query):
message = fields['~message']
return {
"title": "Extract numbers from '{0}'".format(message),
"run_args": [message],
"html": make_html(extract_number(message)),
'webview_transparent_background': True,
}

def run(message):
import os
numbers = extract_number(message)
os.system("echo '%s' | pbcopy" % numbers) #I'm assuming this script will ONLY run in OS X