Created
January 19, 2017 01:21
-
-
Save nvllsvm/64ccbc5cecba817cc86d18e6645dc2b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import argparse | |
import os | |
import requests | |
MAX_RFC = 8056 | |
def download_rfc(rfc_num, output_dir): | |
print(f'Downloading {rfc_num}') | |
filename = f'rfc{rfc_num}.txt' | |
url = f'https://www.rfc-editor.org/rfc/{filename}' | |
response = requests.get(url) | |
if response.status_code == 200: | |
output_path = os.path.join(output_dir, filename) | |
with open(output_path, 'w') as f: | |
f.write(response.text) | |
else: | |
print(f'Error downloading RFC{rfc_num}.') | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-r', '--rfc_num') | |
parser.add_argument('-a', '--all', action='store_const', const=True) | |
parser.add_argument('output_dir') | |
args = parser.parse_args() | |
if args.rfc_num: | |
download_rfc(args.rfc_num, args.output_dir) | |
elif args.all: | |
for i in range(1, MAX_RFC + 1): | |
download_rfc(i, args.output_dir) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment