-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_csv.py
More file actions
91 lines (78 loc) · 3.53 KB
/
Copy pathexport_csv.py
File metadata and controls
91 lines (78 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
"""
Export services to CSV.
"""
import os
import glob
import yaml
import csv
import sys
def load_services():
script_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(os.path.dirname(script_dir))
services_dir = os.path.join(project_root, 'services')
services = []
for yaml_file in glob.glob(os.path.join(services_dir, '**', '*.yml'), recursive=True):
try:
with open(yaml_file, 'r') as f:
data = yaml.safe_load(f)
services.append(data['service'])
except Exception as e:
print(f"Error loading {yaml_file}: {e}")
for yaml_file in glob.glob(os.path.join(services_dir, '**', '*.yaml'), recursive=True):
try:
with open(yaml_file, 'r') as f:
data = yaml.safe_load(f)
services.append(data['service'])
except Exception as e:
print(f"Error loading {yaml_file}: {e}")
return services
def flatten_service(service):
# Flatten key fields
row = {
'id': service.get('id', ''),
'name': service.get('name', ''),
'provider': service.get('provider', ''),
'category': service.get('category', ''),
'url': service.get('url', ''),
'free_tier_type': service.get('free_tier', {}).get('type', ''),
'always_free_included': service.get('free_tier', {}).get('always_free', {}).get('included', False),
'time_limited_duration_days': service.get('free_tier', {}).get('time_limited', {}).get('duration_days', ''),
'credits_amount': service.get('free_tier', {}).get('credits', {}).get('amount', ''),
'regions_always_free': ', '.join(service.get('regions', {}).get('always_free', [])),
'gotchas': ', '.join(service.get('gotchas', [])),
'best_for': ', '.join(service.get('best_for', [])),
'not_for': ', '.join(service.get('not_for', [])),
'cost_under_free_tier': service.get('cost', {}).get('under_free_tier', ''),
'cost_typical_after': service.get('cost', {}).get('typical_after_free', ''),
'requirements_credit_card': service.get('requirements', {}).get('credit_card', False),
'requirements_phone_verification': service.get('requirements', {}).get('phone_verification', False),
'official_docs': service.get('resources', {}).get('official_docs', ''),
'last_verified': service.get('metadata', {}).get('last_verified', ''),
'verified_by': service.get('metadata', {}).get('verified_by', ''),
'cost_risk': service.get('flags', {}).get('cost_risk', ''),
'vendor_lock_in': service.get('flags', {}).get('vendor_lock_in', ''),
'learning_curve': service.get('flags', {}).get('learning_curve', ''),
'setup_time': service.get('flags', {}).get('setup_time', ''),
}
return row
def export_to_csv(services, output_file):
if not services:
print("No services to export.")
return
fieldnames = list(flatten_service(services[0]).keys())
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for service in services:
writer.writerow(flatten_service(service))
print(f"Exported {len(services)} services to {output_file}")
def main():
if len(sys.argv) != 2:
print("Usage: python export_csv.py <output.csv>")
sys.exit(1)
output_file = sys.argv[1]
services = load_services()
export_to_csv(services, output_file)
if __name__ == "__main__":
main()