Created
November 30, 2013 10:53
-
-
Save Enchufa2/7717627 to your computer and use it in GitHub Desktop.
Dropbox recursive downloader
This file contains 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/env python | |
# coding=UTF8 | |
# Author: Iñaki Ucar <i.ucar@enchufa2.es> | |
# Description: Dropbox recursive downloader | |
import os, sys | |
from urllib2 import urlopen, unquote | |
from bs4 import BeautifulSoup | |
from subprocess import call | |
if len(sys.argv) != 3: | |
print 'Use: ./dropbox-downloader.py <path> <url>' | |
exit() | |
path = sys.argv[1] | |
url = sys.argv[2] | |
def downloader(url): | |
soup = BeautifulSoup(urlopen(url)) | |
for a in soup.find_all('a', 'filename-link'): | |
href = a.attrs['href'] | |
name = unquote(href.split('/')[-1]) | |
if name.find('.') == -1: | |
os.mkdir(name) | |
os.chdir(name) | |
downloader(href) | |
else: | |
call(['wget', href]) | |
os.chdir('..') | |
os.chdir(path) | |
downloader(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment