-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
204 lines (165 loc) · 6.13 KB
/
cli.py
File metadata and controls
204 lines (165 loc) · 6.13 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import json
import os
import sys
import click
import fastjsonschema
from snakemd import Document
from snakemd.generator import InlineText
ALLOWED_TYPE = [
'B2B',
'B2C',
'C2C',
'D2C',
'Other',
]
ALLOWED_MARKET = [
'Health',
'Food',
'Automotive',
'Fintech',
'Energy',
'AI',
'Biotech',
'Ecommerce',
'Software',
'Hardware',
'Service',
'Insurance',
'Other',
# TODO: in progress (crete issues if missing your market)
]
JSONSCHEME_COMPILE = fastjsonschema.compile(
definition={
'$schema': 'https://json-schema.org/draft/2019-09/schema',
'type': 'object',
'properties': {
'name': {'type': 'string'},
'repository_organization_url': {'type': 'string', 'format': 'uri'},
'site_url': {'type': 'string', 'format': 'uri'},
'description': {'type': 'string', 'minLength': 5, 'maxLength': 254},
'type': {'type': 'string', 'enum': ALLOWED_TYPE},
'market': {'type': 'string', 'enum': ALLOWED_MARKET},
'foundation_year': {
'type': 'string',
'pattern': '^[2][0-0][1-2][0-9]$'
},
'tags': {
'type': 'array',
'minItems': 1,
'maxItems': 20,
'uniqueItems': True,
'items': {
'type': 'string',
'maxLength': 24
}
}
},
'required': [
'name',
'site_url',
'type',
'market',
'tags',
],
'additionalProperties': False
}
)
def abspath(*args, os_path=True, separator='/'):
path = separator.join(args)
if os_path is True:
from pathlib import Path
return str(Path(path))
return path
def json_validate(filename: str):
if not os.path.exists(filename):
raise FileNotFoundError(filename=filename)
with open(filename) as fh:
content = json.load(fh)
return JSONSCHEME_COMPILE(content)
def check(loaded: list):
values = []
for name, filename in loaded:
print(f'Check: {name}')
values.append(json_validate(filename))
return values
def build(data):
def _header(doc, data):
doc.add_header('Italia Opensource')
doc.add_paragraph(f"""
<img src='https://img.shields.io/badge/startups-{len(data)}-green'>
<img src='https://img.shields.io/github/last-commit/italia-opensource/awesome-italia-startups/main'>
""")
doc.add_paragraph(
'Awesome Italia Startups is a list of italian startups.')
doc.add_paragraph(
'The repository intends to give visibility to startups and stimulate the community to contribute to growing the ecosystem.')
doc.add_paragraph(
'Please read the contribution guidelines before opening a pull request or contributing to this repository') \
.insert_link('contribution guidelines', 'https://github.com/italia-opensource/awesome-italia-startups/blob/main/CONTRIBUTING.md')
doc.add_header('Mantained by', level=3)
doc.add_paragraph("""- **[Fabrizio Cafolla](https://github.com/FabrizioCafolla)**
<a href="https://www.buymeacoffee.com/fabriziocafolla" target="_blank"><img align="right" src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 30px !important; width: 150px !important" ></a>""")
def _projects(doc, data):
doc.add_header('Startups', level=3)
doc.add_header('Website view', level=4)
doc.add_paragraph(
'italia-opensource.github.io').insert_link('italia-opensource.github.io', 'https://italia-opensource.github.io/awesome-italia-startups/')
doc.add_header('List', level=4)
table_content_project = []
startups_name = []
for item in data:
name = item.get('name')
if name in startups_name:
raise Exception(f'Startup {name} already exist')
description = item.get('description', '')
if len(description) > 59:
description = description[0:60] + ' [..]'
table_content_project.append([
InlineText(name, url=item.get('site_url')),
item.get('type'),
item.get('market'),
', '.join(item['tags']),
description
])
startups_name.append(name)
doc.add_table(
['Name', 'Type', 'Market', 'Tags', 'Description'],
table_content_project
)
def _contributors(doc):
doc.add_header('Contributors', level=3)
doc.add_paragraph("""
<a href="https://github.com/italia-opensource/awesome-italia-startups/graphs/contributors">
<img src="https://contrib.rocks/image?repo=italia-opensource/awesome-italia-startups" />
</a>
""")
doc.add_header('License', level=3)
doc.add_paragraph(
'The project is made available under the GPL-3.0 license. See the `LICENSE` file for more information.')
doc = Document('README')
_header(doc, data)
_projects(doc, data)
_contributors(doc)
doc.output_page()
@click.command()
@click.option('--render', default=False, help='Make data render', is_flag=True)
@click.option('--output', default=False, help='Make data output', is_flag=True)
def main(render, output):
data = os.listdir(abspath(os.path.dirname(
os.path.abspath(__file__)), 'data'))
loaded = []
for project in data:
if not project.endswith('.json'):
raise Exception(f'File {project} is not json')
item = (project.replace('.json', ''), abspath(
os.path.dirname(os.path.abspath(__file__)), 'data', project))
loaded.append(item)
loaded = sorted(loaded, key=lambda tup: tup[0])
parsed = check(loaded)
if render:
build(parsed)
if output:
with open('website/src/data/outputs.json', 'w+') as file_output:
file_output.write(json.dumps({'data': parsed}))
if __name__ == '__main__':
sys.exit(main())