diff --git a/scalawiki-core/src/main/scala/org/scalawiki/dto/Image.scala b/scalawiki-core/src/main/scala/org/scalawiki/dto/Image.scala index 9a817363..0a7c865a 100644 --- a/scalawiki-core/src/main/scala/org/scalawiki/dto/Image.scala +++ b/scalawiki-core/src/main/scala/org/scalawiki/dto/Image.scala @@ -16,8 +16,12 @@ case class ImageMetadata(data: Map[String, String]) { def date: Option[ZonedDateTime] = data - .get("DateTime") - .flatMap(s => Try(LocalDateTime.parse(s, ImageMetadata.df).atZone(ZoneOffset.UTC)).toOption) + .get("DateTimeOriginal") + .flatMap { s => + val parsed = Try(LocalDateTime.parse(s, ImageMetadata.df).atZone(ZoneOffset.UTC)) + parsed.failed.foreach(println) + parsed.toOption + } } object ImageMetadata { diff --git a/scalawiki-core/src/test/scala/org/scalawiki/dto/ImageSpec.scala b/scalawiki-core/src/test/scala/org/scalawiki/dto/ImageSpec.scala index acd29373..d9732738 100644 --- a/scalawiki-core/src/test/scala/org/scalawiki/dto/ImageSpec.scala +++ b/scalawiki-core/src/test/scala/org/scalawiki/dto/ImageSpec.scala @@ -1,6 +1,6 @@ package org.scalawiki.dto -import org.scalawiki.dto.ImageSpec.{makeTemplate, withCategories, withSpecialNominations} +import org.scalawiki.dto.ImageSpec._ import org.scalawiki.dto.markup.Template import org.specs2.mutable.Specification @@ -86,6 +86,13 @@ class ImageSpec extends Specification { .get image2.specialNominations === Set.empty + + val page3 = Page("File:Image.jpg").copy(revisions = Seq(Revision.one(withSpecialNomination2))) + val image3 = Image + .fromPageRevision(page3, Some("Monument"), Set("WLM2023-UA-interior")) + .get + + image3.specialNominations === Set("WLM2023-UA-interior") } "resize" should { @@ -172,4 +179,24 @@ object ImageSpec { |[[Category:Bishop's house in Lutsk castle]] |[[Category:Uploaded via Campaign:wlm-ua]] |""".stripMargin + + private val withSpecialNomination2 = """=={{int:filedesc}}== + |{{Information + ||description={{uk|1=Прибутковий будинок, [[:uk:Дніпро (місто)|Дніпро]], вул. Троїцька (Червона), 8}}{{Monument Ukraine|12-101-0443}}[[Category:Wiki Loves Monuments in Ukraine 2023 - Quantity]]{{WLM2023-UA-interior}} + ||date=2023-07-18 08:59:48 + ||source={{own}} + ||author=[[User:Olebesedin|Olebesedin]] + ||permission= + ||other versions= + |}} + |{{Location|48.462144|35.042819}} + | + |=={{int:license-header}}== + |{{self|cc-by-sa-4.0}} + | + |{{Wiki Loves Monuments 2023|ua}} + | + |[[Category:8 Troitska Street, Dnipro]] + |[[Category:Uploaded via Campaign:wlm-ua]] + |""".stripMargin } diff --git a/scalawiki-wlx/src/main/resources/wlm_ua.conf b/scalawiki-wlx/src/main/resources/wlm_ua.conf index 6b3e9fde..579b44d8 100644 --- a/scalawiki-wlx/src/main/resources/wlm_ua.conf +++ b/scalawiki-wlx/src/main/resources/wlm_ua.conf @@ -3,7 +3,7 @@ "country": "Ukraine", - "year": 2016, + "year": 2023, "campaign": "wlm-ua", diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala index 5045c0b0..039451b6 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala @@ -105,11 +105,13 @@ object Contest { .find(country => country.name == countryStr || country.code == countryStr) ) yield new Contest( - contestType, - country, - year, + contestType = contestType, + country = country, + year = year, uploadConfigs = Seq(uploadConfig), - config = Some(config) + config = Some(config), + specialNominations = SpecialNomination.nominations + .filter(n => n.years.contains(year)) ) } diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/MonumentDbStat.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/MonumentDbStat.scala index 6b48b7e8..6cc67b95 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/MonumentDbStat.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/MonumentDbStat.scala @@ -21,7 +21,7 @@ class MonumentDbStat { "article" ) - def getStat(monumentDbs: Seq[MonumentDB]) = { + def getStat(monumentDbs: Seq[MonumentDB]): String = { val title = monumentDbs.head.contest.contestType.name + " database statistics" @@ -54,7 +54,7 @@ class MonumentDbStat { ) } - val table = new Table(columns, data, title) + val table = Table(columns, data, title) table.asWiki } diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/RecentlyTaken.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/RecentlyTaken.scala new file mode 100644 index 00000000..e2dec5a3 --- /dev/null +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/RecentlyTaken.scala @@ -0,0 +1,32 @@ +package org.scalawiki.wlx.stat.reports +import org.scalawiki.dto.markup.Table +import org.scalawiki.wlx.stat.ContestStat + +import java.time.ZonedDateTime + +class RecentlyTaken(val stat: ContestStat) extends Reporter { + + private val jun30 = ZonedDateTime.parse(s"${contest.year}-06-30T23:59:59Z") + + override def name: String = "RecentlyTaken" + + override def table: Table = { + val data = stat.currentYearImageDb + .map { db => + val images = db.images.filter { i => + i.metadata.exists(_.date.exists(_.isAfter(jun30))) && + !i.specialNominations.contains(s"WLM${contest.year}-UA-interior") + } + images.map { i => + List( + s"[[:${i.title}]]", + s"[[User:${i.author.getOrElse("")}|${i.author.getOrElse("")}]]", + i.metadata.flatMap(_.date.map(_.toString)).getOrElse("") + ) + + } + } + .getOrElse(Nil) + Table(Seq("photo", "author", "date"), data) + } +} diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Reporter.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Reporter.scala index 4db7adae..1c469741 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Reporter.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/Reporter.scala @@ -2,17 +2,20 @@ package org.scalawiki.wlx.stat.reports import org.scalawiki.MwBot import org.scalawiki.dto.markup.Table +import org.scalawiki.wlx.dto.Contest import org.scalawiki.wlx.stat.ContestStat +import scala.concurrent.Future + trait Reporter { def stat: ContestStat - def contest = stat.contest + def contest: Contest = stat.contest def name: String - def category = contest.name + def category: String = contest.name def page = s"Commons:$category/$name" @@ -26,7 +29,7 @@ trait Reporter { header + table.asWiki + categoryText } - def updateWiki(bot: MwBot) = { + def updateWiki(bot: MwBot): Future[Any] = { bot.page(page).edit(asText, Some("updating")) } diff --git a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala index 9ff26b31..f501fb2f 100644 --- a/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala +++ b/scalawiki-wlx/src/main/scala/org/scalawiki/wlx/stat/reports/ReporterRegistry.scala @@ -15,11 +15,11 @@ class ReporterRegistry(stat: ContestStat, cfg: StatConfig)(implicit import org.scalawiki.wlx.stat.reports.{ReporterRegistry => RR} - val contest = stat.contest - val monumentDb = stat.monumentDb - val currentYearImageDb = stat.currentYearImageDb - val totalImageDb = stat.totalImageDb - val commons = MwBot.fromHost(MwBot.commons) + private val contest = stat.contest + private val monumentDb = stat.monumentDb + private val currentYearImageDb = stat.currentYearImageDb + private val totalImageDb = stat.totalImageDb + private val commons = MwBot.fromHost(MwBot.commons) def monumentDbStat: Option[String] = stat.monumentDb.map(RR.monumentDbStat) @@ -45,6 +45,7 @@ class ReporterRegistry(stat: ContestStat, cfg: StatConfig)(implicit */ def currentYear(): Unit = { for (imageDb <- currentYearImageDb) { + new RecentlyTaken(stat).updateWiki(commons) if (cfg.regionalGallery && stat.totalImageDb.isEmpty) { Output.byRegion(monumentDb.get, imageDb)