2021-01-29 23:01:10 +00:00
|
|
|
import csv
|
2023-08-28 17:50:09 +00:00
|
|
|
import string
|
|
|
|
|
2017-02-27 23:59:32 +00:00
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
summary_template = """
|
2017-04-20 22:21:42 +00:00
|
|
|
# Summary
|
2017-02-27 23:59:32 +00:00
|
|
|
|
2023-08-28 17:09:42 +00:00
|
|
|
* Apps/tools covered: **{n_apps}**
|
|
|
|
* Number of categories: **{n_cats}**.
|
2017-04-20 22:21:42 +00:00
|
|
|
|
|
|
|
# Index
|
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
{cats}
|
2017-07-09 22:18:09 +00:00
|
|
|
|
2017-04-20 22:21:42 +00:00
|
|
|
Some links to [related resources](#resources).
|
|
|
|
"""
|
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
resources_template = """
|
2017-07-10 20:10:47 +00:00
|
|
|
# <a name="resources"></a>Related resources
|
2017-07-10 19:53:56 +00:00
|
|
|
|
|
|
|
A list of some online resoures that contribute interesting links to apps and info.
|
|
|
|
|
|
|
|
{}
|
|
|
|
"""
|
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
|
|
|
|
def load_csv(file_name):
|
|
|
|
with open(file_name, 'r') as infile:
|
|
|
|
csv_reader = csv.DictReader(infile, delimiter=',')
|
|
|
|
fields = csv_reader.fieldnames
|
|
|
|
data = []
|
|
|
|
for item in csv_reader:
|
2023-03-24 14:08:36 +00:00
|
|
|
data.append(item)
|
2021-01-29 23:01:10 +00:00
|
|
|
return fields, data
|
|
|
|
|
|
|
|
|
2017-04-20 22:21:42 +00:00
|
|
|
def fmt_app(app):
|
2021-01-29 23:01:10 +00:00
|
|
|
descr = ''.join(c if c != '\n' else ' ' for c in app['description'])
|
2023-03-23 13:40:03 +00:00
|
|
|
if app['homepage'] != '':
|
2023-05-26 10:32:29 +00:00
|
|
|
st = '* [{}]({}) - {}'.format(app['name'], app['homepage'], descr)
|
2023-03-23 13:40:03 +00:00
|
|
|
elif app['git'] != '':
|
2023-03-30 10:14:55 +00:00
|
|
|
st = '* [{}]({}) - {}'.format(app['name'], app['git'], descr)
|
2021-05-12 08:48:19 +00:00
|
|
|
else:
|
|
|
|
st = '* {} - {}'.format(app['name'], descr)
|
2023-03-24 14:08:36 +00:00
|
|
|
return st
|
2017-04-20 22:21:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def print_apps(cats, apps):
|
2021-01-29 23:01:10 +00:00
|
|
|
for c in cats:
|
|
|
|
cat_item = cats[c]
|
|
|
|
print('## <a name="{}"></a>{}\n'.format(c, cat_item['name']))
|
2022-10-16 19:39:01 +00:00
|
|
|
if cat_item['description'] != '':
|
|
|
|
print(f"{cat_item['description']}.\n")
|
2021-01-29 23:01:10 +00:00
|
|
|
apps_in_cat = [a for a in apps if a['category'] == c]
|
2023-03-24 14:08:36 +00:00
|
|
|
apps_in_cat = sorted(apps_in_cat, key=lambda i: i['name'].upper())
|
2021-01-29 23:01:10 +00:00
|
|
|
for app in apps_in_cat:
|
2017-04-20 22:21:42 +00:00
|
|
|
print(fmt_app(app))
|
2021-01-29 23:01:10 +00:00
|
|
|
print()
|
2017-04-20 22:21:42 +00:00
|
|
|
|
2023-03-24 14:08:36 +00:00
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
def fmt_categories(cats):
|
2023-08-28 17:50:09 +00:00
|
|
|
group_by_letters = {x: [] for x in string.ascii_uppercase}
|
|
|
|
for c in cats:
|
|
|
|
initial = cats[c]['name'][0].upper()
|
|
|
|
group_by_letters[initial].append(c)
|
|
|
|
# print(group_by_letters)
|
|
|
|
strings_by_letters = {x: [] for x in string.ascii_uppercase}
|
|
|
|
for g in group_by_letters:
|
|
|
|
strings_by_letters[g] = [f"[{cats[c]['name']}](#{c}) ({cats[c]['count']})" for c in group_by_letters[g]]
|
|
|
|
lines_by_letters = {x: [] for x in string.ascii_uppercase}
|
|
|
|
# print(strings_by_letters)
|
|
|
|
for g in group_by_letters:
|
|
|
|
lines_by_letters[g] = ', '.join(strings_by_letters[g])
|
|
|
|
lines_to_join = ['* ' + lines_by_letters[key] for key in lines_by_letters if len(lines_by_letters[key])]
|
|
|
|
# print(lines_by_letters)
|
|
|
|
# print(lines_to_join)
|
|
|
|
return '\n'.join(lines_to_join)
|
|
|
|
|
|
|
|
|
|
|
|
def fmt_categories_old(cats):
|
2017-04-20 22:21:42 +00:00
|
|
|
st = []
|
2021-01-29 23:01:10 +00:00
|
|
|
for c in cats:
|
|
|
|
st.append("[{}](#{}) ({})".format(cats[c]['name'], c, cats[c]['count']))
|
2023-08-28 17:13:07 +00:00
|
|
|
return ', '.join(st)
|
2017-02-27 23:59:32 +00:00
|
|
|
|
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
def count_apps(apps, categories):
|
|
|
|
for c in categories:
|
|
|
|
categories[c]['count'] = 0
|
|
|
|
for a in apps:
|
|
|
|
c = a['category']
|
|
|
|
if c in categories:
|
|
|
|
categories[c]['count'] += 1
|
2023-03-24 14:08:36 +00:00
|
|
|
# else:
|
|
|
|
# print('Category {} does not have any app'.format(c))
|
2021-01-29 23:01:10 +00:00
|
|
|
return categories
|
|
|
|
|
2017-03-27 20:10:11 +00:00
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
def categories_list_to_dict(category_list):
|
2023-08-28 17:10:06 +00:00
|
|
|
category_list = sorted(category_list, key=lambda d: d['name'])
|
2021-01-29 23:01:10 +00:00
|
|
|
d = {}
|
|
|
|
for c in category_list:
|
|
|
|
d[c['label']] = {'name': c['name'], 'description': c['description']}
|
|
|
|
return d
|
2017-04-20 22:21:42 +00:00
|
|
|
|
2017-07-10 19:53:56 +00:00
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
def main():
|
2021-02-01 08:20:15 +00:00
|
|
|
_, apps = load_csv('data/apps.csv')
|
|
|
|
_, categories = load_csv('data/categories.csv')
|
|
|
|
_, resources = load_csv('data/resources.csv')
|
2021-01-29 23:01:10 +00:00
|
|
|
categories = categories_list_to_dict(categories)
|
|
|
|
categories = count_apps(apps, categories)
|
|
|
|
|
2017-07-10 19:53:56 +00:00
|
|
|
md_res = ''
|
2021-01-29 23:01:10 +00:00
|
|
|
for r in resources:
|
2017-07-10 20:00:50 +00:00
|
|
|
md_res += '[{}]({}) - {}\n\n'.format(r['title'], r['url'], r['description'])
|
2017-07-10 19:53:56 +00:00
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
print(summary_template.format(n_apps=len(apps), n_cats=len(categories), cats=fmt_categories(categories)))
|
|
|
|
print_apps(categories, apps)
|
|
|
|
print(resources_template.format(md_res))
|
|
|
|
|
2017-07-10 19:53:56 +00:00
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|