Skip to content

Instantly share code, notes, and snippets.

@Jimexist
Created October 20, 2017 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jimexist/26c66a54c457a85cba4732ca78b257c4 to your computer and use it in GitHub Desktop.
Save Jimexist/26c66a54c457a85cba4732ca78b257c4 to your computer and use it in GitHub Desktop.
vgg download
#!/usr/bin/env python3
import os
def gen_dir(root, d):
path = os.path.join(root, d)
print('processing', path)
os.makedirs(path, exist_ok=True)
makefile_path = os.path.join(path, 'Makefile')
file_ids = []
urls = []
with open(path+'.txt', 'r') as fin:
for line in fin.readlines():
tokens = line.split(' ')
file_id, url = tokens[:2]
file_ids.append('_'.join([d, file_id]))
urls.append(url)
with open(makefile_path, 'w') as fout:
print('generating', makefile_path)
fout.write('all: ' + ' '.join(file_ids) + '\n\n')
for file_id, url in zip(file_ids, urls):
fout.write('{}:\n'.format(file_id))
fout.write('\t-wget -nc --timeout=120 --quiet -O {} {}\n\n'.format(file_id, url))
def main():
for root, dirs, files in os.walk('./files'):
for f in files:
if f.endswith('.txt'):
gen_dir(root, f[:-4])
if __name__ == '__main__':
main()
SUBDIRS := $(wildcard files/*)
all: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
.PHONY: all $(SUBDIRS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment