This repository has been archived by the owner on Dec 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of a CLI that will strain links out to CSV
- Loading branch information
Showing
5 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ __pycache__/ | |
# Distribution / packaging | ||
.Python | ||
env/ | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
import optparse | ||
import storytracker | ||
|
||
|
||
p = optparse.OptionParser( | ||
description="Archive the HTML from the provided URLs", | ||
usage="storytracker-archive [URL]... [OPTIONS]", | ||
) | ||
|
||
p.add_option( | ||
"--do-not-verify", | ||
"-v", | ||
action="store_false", | ||
dest="verify", | ||
default=True, | ||
help="Skip verification that HTML is in the response's content-type header" | ||
) | ||
|
||
p.add_option( | ||
"--do-not-minify", | ||
"-m", | ||
action="store_false", | ||
dest="minify", | ||
default=True, | ||
help="Skip minification of HTML response" | ||
) | ||
|
||
p.add_option( | ||
"--do-not-extend-urls", | ||
"-e", | ||
action="store_false", | ||
dest="extend_urls", | ||
default=True, | ||
help="Do not extend relative urls discovered in the HTML response" | ||
) | ||
|
||
p.add_option( | ||
"--do-not-compress", | ||
"-c", | ||
action="store_false", | ||
dest="compress", | ||
default=True, | ||
help="Skip compression of the HTML response" | ||
) | ||
|
||
p.add_option( | ||
"--output-dir", | ||
"-d", | ||
action="store", | ||
type="string", | ||
dest="output_dir", | ||
default=None, | ||
help="Provide a directory for the archived data to be stored" | ||
) | ||
|
||
kwargs, args = p.parse_args() | ||
|
||
for a in args: | ||
obj = storytracker.archive(a, **kwargs.__dict__) | ||
if not kwargs.output_dir and obj: | ||
if kwargs.compress: | ||
sys.stdout.write(obj.gzip) | ||
else: | ||
sys.stdout.write(obj.html.encode("utf-8")) | ||
elif kwargs.output_dir and obj: | ||
sys.stdout.write(obj.archive_path) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
import optparse | ||
import storytracker | ||
|
||
|
||
p = optparse.OptionParser( | ||
description="Retrieves HTML from the provided URLs", | ||
usage="storytracker-get [URL]... [OPTIONS]", | ||
) | ||
|
||
p.add_option( | ||
"--do-not-verify", | ||
"-v", | ||
action="store_false", | ||
dest="verify", | ||
default=True, | ||
help="Skip verification that HTML is in the response's content-type header" | ||
) | ||
|
||
kwargs, args = p.parse_args() | ||
|
||
for a in args: | ||
html = storytracker.get(a, verify=kwargs.verify) | ||
sys.stdout.write(html.encode("utf-8")) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
import csv | ||
import six | ||
import optparse | ||
import storytracker | ||
|
||
|
||
p = optparse.OptionParser( | ||
description="Extracts hyperlinks from archived files or streams and \ | ||
outputs them as comma-delimited values", | ||
usage="storytracker-links2csv [ARCHIVE PATH]...", | ||
) | ||
|
||
kwargs, args = p.parse_args() | ||
|
||
def prep(val): | ||
if not val: | ||
return None | ||
else: | ||
return six.text_type(val).encode("utf-8") | ||
|
||
for a in args: | ||
obj = storytracker.open_archive_filepath(a) | ||
f = six.BytesIO() | ||
writer = csv.writer(f) | ||
for h in obj.hyperlinks: | ||
writer.writerow(map(prep, [ | ||
obj.url, | ||
obj.timestamp, | ||
h.string, | ||
h.domain, | ||
h.href, | ||
])) | ||
sys.stdout.write(f.getvalue()) | ||
|
||
# Allow directory input? | ||
# Allow stream input? |
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