forked from Geonovum/technisch-register
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpages.py
More file actions
110 lines (84 loc) · 3.56 KB
/
Copy pathwebpages.py
File metadata and controls
110 lines (84 loc) · 3.56 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from bs4 import BeautifulSoup as BS
from json import load
from subprocess import call
import codecs
def create_standard_title(title, description):
title = '''
<h2>%s</h2>
<p>%s</p>
''' % (title, description)
# use python's built-in parser since
# it does not create html and body tags
return BS(title, 'html.parser')
def create_artifact_title(standard, artifact, title):
title = '''
<p><i class="fa fa-file-o"></i>
<span style='margin-left: 25px'>
<a href="http://register.geostandaarden.nl/%s/%s">%s</a>
</span>
</p> ''' % (artifact, standard, title)
return BS(title, 'html.parser')
def create_artifact_description(artifact):
summary ='''
<p>
<span style='margin-left:37px; width: 100%%'>%s</span>
</p>
''' % artifact['beschrijving']
return BS(summary, 'html.parser')
def create_standard_webpage(standard, artifacts):
"""Build a standard's overview page
e.g. http://register.geostandaarden.nl/imgeo/
"""
# load standard HTML template
with open('web/templates/standard.html', 'r') as f:
html = BS(f, 'html.parser')
# fetch title element from template
el_title = html.find(id="title")
# fetch #container element from template
el_container = html.find(id="container")
# construct title
title = create_standard_title(standard['titel'], standard['beschrijving'])
# append title to #title div
el_title.append(title)
with codecs.open('descriptions.json', encoding='utf8') as f:
descriptions = load(f)
# iterate over all artifacts i.e. informatiemodel, gmlapplicatieschema, regels, etc.
for artifact in artifacts:
# create title of each artifact
title = create_artifact_title(standard['id'], artifact, descriptions[artifact]['titel'])
el_container.append(title)
# create description of each standard
description = create_artifact_description(descriptions[artifact])
el_container.append(description)
informatiemodel_link = html.find(id="breadctxt").findAll('a')[-1]
standard_title = standard['titel_kort']
informatiemodel_link['href'] = "http://register.geostandaarden.nl/" + standard_title.lower()
informatiemodel_link.string = standard_title
return html.prettify()
def create_overview_entry(standard, title_short, description):
# url = "http://register.geostandaarden.nl"
url = "."
overview = '''
<p>
<i class="fa fa-file"></i>
<span style='margin-left: 25px'>
<a href="%s/%s/index.html">%s</a>
</span>
</p>
<p><span style='margin-left:37px; width: 100%%'>%s</span></p>
''' % (url, standard, title_short, description)
return BS(overview, 'html.parser')
def create_overview_page(standards, source, destination_temp):
print 'Creating overview page...'
# open overview page template
with codecs.open('web/templates/overview.html', 'r', encoding='utf8') as f:
html = BS(f, 'html.parser')
el_container = html.find(id='leftcolumn')
for standard in standards:
overview = create_overview_entry(standard['id'], standard['titel_kort'], standard['beschrijving_kort'])
el_container.append(overview)
with codecs.open('%s/index.html' % destination_temp, 'w', encoding='utf8') as f:
f.write(html.prettify())
#OSFS('./').copydir('../web/assets', '%s/assets' % destination_temp)
# call('cp -r web/assets %s/assets' % destination_temp, shell=True)
print 'Done!'