import java.io.File
import scala.io.Source
import com.sanoma.cda.geoip.MaxMindIpGeo
import com.sanoma.cda.geo.Point
import java.io.PrintWriter val geoIp = MaxMindIpGeo("/data/elas-input/GeoIP2-City.mmdb", 1000,synchronized = true) def iter_dir(srcDir:String,dstDir:String): Unit ={
val files = (new File(srcDir)).listFiles().filter(_.isFile)
for( item <- files){
println(item.getName)
val dstname = item.getName
val out = new PrintWriter(s"""${dstDir}/${dstname}""") for(line <- Source.fromFile(item).getLines()){
val it = line.split("\t")
val geo = geoIp.getLocation(it(0))
if(geo.isEmpty){
out.printf("%s,%s,%s,%s\n",it(0),it(1),it(2),it(3),it(4),"")
}
else{
val geoGet = geo.get
val countryCode = geoGet.countryCode.getOrElse("")
val countryName = geoGet.countryName.getOrElse("")
val region = geoGet.region.getOrElse("")
val city = geoGet.city.getOrElse("")
val geoPoint = geoGet.geoPoint
val latitude = if(geoPoint.isEmpty) "" else geoPoint.get.latitude.toString
val longitude = if(geoPoint.isEmpty) "" else geoPoint.get.longitude.toString
val postalCode = geoGet.postalCode.getOrElse("")
val continent = geoGet.continent.getOrElse("")
out.printf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",it(0),it(1),it(2),it(3),it(4),countryCode,countryName,region,city,latitude,longitude,postalCode,continent,it(5))
}
}
out.close()
}
}
iter_dir("/data/elas-input/uniqServiceDir","/data/elas-input/tsoutput") val str2 = "North Amercia"
val index = str.indexOf(str2)
val index2 = str.length + index + 1
val content = str.substring(index2)

spark geoip的更多相关文章

  1. spark streaming 使用geoIP解析IP

    1.首先将GEOIP放到服务器上,如,/opt/db/geo/GeoLite2-City.mmdb 2.新建scala sbt工程,测试是否可以顺利解析 import java.io.Fileimpo ...

  2. geoip ip2region2 with spark

    上一篇文章中 我使用 maxmind的免费库开发了一个waterdrop的 插件,测试数据发现,国内的有些市级还是不准确,而且香港并不是显示中国,这就不友好了. 找了一下,发下 ip2region 这 ...

  3. spark操作geoip的domain数据库

    val ipv4 = sc.textFile("hdfs://hbase11:9000/sparkTsData/GeoIP2-Domain-Blocks-IPv4.csv").ma ...

  4. geoip scala api

    #!/bin/bash /home/hadoop/spark-1.6.2/bin/spark-shell --master spark://hbase11:7077 --executor-memory ...

  5. 使用Java编写并运行Spark应用程序

    我们首先提出这样一个简单的需求: 现在要分析某网站的访问日志信息,统计来自不同IP的用户访问的次数,从而通过Geo信息来获得来访用户所在国家地区分布状况.这里我拿我网站的日志记录行示例,如下所示: 1 ...

  6. Spark踩坑记——Spark Streaming+Kafka

    [TOC] 前言 在WeTest舆情项目中,需要对每天千万级的游戏评论信息进行词频统计,在生产者一端,我们将数据按照每天的拉取时间存入了Kafka当中,而在消费者一端,我们利用了spark strea ...

  7. Spark RDD 核心总结

    摘要: 1.RDD的五大属性 1.1 partitions(分区) 1.2 partitioner(分区方法) 1.3 dependencies(依赖关系) 1.4 compute(获取分区迭代列表) ...

  8. spark处理大规模语料库统计词汇

    最近迷上了spark,写一个专门处理语料库生成词库的项目拿来练练手, github地址:https://github.com/LiuRoy/spark_splitter.代码实现参考wordmaker ...

  9. Hive on Spark安装配置详解(都是坑啊)

    个人主页:http://www.linbingdong.com 简书地址:http://www.jianshu.com/p/a7f75b868568 简介 本文主要记录如何安装配置Hive on Sp ...

随机推荐

  1. -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.

    一, eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery ...

  2. Ceph: validate that the RBD cache is active

    Ceph: validate that the RBD cache is active Quick and simple test to validate if the RBD cache is en ...

  3. mysql 表被锁处理方案

    1. 查询锁表信息 当前运行的所有事务 select * from information_schema.innodb_trx 当前出现的锁 select * from information_sch ...

  4. 512M内存编译php出错

    make时错误如下 virtual memory exhausted: Cannot allocate memory make: *** [ext/fileinfo/libmagic/apprenti ...

  5. 【转】c# 调用windows API(user32.dll)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  6. sql insert into select语句写法-将查询结果直接插入到表中

    insert into month_gpcj_info(idStr,zszrmygpsl,xyzrmygpsl,mycje,mycjl,month_date,dataCompiledDate) sel ...

  7. bzoj4401: 块的计数

    首先,块的大小确定的话,可以发现方案最多只有1种 然后就可以O(nsqrt(n))搞,不过会TLE 接着我们又发现,一个节点可以作一个块的根,当且仅当该节点的size能被块的大小整除 然后就可以O(n ...

  8. (转) Web 建站技术中,HTML、HTML5、XHTML、CSS、SQL、JavaScript、PHP、ASP.NET、Web Services 是什么?

    Web 建站技术中,HTML.HTML5.XHTML.CSS.SQL.JavaScript.PHP.ASP.NET.Web Services 是什么? 建站有很多技术,如 HTML.HTML5.XHT ...

  9. Matlab的实时编辑器(Live Script)

    Matlab的实时编辑器(Live Script) 看到伟哥换用了matlab2016a,里面集成了acf行人检测算法,感觉挺好的,索性也从matlab2014a跨越到matlab2016a. 安装后 ...

  10. 配置jdk相关的记录

    1.8.0_60JAVA_HOME=/usr/local/java/jdk1.8.0_60JRE_HOME=${JAVA_HOME}/jreCLASSPATH=.:${JAVA_HOME}/lib:$ ...