<commit_before>package org.scalawiki.wlx

import org.scalawiki.dto.{Namespace, Page}
import org.scalawiki.dto.cmd.Action
import org.scalawiki.dto.cmd.query.Query
import org.scalawiki.dto.cmd.query.list._
import org.scalawiki.wlx.dto.{Contest, ContestType}
import org.scalawiki.{MwBot, WithBot}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

object CampaignList extends WithBot {

  override def host = MwBot.commons

  def categoryMembers(parent: String): Action = {
    Action(Query(ListParam(CategoryMembers(
      CmTitle(parent), CmNamespace(Seq(Namespace.CATEGORY)), CmLimit("max"))
    )))
  }

  def categoriesMembers(categories: Seq[String]): Future[Seq[Seq[Page]]] = {
    val queries = categories.map(categoryMembers)
    Future.sequence(queries.map(bot.run(_)))
  }

  def titles(pages: Seq[Seq[Page]]) = pages.flatten.map(_.title)

  def getYears(contestType: ContestType): Future[Seq[Contest]] = {
    bot.run(categoryMembers(contestType.imagesCategory)).map { cats =>
      cats.flatMap(cat => CountryParser.fromCategoryName(cat.title))
    }
  }

  def main(args: Array[String]): Unit = {
    val types = ContestType.all
    val contestCats = types.map(_.imagesCategory)

    for (yearCats <- categoriesMembers(contestCats)) {
      val imageCats = titles(yearCats).filter(CountryParser.isContestCategory)
      for (campaignCats <- categoriesMembers(imageCats)) {
        titles(campaignCats).foreach(println)
      }
    }
  }
}<commit_msg>extract contestsFromCategory and rewrite in for comprehensions<commit_after>package org.scalawiki.wlx

import org.scalawiki.dto.{Namespace, Page}
import org.scalawiki.dto.cmd.Action
import org.scalawiki.dto.cmd.query.Query
import org.scalawiki.dto.cmd.query.list._
import org.scalawiki.wlx.dto.{Contest, ContestType}
import org.scalawiki.{MwBot, WithBot}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

object CampaignList extends WithBot {

  override def host = MwBot.commons

  def categoryMembers(parent: String): Action = {
    Action(Query(ListParam(CategoryMembers(
      CmTitle(parent), CmNamespace(Seq(Namespace.CATEGORY)), CmLimit("max"))
    )))
  }

  def titles(pages: Seq[Seq[Page]]): Seq[String] = pages.flatten.map(_.title)

  def getYears(contestType: ContestType): Future[Seq[Contest]] =
    contestsFromCategory(contestType.imagesCategory)

  def contestsFromCategory(parent: String): Future[Seq[Contest]] = {
    for (cats <- bot.run(categoryMembers(parent))) yield
      for (cat <- cats;
           contest <- CountryParser.fromCategoryName(cat.title)
      ) yield contest
  }

  def categoriesMembers(categories: Seq[String]): Future[Seq[Seq[Page]]] = {
    val queries = categories.map(categoryMembers)
    Future.sequence(queries.map(bot.run(_)))
  }


  def main(args: Array[String]): Unit = {
    val types = ContestType.all
    val contestCats = types.map(_.imagesCategory)

    for (yearCats <- categoriesMembers(contestCats)) {
      val imageCats = titles(yearCats).filter(CountryParser.isContestCategory)
      for (campaignCats <- categoriesMembers(imageCats)) {
        titles(campaignCats).foreach(println)
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.1244153414405987, 'fraction_numerical': 0.0, 'mean_word_length': 4.502572898799314, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4332843', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1024, 'n_words': 173}