Skip to content

Commit

Permalink
mensa -> canteen
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Jul 29, 2023
1 parent b0ba83a commit e01ecf3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 51 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# MensaBot - A bot that reminds you of your food in your mensa
# MensaBot - A bot that reminds you of your food in your canteen

This bot sends you a daily reminder of the current food in your canteen.
This bot sends you a daily reminder of the current food in your canteen (dt. mensa).
Additionally, you can use commands to request the listing directly.

## Features

* Schedule daily posts about the food in your mensa
* Schedule daily posts about the food in your canteen
* Request summary of food in your mensa (at the current date)
* Change display name per room
* Simple rights management (only configured admins can interact with the bot)

![Functions](.docs/imgs/functions.png)

### Supported APIs
This bot aims to support multiple mensa APIs. For details about the implementation, take a look at [Development](#development).
This bot aims to support multiple canteen APIs. For details about the implementation, take a look at [Development](#development).

Currently the bot supports the following mensa:
Currently, the bot supports the following mensa:
* [Studierendenwerk Karlsruhe](https://www.sw-ka.de/en/hochschulgastronomie/speiseplan/)

## Setup
Expand All @@ -33,12 +33,12 @@ Currently the bot supports the following mensa:

* An admin can invite the bot to an *unencrypted* room. If the room has enabled encryption or if the invite was not sent by an admin, the bot ignores it (without logging it)
* After the bot has joined use `!mensa help` to get an overview about the features of the bot (remember: the bot only respond to admin users)
* In order to get daily notifications about the food in your mensa, simply use `!mensa subscribe`. This command will print the room id of the current room into the channel. Add this channel to the
* In order to get daily notifications about the food in your canteen, simply use `!mensa subscribe`. This command will print the room id of the current room into the channel. Add this channel to the
list in the config and restart the bot.

## Development

Join our discussion at our matrix channel [#mensa-bot:fuchss.org](https://matrix.to/#/#mensa-bot:fuchss.org)

* The basic functionality (commands) are located in [Main.kt](src/main/kotlin/org/fuchss/matrix/mensa/Main.kt). There you can also find the main method of the program.
* Every mensa that shall be considered has to implement the `MensaAPI`. Currently, there is only one implementation for the [sw-ka.de interface](https://sw-ka.de).
* Every canteen that shall be considered has to implement the `CanteenAPI`. Currently, there is only one implementation for the [sw-ka.de interface](https://sw-ka.de).
4 changes: 2 additions & 2 deletions src/main/kotlin/org/fuchss/matrix/mensa/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import net.folivo.trixnity.core.model.events.Event
import net.folivo.trixnity.core.model.events.m.room.EncryptedEventContent
import net.folivo.trixnity.core.model.events.m.room.RoomMessageEventContent
import okio.Path.Companion.toOkioPath
import org.fuchss.matrix.mensa.api.MensaAPI
import org.fuchss.matrix.mensa.api.CanteenAPI
import org.fuchss.matrix.mensa.swka.SWKAMensa
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand All @@ -26,7 +26,7 @@ import kotlin.random.Random
import kotlin.time.Duration.Companion.days

private val logger: Logger = LoggerFactory.getLogger(MatrixBot::class.java)
private val mensa: MensaAPI = SWKAMensa()
private val mensa: CanteenAPI = SWKAMensa()

fun main() {
runBlocking {
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/org/fuchss/matrix/mensa/api/Canteen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.fuchss.matrix.mensa.api

/**
* This class represents a canteen with food.
* @param[id] the unique id of the canteen
* @param[name] a nice readable name of the canteen
*/
data class Canteen(
val id: String,
val name: String
)
21 changes: 21 additions & 0 deletions src/main/kotlin/org/fuchss/matrix/mensa/api/CanteenAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.fuchss.matrix.mensa.api

import kotlinx.datetime.Clock
import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlinx.datetime.todayIn

/**
* This interface defines the minimum functionality that a canteen provides.
*/
interface CanteenAPI {
suspend fun foodToday() = foodAtDate(Clock.System.todayIn(TimeZone.currentSystemDefault()))

/**
* Retrieve foods of different canteens at a certain date.
* @param[date] the date to consider
* @return a map that contains canteens with food mapped to their lines at a certain day
* (remember: the key (canteen) may contain more information than the value (list of canteen lines))
*/
suspend fun foodAtDate(date: LocalDate): Map<Canteen, List<CanteenLine>>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.fuchss.matrix.mensa.api

/**
* This class defines a mensa line that serves food.
* This class defines a canteen line that serves food.
* @param[name] the name of the line
* @param[meals] the food the line serves
*/
data class MensaLine(val name: String, val meals: List<Meal>)
data class CanteenLine(val name: String, val meals: List<Meal>)
11 changes: 0 additions & 11 deletions src/main/kotlin/org/fuchss/matrix/mensa/api/Mensa.kt

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/kotlin/org/fuchss/matrix/mensa/api/MensaAPI.kt

This file was deleted.

16 changes: 8 additions & 8 deletions src/main/kotlin/org/fuchss/matrix/mensa/swka/SWKAMensa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import kotlinx.datetime.LocalDate
import kotlinx.datetime.minus
import kotlinx.datetime.plus
import org.fuchss.matrix.mensa.api.Meal
import org.fuchss.matrix.mensa.api.Mensa
import org.fuchss.matrix.mensa.api.MensaAPI
import org.fuchss.matrix.mensa.api.MensaLine
import org.fuchss.matrix.mensa.api.Canteen
import org.fuchss.matrix.mensa.api.CanteenAPI
import org.fuchss.matrix.mensa.api.CanteenLine
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.slf4j.LoggerFactory

class SWKAMensa : MensaAPI {
class SWKAMensa : CanteenAPI {
companion object {
private val logger = LoggerFactory.getLogger(SWKAMensa::class.java)
private const val SWKA_WEBSITE = //
"https://www.sw-ka.de/de/hochschulgastronomie/speiseplan/mensa_adenauerring/?view=ok&c=adenauerring&STYLE=popup_plain&kw=%%%WoY%%%"
private val LINES_TO_CONSIDER = listOf("Linie ", "Schnitzel", "[pizza]werk Pizza", "[pizza]werk Pasta", "[kœri]werk")
}

override suspend fun foodAtDate(date: LocalDate): Map<Mensa, List<MensaLine>> {
override suspend fun foodAtDate(date: LocalDate): Map<Canteen, List<CanteenLine>> {
val week = numberOfWeek(date)
val html = request(week)

Expand All @@ -39,7 +39,7 @@ class SWKAMensa : MensaAPI {
}

val mensaLinesRaw = tableOfDay[0].select("td[width=20%] + td")
val mensaLines = mutableListOf<MensaLine>()
val mensaLines = mutableListOf<CanteenLine>()

for (line in mensaLinesRaw) {
val name = line.previousElementSibling()?.text()?.trim() ?: continue
Expand All @@ -52,13 +52,13 @@ class SWKAMensa : MensaAPI {
parseMeal(meal)?.let { meals.add(it) }
}
if (meals.isNotEmpty()) {
mensaLines.add(MensaLine(name, meals))
mensaLines.add(CanteenLine(name, meals))
}
}

mensaLines.sortBy { it.name }

val mensa = Mensa("adenauerring", "Mensa am Adenauerring")
val mensa = Canteen("adenauerring", "Mensa am Adenauerring")
return mapOf(mensa to mensaLines)
}

Expand Down

0 comments on commit e01ecf3

Please sign in to comment.