Skip to content

Instantly share code, notes, and snippets.

@sunuslee
Created November 27, 2012 16:21
Show Gist options
  • Save sunuslee/4155207 to your computer and use it in GitHub Desktop.
Save sunuslee/4155207 to your computer and use it in GitHub Desktop.
linux download tool with firefox addon:cliwget
#!/usr/bin/env python
# encoding=utf-8
import sys
import os
import datetime
SHEBANG = "#!/bin/bash\n\n"
def get_cmd(editor, initial=""):
from subprocess import call
from tempfile import NamedTemporaryFile
# Create the initial temporary file.
with NamedTemporaryFile(delete=False) as tf:
tfName = tf.name
tf.write(initial)
# Fire up the editor.
if call([editor, tfName], shell=False) != 0:
return None
# Editor died or was killed.
# Get the modified content.
fd = open(tfName)
res = fd.read()
fd.close()
os.remove(tfName)
return res
def main():
#cmd = raw_input('enter download cmd:\n')
cmd = get_cmd(editor='vim', initial="")
if len(sys.argv) > 1 and sys.argv[1] == 's':
#keep the download infomation.
t = datetime.datetime.now()
filename = "swget_%02d%02d%02d%02d%02d" %\
(t.month, t.day, t.hour, t.minute, t.second)
with open(filename, 'w') as f:
f.write(SHEBANG)
f.write(cmd)
f.close()
os.chmod(filename, 0777)
os.system(cmd)
main()
# usage install the addon at: https://addons.mozilla.org/en-US/firefox/addon/cliget/?src=userprofile
# when you have something to download, click the download button first, then copy the wget command lines from cliwget
# then run this script with the optional argument 's', copy the command to the editor, then save and quit. it will
# begin to download. if you have use the argument 's', then this script will create another executable script, you
# can use that script to resume you interrupt download.( if server support)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment