Skip to content

Commit

Permalink
Remove geoip dependecy, no longer resolving IP address to geo locations
Browse files Browse the repository at this point in the history
  • Loading branch information
2bethere committed Mar 26, 2020
1 parent d416bbe commit 1ba75d4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ libraryDependencies ++= Seq(
"com.ircclouds.irc" % "irc-api" % "1.0-0014",
"org.apache.kafka" % "kafka-clients" % "2.2.0",
"ch.qos.logback" % "logback-core" % "1.1.2",
"ch.qos.logback" % "logback-classic" % "1.1.2",
"io.imply" %% "hostbook" % "0.2"
"ch.qos.logback" % "logback-classic" % "1.1.2"
)

lazy val root = project.in(file(".")).enablePlugins(JavaAppPackaging)
Expand Down
22 changes: 1 addition & 21 deletions src/main/scala/io/imply/wikiticker/ConsoleTicker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import com.metamx.common.scala.Logging
import com.metamx.common.scala.lifecycle._
import com.metamx.common.scala.untyped.Dict
import com.twitter.app.Flags
import io.imply.hostbook.GeoLookup
import java.io.File

object ConsoleTicker extends Logging
{
private val geoDb = GeoLookup.fromFreeDownloadableCityDatabase(new File(Files.createTempDir(), "geodb"))
private val ipPattern = "(\\d+.\\d+.\\d+.\\d+)".r

private var messageCounter = 0
Expand All @@ -51,8 +49,7 @@ object ConsoleTicker extends Logging

val listener = new MessageListener {
override def process(message: Message) = {
writer.write(Jackson.generate(withGeo(message.toMap)))

writer.write(Jackson.generate(message.toMap))
messageCounter += 1
if (messageCounter % 100 == 0) {
log.info(s"Processed [${messageCounter}] messages")
Expand Down Expand Up @@ -143,21 +140,4 @@ object ConsoleTicker extends Logging
}
}

def withGeo(map: Dict): Dict = {
map ++ (map("user").asInstanceOf[String] match {
case ipPattern(ip) => {
val result = geoDb.lookup(ip)
Dict(
"isAnonymous" -> true,
"cityName" -> result.cityName.orNull,
"countryIsoCode" -> result.countryIsoCode.orNull,
"countryName" -> result.countryName.orNull,
"metroCode" -> result.metroCode.orNull,
"regionIsoCode" -> result.regionIsoCode.orNull,
"regionName" -> result.regionName.orNull
)
}
case _ => Dict("isAnonymous" -> false)
})
}
}

0 comments on commit 1ba75d4

Please sign in to comment.