A variety of simple automation scripts and enhancements to Sway and i3.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
980B

  1. #!/usr/bin/perl
  2. # TODO: If gammastep is already running, allow location to update
  3. use strict;
  4. use warnings;
  5. use LWP::UserAgent;
  6. use JSON::XS;
  7. my $location = "https://papillon.john.me.tz/data/location.json";
  8. my $lat_lon = fetch_lat_lon($location);
  9. my $pid = fork;
  10. unless ($pid) {
  11. open STDIN, '/dev/null';
  12. open STDOUT, '>>/dev/null';
  13. open STDERR, '>>/dev/null';
  14. `gammastep -l $lat_lon`;
  15. }
  16. sub fetch_lat_lon
  17. {
  18. my ($location) = shift;
  19. my $ua = LWP::UserAgent->new();
  20. my $json = JSON::XS->new();
  21. my $raw = $ua->get($location)->content();
  22. if (defined $raw) {
  23. print($raw."\n");
  24. my $decoded = $json->decode($raw);
  25. if (defined $decoded->{lat} && defined $decoded->{lon}) {
  26. return "$decoded->{lat}:$decoded->{lon}";
  27. }
  28. print $decoded->{lat};
  29. }
  30. sleep 5;
  31. return fetch_lat_lon($ua, $json, $location);
  32. }
  33. exit;