forked from hbunke/BibsOnGitHub
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjson-to-html-libs.py
51 lines (45 loc) · 1.48 KB
/
json-to-html-libs.py
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
import json
html_string = '''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.css">
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.js"></script>
<script type="text/javascript" class="init">
$(document).ready( function () {
$('#table_id').DataTable();
} );
</script>
<style>
body {
font-family: Tahoma, Verdana, sans-serif;
margin: 30px;
}
</style>
</head>
<body>
<h2>Libraries on GitHub</h2>
<table id="table_id" class="display">
<thead>
<tr>
<th>Country</th>
<th>City</th>
<th>Organisation</th>
<th>Repositories</th>
</tr>
</thead>
<tbody id="myTable">
'''
with open("all-libs.json", 'r', encoding="utf-8") as json_file:
data = json.load(json_file)
for org in data["organisations"]:
html_string += "<tr><td>" + org['country'] + "</td><td>" + org['city'] + "</td><td><a href=\"" + org['url'] + "\">" + org['name'] + "</a></td><td>" + str(len(org['repositories'])) + "</td></tr>\n"
html_string += '''
</tbody>
</table>
</body>
'''
with open('libraries.html', 'w', encoding='utf8') as html_file:
html_file.write(html_string)