2021-01-29 23:01:10 +00:00
|
|
|
import csv
|
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
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
To date, **{n_apps}** apps/tools covered, divided in **{n_cats}** categories.
|
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:42:13 +00:00
|
|
|
If you have any suggestion or want your project listed here, drop me an email at `toolleeo@gmail.com`.
|
2017-04-20 22:21:42 +00:00
|
|
|
"""
|
|
|
|
|
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:
|
|
|
|
data.append(item)
|
|
|
|
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'])
|
|
|
|
st = '* [{}]({}) - {}'.format(app['name'], app['url'], descr)
|
2017-07-10 20:29:50 +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']))
|
|
|
|
apps_in_cat = [a for a in apps if a['category'] == c]
|
|
|
|
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
|
|
|
|
2021-01-29 23:01:10 +00:00
|
|
|
def fmt_categories(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']))
|
2017-07-09 22:10:28 +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
|
2021-01-29 23:42:13 +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):
|
|
|
|
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()
|