Add what's hot
This commit is contained in:
parent
3091d4759b
commit
80261ff066
2 changed files with 62 additions and 0 deletions
1
README
Normal file
1
README
Normal file
|
@ -0,0 +1 @@
|
|||
whats_hot.py is wat je wil
|
61
whats_hot.py
Executable file
61
whats_hot.py
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
from datetime import date
|
||||
|
||||
|
||||
MONTHS = "JFMAMJJASOND"
|
||||
LEVEL_SYMBOLS = " ░▓█"
|
||||
|
||||
current_month_0 = date.today().month - 1
|
||||
|
||||
|
||||
def score(item):
|
||||
name, months = item
|
||||
# Sort by score of current month, then by name
|
||||
return (months[current_month_0], name)
|
||||
|
||||
|
||||
def ranked_data(data):
|
||||
return list(sorted(data.items(), key=score))
|
||||
|
||||
|
||||
def color_for_month(month, text):
|
||||
if month == current_month_0:
|
||||
return text
|
||||
return f"\033[90m{text}\033[0m"
|
||||
|
||||
|
||||
def format(item):
|
||||
name, months = item
|
||||
|
||||
return "{} {}".format(
|
||||
" ".join(color_for_month(month, LEVEL_SYMBOLS[level]) for month, level in enumerate(months)),
|
||||
name
|
||||
)
|
||||
|
||||
|
||||
def month_header():
|
||||
return " ".join(color_for_month(i, m) for i, m in enumerate(MONTHS))
|
||||
|
||||
|
||||
def main():
|
||||
with open("./fruit.json") as f_in:
|
||||
fruit = json.load(f_in)
|
||||
with open("./groenten.json") as f_in:
|
||||
groenten = json.load(f_in)
|
||||
|
||||
print("Fruit")
|
||||
print(month_header())
|
||||
for item in ranked_data(fruit):
|
||||
print(format(item))
|
||||
|
||||
print()
|
||||
print("Groenten")
|
||||
print(month_header())
|
||||
for item in ranked_data(groenten):
|
||||
print(format(item))
|
||||
print(month_header())
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue