|
1 |
| -import os |
2 |
| -import json |
3 |
| - |
4 |
| -directory = '../docs/_apps' |
5 |
| - |
6 |
| -apps = [app for app in os.listdir(directory) if os.path.isdir(os.path.join(directory, app)) and not app.startswith('_')] |
7 |
| - |
8 |
| -for app in apps: |
9 |
| - app_dir = os.path.join(directory, app) |
10 |
| - app_vers = [app_ver for app_ver in os.listdir(app_dir) if os.path.isdir(os.path.join(app_dir, app_ver))] |
11 |
| - sorted_app_info = sorted([app_ver.lstrip('v') for app_ver in app_vers], reverse=True) # sort versions from latest to earliest |
12 |
| - app_info_dict = {'v' + app_ver: tuple() for app_ver in sorted_app_info} |
13 |
| - for app_ver in app_vers: |
14 |
| - app_ver_dir = os.path.join(app_dir, app_ver) |
15 |
| - json_files = [json_file for json_file in os.listdir(app_ver_dir) if json_file[-5:] == '.json'] |
16 |
| - for json_file in json_files: |
17 |
| - json_file_path = os.path.join(app_ver_dir, json_file) |
18 |
| - if json_file == 'metadata.json': |
19 |
| - with open(json_file_path) as metadata_file: |
20 |
| - metadata = json.load(metadata_file) |
21 |
| - title = metadata['name'] |
22 |
| - ver_num = metadata['app_version'] |
23 |
| - if ver_num.lstrip('v') == sorted_app_info[0]: |
24 |
| - description = metadata['description'] # get description for the latest app version |
25 |
| - elif json_file == 'submission.json': |
26 |
| - with open(json_file_path) as submission_file: |
27 |
| - submission = json.load(submission_file) |
28 |
| - submitter = submission['submitter'] |
29 |
| - |
30 |
| - app_info_dict[app_ver] = (ver_num, submitter) |
31 |
| - |
32 |
| - file_name = os.path.join(directory, app, 'index.md') |
33 |
| - |
34 |
| - f = open(file_name, "w") |
35 |
| - |
36 |
| - f.write('---\n') |
37 |
| - f.write("layout: posts\n") |
38 |
| - f.write("classes: wide\n") |
39 |
| - f.write(f"title: {title}\n") |
40 |
| - f.write("---\n") |
41 |
| - f.write(f"{description}\n") |
42 |
| - |
43 |
| - for app_info in app_info_dict: |
44 |
| - ver_num = app_info_dict[app_info][0] |
45 |
| - submitter = app_info_dict[app_info][1] |
46 |
| - f.write(f"- [{ver_num}](http://apps.clams.ai/{app}/{ver_num}) ([`{submitter}`](https://github.com/{submitter}))\n") |
47 |
| - |
48 |
| - f.close() |
| 1 | +import os |
| 2 | +import json |
| 3 | +import datetime |
| 4 | + |
| 5 | +app_par_dir = os.path.join(os.path.dirname(__file__), '..', 'docs', '_apps') |
| 6 | + |
| 7 | +apps = [app for app in os.listdir(app_par_dir) if os.path.isdir(os.path.join(app_par_dir, app)) and not app.startswith('_')] |
| 8 | + |
| 9 | +for app in apps: |
| 10 | + app_dir = os.path.join(app_par_dir, app) |
| 11 | + app_vers = [app_ver for app_ver in os.listdir(app_dir) if os.path.isdir(os.path.join(app_dir, app_ver))] |
| 12 | + app_submitters = dict() |
| 13 | + app_descriptions = {app_ver: tuple() for app_ver in app_vers} |
| 14 | + app_vers_sorted = list() |
| 15 | + for app_ver in app_vers: |
| 16 | + app_ver_dir = os.path.join(app_dir, app_ver) |
| 17 | + json_files = [json_file for json_file in os.listdir(app_ver_dir) if json_file[-5:] == '.json'] |
| 18 | + for json_file in json_files: |
| 19 | + json_file_path = os.path.join(app_ver_dir, json_file) |
| 20 | + if json_file == 'metadata.json': |
| 21 | + with open(json_file_path) as metadata_file: |
| 22 | + metadata = json.load(metadata_file) |
| 23 | + app_title = metadata['name'] |
| 24 | + ver_num = metadata['app_version'] |
| 25 | + app_descriptions[app_ver] = metadata['description'] |
| 26 | + elif json_file == 'submission.json': |
| 27 | + with open(json_file_path) as submission_file: |
| 28 | + app_submission = json.load(submission_file) |
| 29 | + app_submitter = app_submission['submitter'] |
| 30 | + submission_time = app_submission['time'] |
| 31 | + app_submitters[app_ver] = app_submitter |
| 32 | + app_vers_sorted.append({'app_ver': app_ver, 'submission_time': submission_time}) |
| 33 | + |
| 34 | + app_vers_sorted.sort(key=lambda x: x['submission_time'], reverse=True) |
| 35 | + app_description = app_descriptions[app_vers_sorted[0]['app_ver']] |
| 36 | + |
| 37 | + file_name = os.path.join(app_par_dir, app, 'index.md') |
| 38 | + |
| 39 | + f = open(file_name, "w") |
| 40 | + |
| 41 | + f.write('---\n') |
| 42 | + f.write("layout: posts\n") |
| 43 | + f.write("classes: wide\n") |
| 44 | + f.write(f"title: {app_title}\n") |
| 45 | + f.write("---\n") |
| 46 | + f.write(f"{app_description}\n") |
| 47 | + |
| 48 | + clams_url = "{{ url }}" |
| 49 | + |
| 50 | + for app_ver in app_vers_sorted: |
| 51 | + ver_num = app_ver['app_ver'] |
| 52 | + app_submitter = app_submitters[ver_num] |
| 53 | + f.write(f"- [{ver_num}]({clams_url}/{app}/{ver_num}) ([`{app_submitter}`](https://github.com/{app_submitter}))\n") |
| 54 | + |
| 55 | + f.close() |
0 commit comments