-
Notifications
You must be signed in to change notification settings - Fork 0
/
zd_download.py
62 lines (51 loc) · 1.5 KB
/
zd_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# encoding: utf-8
import os
import string
import sys
import workflow
import tempfile
import subprocess
def getAppleScript(browser="Google Chrome"):
template = """
on run argv
tell application "%s"
set result to execute front window's active tab javascript "
attachments = this.document.getElementsByClassName(\\"attachment\\");
var thisPageAttachments = [];
for (var i=0; i < attachments.length; i++){
thisPageAttachments.push(attachments[i].href);
}
thisPageAttachments"
end tell
return result
end run
"""
return template % (browser)
def main(wf):
log = wf.logger
applescript = tempfile.NamedTemporaryFile(suffix=".applescript", delete=False)
applescript.write(getAppleScript())
proc = subprocess.Popen(['/usr/bin/osascript', applescript.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = proc.communicate()
out = None
err = None
log.debug(out)
log.debug(err)
log.debug(applescript.name)
log.debug("Done!")
wf.add_item(
title="result",
arg=out,
valid=True
)
print "test"
wf.send_feedback()
if __name__ == u"__main__":
wf = workflow.Workflow(
# update_settings={
# 'github_slug': 'mikepkes/ZendeskHelpers',
# 'frequency': 1
# }
)
wf.run(main)