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.

41 lines
827B

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