-
-
Save EdwardIII/4721516 to your computer and use it in GitHub Desktop.
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 | |
from linklooker.linklooker import Links, Link | |
import argparse | |
import csv | |
def output_results(results, output_file): | |
if not results: | |
exit("Couldn't find any results!") | |
#TODO: use for -v mode | |
#import os | |
#for row in results: | |
# for key in row.keys(): | |
# print '{} {}'.format(key, row[key]) | |
# print os.linesep | |
#if parser.parse_args().output: | |
#out_f = parser.parse_args().output | |
# Write out header | |
header = results[0].keys() | |
# Write out dictionary | |
data = csv.DictWriter(output_file, header, delimiter=',') | |
print data.writeheader() | |
for r in results: | |
print data.writerow(r) | |
output_file.close() | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--csv', help='Provide a CSV to scan links from with the format: link, link to look for') | |
parser.add_argument('--prcsv', help='Provide a CSV to scan links in sho\'s format') | |
parser.add_argument('--pr_first', help='Provide a CSV to scan links with the new format from 19/12/2012') | |
parser.add_argument('--output', type=argparse.FileType('w'), help='Path to output CSV') | |
parser.add_argument('--grcsv', help='Only check that a CSV of urls are up') | |
links = Links() | |
if parser.parse_args().csv: | |
print "Parsing CSV..." | |
results = links.status_table_from_csv(parser.parse_args().csv) | |
output_results(results, parser.parse_args().output) | |
if parser.parse_args().prcsv: | |
print "Parsing PR CSV..." | |
results = links.status_table_from_pr_csv(parser.parse_args().prcsv) | |
output_results(results, parser.parse_args().output) | |
if parser.parse_args().pr_first: | |
print "Parsing CSV..." | |
output_results(links.table_from_pr_first_csv(parser.parse_args().pr_first), parser.parse_args().output) | |
if parser.parse_args().grcsv: | |
print "Checking if url is up..." | |
output_results(links.pr_greater_than_0(parser.parse_args().grcsv), parser.parse_args().output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment