badi-date.pl 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Getopt::Long;
  5. use JSON;
  6. use POSIX;
  7. use Data::Dumper;
  8. # Check for gum
  9. if (!-x "/usr/bin/gum") {
  10. print STDERR "Error: gum is not installed. Please install it to continue.\n";
  11. print STDERR "Installation instructions for popular Linux distributions:\n";
  12. print STDERR " Ubuntu/Debian: sudo apt install gum\n";
  13. print STDERR " Fedora: sudo dnf install gum\n";
  14. print STDERR " Arch Linux: sudo pacman -S gum\n";
  15. print STDERR " CentOS/RHEL: sudo yum install gum\n";
  16. print STDERR " openSUSE: sudo zypper install gum\n";
  17. print STDERR " Gentoo: sudo emerge gum\n";
  18. print STDERR " Alpine: sudo apk add gum\n";
  19. print STDERR " NixOS: nix-env -iA nixpkgs.gum\n";
  20. exit 1;
  21. }
  22. my $today;
  23. my $date;
  24. my $progress;
  25. GetOptions(
  26. 'today' => \$today,
  27. 'date=s' => \$date,
  28. 'progress' => \$progress,
  29. );
  30. if ($today) {
  31. my $json_string = `curl -s http://localhost:1844/today?timezoneId=America/New_York`;
  32. my $json = decode_json($json_string);
  33. my $message = $json->{'message'};
  34. $message =~ s/<[^>]*>//g;
  35. system("gum style --foreground 212 '$message'");
  36. }
  37. elsif ($date) {
  38. my ($year, $month, $day) = split('-', $date);
  39. my $json_string = `curl -s "http://localhost:1844/date?year=$year&month=$month&day=$day&timezoneId=America/New_York"`;
  40. my $json = decode_json($json_string);
  41. my $message = $json->{'message'};
  42. $message =~ s/<[^>]*>//g;
  43. system("gum style --foreground 212 '$message'");
  44. }
  45. elsif ($progress) {
  46. my $json_string = `curl -s http://localhost:1844/today?timezoneId=America/New_York`;
  47. my $json = decode_json($json_string);
  48. my $badi_date = $json->{'badi_date'};
  49. my $day_of_month = $badi_date->{'day'};
  50. my $month_of_year = $badi_date->{'month'};
  51. my $year_of_vahid = ($badi_date->{'year'} - 1) % 19 + 1;
  52. my $vahid_of_kull_i_shay = floor(($badi_date->{'year'} - 1) / 19) + 1;
  53. my $year_of_kull_i_shay = $badi_date->{'year'};
  54. my $day_progress = "█" x $day_of_month . " " x (19 - $day_of_month);
  55. my $month_progress = "█" x $month_of_year . " " x (19 - $month_of_year);
  56. my $vahid_progress = "█" x $year_of_vahid . " " x (19 - $year_of_vahid);
  57. my $kull_i_shay_vahid_progress = "█" x $vahid_of_kull_i_shay . " " x (19 - $vahid_of_kull_i_shay);
  58. my $kull_i_shay_year_progress = "█" x int($year_of_kull_i_shay / 361 * 19) . " " x (19 - int($year_of_kull_i_shay / 361 * 19));
  59. system("gum style --foreground 212 'Day of Month: [$day_progress] $day_of_month/19'");
  60. system("gum style --foreground 212 'Month of Year: [$month_progress] $month_of_year/19'");
  61. system("gum style --foreground 212 'Year of Vahid: [$vahid_progress] $year_of_vahid/19'");
  62. system("gum style --foreground 212 'Vahid of Kull-i-Shay: [$kull_i_shay_vahid_progress] $vahid_of_kull_i_shay/19'");
  63. system("gum style --foreground 212 'Year of Kull-i-Shay: [$kull_i_shay_year_progress] $year_of_kull_i_shay/361'");
  64. }
  65. else {
  66. # Default behavior: display today's date
  67. # Or show help
  68. }
  69. 1;