Skip to content

Commit 7ed3277

Browse files
author
Brandon Duffany
committed
Script to download cb_compile_tester's projects
1 parent 79acfd4 commit 7ed3277

32 files changed

+42
-0
lines changed

batch/__init__.py

Whitespace-only changes.

batch/fetch_projects.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
"""A script to downloads all projects for a particular user."""
3+
4+
# This is necessary in order to run the script; otherwise the script needs to
5+
# be run as a python module (which is inconvenient).
6+
if __name__ == '__main__' and __package__ is None:
7+
from os import sys, path
8+
sys.path.append(path.join(path.dirname(path.abspath(__file__)), '..'))
9+
10+
11+
from urllib.request import urlopen
12+
from urllib.request import urlretrieve
13+
import argparse
14+
import os
15+
16+
from codebender_testing.config import LIVE_SITE_URL
17+
18+
from lxml import html
19+
20+
21+
def download_projects(url, user, path):
22+
connection = urlopen('/'.join([url, 'user', user]))
23+
dom = html.fromstring(connection.read().decode('utf8'))
24+
os.chdir(path)
25+
for link in dom.xpath('//table[@id="user_projects"]//a'):
26+
project_name = link.xpath('text()')[0]
27+
sketch_num = link.xpath('@href')[0].split(':')[-1]
28+
print("Downloading %s (sketch %s)" % (project_name, sketch_num))
29+
urlretrieve('%s/utilities/download/%s' % (url, sketch_num),
30+
os.path.join(path, '%s.zip' % project_name))
31+
32+
33+
if __name__ == "__main__":
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("user", help="the user whose projects we want to download")
36+
parser.add_argument("-u", "--url", help="url of the codebender site to use",
37+
default=LIVE_SITE_URL)
38+
parser.add_argument("-d", "--directory", help="output directory of the downloaded projects",
39+
default=".")
40+
args = parser.parse_args()
41+
download_projects(args.url, args.user, args.directory)

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
flake8
2+
lxml
23
pytest
34
setuptools>=12.1
45
tox
775 Bytes
Binary file not shown.
1.32 KB
Binary file not shown.
1.38 KB
Binary file not shown.
6.09 KB
Binary file not shown.
Binary file not shown.
7.44 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)