forked from jellylidong/DeepDefense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparkIP.py
45 lines (32 loc) · 983 Bytes
/
sparkIP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
__author__ = 'vcoder'
import os
import sys
# os.environ['SPARK_HOME'] = "/home/vcoder/EDA/spark-1.5.0"
# sys.path.append("/home/vcoder/EDA/spark-1.5.0/python")
os.environ['SPARK_HOME'] = "/home/worker/software/spark-1.5.0"
sys.path.append("/home/worker/software/spark-1.5.0/python")
from pyspark import SparkContext
from pyspark import SparkConf
# import pymongo_spark
# pymongo_spark.activate()
sc = SparkContext(appName="sparkIP");
# a =[1,2,3,4,5];
# b = sc.parallelize(a);
# c = b.map(lambda k :2*k);
# print c.collect()
a = sc.textFile('csv/output.csv')
#print a.collect()[0]
b = a.map(lambda line: line.split(',')).map(lambda val:(val[1], val[2]))
print b.collect()[0:10]
import pymongo
from pymongo import MongoClient
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client['test']
ips = db.ips3
content = {"fileName": "testIP",
"IPs": b.collect()[0:10]}
ips.insert_one(content)
aaa = ips.find()
print aaa[0]['IPs'][0][0]
sc.stop()