Last active
October 21, 2022 21:06
-
-
Save kubukoz/6e958fedd0296664f91bc7159c4c9e31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> using scala "3.1.2" | |
//> using plugin "org.polyvariant:::better-tostring:0.3.15" | |
//> using lib "com.monovore::decline-effect:2.3.0" | |
//> using lib "org.typelevel::cats-effect:3.3.14" | |
//> using lib "co.fs2::fs2-io:3.2.10" | |
import cats.effect.IOApp | |
import cats.effect.IO | |
import com.monovore.decline.effect.CommandIOApp | |
import cats.effect.ExitCode | |
import com.monovore.decline.Opts | |
import cats.implicits._ | |
import fs2.io.file.Files | |
import com.monovore.decline.Argument | |
import fs2.io.file.Path | |
import sys.process._ | |
object FixTimezone extends CommandIOApp("fix-timezone", "Fix timezone") { | |
implicit val pathArg: Argument[Path] = | |
Argument[java.nio.file.Path].map(Path.fromNioPath(_)) | |
def main: Opts[IO[ExitCode]] = | |
Opts.argument[Path]("directory").map(fixPath(_).as(ExitCode.Success)) | |
def hasGPS(path: Path): IO[Boolean] = IO.interruptibleMany { | |
s"exiftool $path".!!.contains("GPS") | |
} | |
def shiftTimezone(path: Path): IO[Unit] = IO.interruptibleMany { | |
s"jhead -ta+1 $path".!! | |
}.void | |
def fixPath(path: Path): IO[Unit] = { | |
Files[IO] | |
.list(path) | |
.as(1) | |
.foldMonoid | |
.evalMap(c => IO.println(s"File count: $c")) | |
.drain ++ | |
Files[IO] | |
.list(path) | |
.evalFilterNotAsync(maxConcurrent = 10)(hasGPS) | |
.evalMap(p => shiftTimezone(p).as(p)) | |
.debug("Fixed " + _) | |
}.compile.drain | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment