-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathyaml_2_js.py
187 lines (176 loc) · 5.89 KB
/
yaml_2_js.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#! /usr/bin/env python
#coding=utf8
'''
Convert data.yaml to data.js
'''
import re
import yaml
from markdown import markdown
fields = [
'stars',
'stars_dif',
'name',
'source',
'open_issues',
'demo',
'js_kB',
'css_kB',
'language',
'db',
'markdown_support',
'social_network_login',
'anonymous_comments',
'edit',
'vote',
'moderation',
'nested_comments',
'mail_notification',
'antispam',
'bad_words_list',
'use_cookies',
'avatar',
'provided_hosting',
'collapse_comments',
'sort',
'docker',
'paging',
'rate_limit',
'hide_long_threads',
'import_from_wordpress',
'import_from_disqus',
'english_documentation',
'dependency',
'webmention',
'display_images',
'license',
'rss',
'static',
'created',
#'updated', # What's this date?
'last_committed',
#'unmaintained', #or Maintaned?
'description',
]
fields_dic={
'stars': 'Github stars',
'stars_dif': 'Stars in 2 weeks',
'name': 'Name',
'source': 'Source code',
'demo': 'Demo & examples',
'js_kB': 'js, kB',
'css_kB': 'css, kB',
'language': 'Language',
'db': 'Database',
'mail_notification': 'Mail notification',
'edit': 'User can edit',
'vote': 'User can vote',
'antispam': 'Antispam',
'bad_words_list': 'Bad words list',
'use_cookies': 'Uses cookies',
'avatar': 'Avatar',
'markdown_support': 'Markdown support',
'moderation': 'Moderation',
'dependency': 'Dependencies',
'webmention': 'Supports Webmention',
'nested_comments': 'Nested comments',
'provided_hosting': 'Can host for you',
'collapse_comments': 'Collapse comments',
'sort': 'Configurable order',
'rate_limit': 'Comment rate limit',
'docker': 'Docker container',
'paging': 'Paging',
'hide_long_threads': 'Hide long threads',
'anonymous_comments': 'Anonymous comments',
'social_network_login': 'Social network login',
'import_from_wordpress': 'Import from wordpress',
'import_from_disqus': 'Import from disqus',
'english_documentation': 'English documentation',
'rss': 'RSS',
'display_images': 'Display images',
'static': 'Static',
'description': 'Description',
'updated': 'Updated (y‑m‑d)',
'last_committed': 'Updated (y‑m‑d)',
'created': 'Created (y‑m‑d)',
'license': 'License',
'open_issues': 'Open issues + PR',
'unmaintained': 'Unmaintained',
}
def source_urlify(x):
ar=[]
if type(x) is list:
for i in range(len(x)):
if re.search('github.com', x[i]):
ar.append('<a href="{}">{}</a>'.format(x[i],'github') )
elif re.search('gitlab.com', x[i]):
ar.append('<a href="{}">{}</a>'.format(x[i],'gitlab') )
elif re.match('^http', x[i]):
ar.append('<a href="{}">[{}]</a>'.format(x[i],i+1) )
else:
m = markdown(str(x[i]))
m = re.sub('<p>','', m)
m = re.sub('</p>','', m)
ar.append(m)
return "'"+ ', '.join(ar) + "'"
else:
if re.search('github.com', x):
return '<a href="{}">{}</a>'.format(x,'github')
elif re.search('gitlab.com', x):
return '<a href="{}">{}</a>'.format(x,'gitlab')
else:
return '<a href="{}">{}</a>'.format(x,'link')
def urlify(x):
ar=[]
if type(x) is list:
for i in range(len(x)):
if re.search('github.com', x[i]):
ar.append('<a href="{}">{}</a>'.format(x[i],'github') )
elif re.search('gitlab.com', x[i]):
ar.append('<a href="{}">{}</a>'.format(x[i],'gitlab') )
elif re.match('^http', x[i]):
ar.append('<a href="{}">[{}]</a>'.format(x[i],i+1) )
else:
m = markdown(str(x[i]))
m = re.sub('<p>','', m)
m = re.sub('</p>','', m)
ar.append(m)
return "'"+ ', '.join(ar) + "'"
else:
if re.match('http', str(x)):
return '<a href="{}">{}</a>'.format(x,'demo')
else:
m = markdown(str(x))
m = re.sub('<p>','', m)
m = re.sub('</p>','', m)
return m
# Read YAML file
with open("data.yaml", 'r') as f:
data = yaml.load(f, Loader=yaml.SafeLoader)
# Write to data.js
with open("data.js", 'w') as out:
print ('var osc_data = [', file=out)
for el in data:
print('[', end=' ', file=out)
for fi in fields:
# Check if the field exists (e.g. "Demo" for "Isso")
if fi=='source':
if type(data[el][fi]) is list:
print (source_urlify(data[el][fi]), end=", ", file=out)
else:
print ("'" + source_urlify(data[el][fi]) +"',", end=' ', file=out)
elif fi in data[el]:
if type(data[el][fi]) is list:
print (urlify(data[el][fi]), end=", ", file=out)
else:
print ("'" + urlify(data[el][fi]) +"',", end=' ', file=out)
else:
print ("'?',", end=' ', file=out)
print('],', file=out)
print(']', file=out)
# Add 'cols' variable to data.js
# It contains all column names
print('var cols=[', file=out)
for fi in fields:
print ('{title: "' + fields_dic[fi] + '"}, ', file=out)
print(']', file=out)
print('data.js has been updated')