Created
June 13, 2023 16:37
-
-
Save lordjabez/9a323066593646811ba45730ce807f3c to your computer and use it in GitHub Desktop.
Generate an index of AWS service FAQs
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
#!/usr/bin/env python3 | |
import boto3 | |
import cachier | |
import requests | |
@cachier.cachier() | |
def get_services(): | |
search_url = 'https://aws.amazon.com/api/dirs/items/search' | |
search_params = { | |
'item.directoryId': 'aws-products', | |
'item.locale': 'en_US', | |
'tags.id': ['aws-products#type#service', '!aws-products#type#variant'], | |
'size': 500, | |
} | |
response = requests.get(search_url, params=search_params) | |
return response.json()['items'] | |
@cachier.cachier() | |
def url_is_valid(url): | |
print(f'Validating {url}') | |
response = requests.get(url) | |
return response.status_code == requests.codes.ok and 'FAQs' in response.text | |
services = get_services() | |
services = (s['item'] for s in services) | |
services = ((s['name'], s['additionalFields']) for s in services) | |
services = ((s[0], s[1]['productName'], s[1]['productCategory'], s[1]['productUrl']) for s in services) | |
services = ((s[0], s[1], s[2], s[3].split('?')[0] + 'faqs/') for s in services) | |
services = (s for s in services if url_is_valid(s[3])) | |
services = sorted(services) | |
services_by_category = {} | |
for service in services: | |
category = service[2] | |
if category not in services_by_category: | |
services_by_category[category] = [] | |
services_by_category[category].append(service) | |
with open('services.html', 'w') as services_file: | |
for category in sorted(services_by_category): | |
print(f'<h3>{category}</h3>', file=services_file) | |
print('<ul>', file=services_file) | |
for service in services_by_category[category]: | |
print(f'<li><a href="{service[3]}">{service[1]}</a></li>', file=services_file) | |
print('</ul>', file=services_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment