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. PHP值传递和引用传递的区别

    PHP值传递和引用传递的区别.什么时候传值什么时候传引用 (1)按值传递:函数范围内对值的任何改变在函数外部都会被忽略 (2)按引用传递:函数范围内对值的任何改变在函数外部也能反映出这些修改 (3)优 ...

  2. Spring + Spring MVC+Hibernate框架整合详细配置

    来源于:http://www.jianshu.com/p/8e2f92d0838c 具体配置参数: Spring: spring-framework-4.2.2Hibernate: hibernate ...

  3. 50ms延时程序

    12MHz晶振 一个机器周期2us, DEL:  MOV  R7,#200D DEL1: MOV R6,#125 DEL2: DJNZ R6,DEL2 ;125*2=250us DJNZ  R7,DE ...

  4. Integer与int的种种比较

    package com.lxm.basics; public class IntegerTest { public static void main(String[] args) { Integer ...

  5. ART、JIT、AOT、Dalvik之间的关系

    原文地址: https://github.com/ZhaoKaiQiang/AndroidDifficultAnalysis/blob/master/10.ART%E3%80%81JIT%E3%80% ...

  6. FastDFS搭建及java整合代码【转】

    FastDFS软件介绍 1.什么是FastDFS FastDFS是用C语言编写的一款开源的分布式文件系统.FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高 ...

  7. [转]webApi 参数传递总结

    在WebAPI中,请求主体(HttpContent)只能被读取一次,不被缓存,只能向前读取的流. 举例子说明: 1. 请求地址:/?id=123&name=bob 服务端方法: void Ac ...

  8. nutch-介绍

    本文主要源于http://www.ibm.com/developerworks/cn/opensource/os-cn-nutchintro/ 基本信息 Nutch是一个开放源代码(open-sour ...

  9. git初体验(六)git配置

    一.基本配置 看这篇Git 基本配置其实就解决很多问题了. 二.客户端配置 1.git bash 粘贴与编辑 在git bash客户端头部右键,现在属性,然后把"快速编辑模式勾选即可&quo ...

  10. 使用HTML来生产Android界面

    使用HTML来生产Android界面 (2013-03-11 17:50:39) 转载▼   分类: Android 1. HTML 开发软件界面   因为android软件开发分工目前还没有细化,程 ...