yearprogress.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. # python recreation of https://twitter.com/year_progress?lang=en
  3. from datetime import date
  4. import datetime
  5. #https://www.geeksforgeeks.org/python-program-to-find-number-of-days-between-two-given-dates/
  6. def numOfDays(date1, date2):
  7. if date2 > date1:
  8. return (date2 - date1).days
  9. else:
  10. return (date1 - date2).days
  11. def main():
  12. today = datetime.date.today()
  13. year = int(today.strftime("%Y"))
  14. currentYear = date(year, 1, 1)
  15. nextYear = date(year+1, 1, 1)
  16. days = numOfDays(currentYear, nextYear)
  17. daysLeft = numOfDays(today, nextYear)
  18. daysPassed = days - daysLeft
  19. percent = daysPassed/days
  20. roundedPercent = int(round(percent * 100, 0))
  21. bars = 15
  22. filled = int(round(percent * bars, 0))
  23. fill = "▓"
  24. unfill = "░"
  25. count = 0
  26. print(f"{currentYear.year} is {roundedPercent}% complete.")
  27. while True:
  28. count = count + 1
  29. if count <= filled:
  30. print(fill, end="")
  31. elif count <= bars:
  32. print(unfill, end="")
  33. else:
  34. break
  35. if __name__ == "__main__":
  36. main()