-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataprocesser.py
48 lines (40 loc) · 1.51 KB
/
dataprocesser.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
46
#!/usr/bin/env python
import json
import twitterutl as Utl
from dbConfig import MongoConf
from pymongo import Connection
class DataProc(object) :
def __init__(self, configfile):
fileHandle = open(configfile, 'r')
self.conf = json.load(fileHandle)
self.connection = Connection(self.conf['host'],self.conf['port'])
self.db = {}
for dbname in self.conf['dbname']:
self.db[dbname] = self.connection[dbname]
# for collection in self.conf[dbname]:
# self.collections[dbname][collection] = self.db[collection]
def findmatch(self, tweet):
match_dbname = []
match_collection = []
#print 'in find match'
for dbname in self.conf['dbname']:
#print dbname
for term in self.conf[dbname]:
#print "term: %s\n text:%s\n" %(term, tweet)
if -1 != tweet.lower().find(term.lower()):
# print "term: %s\n text:%s\n" %(term, tweet)
match_dbname.append(dbname)
match_collection.append(term)
return (match_dbname, match_collection)
def process(self, tweet):
tweet = json.loads(tweet)
twi = Utl.processTweetStream(tweet)
# what's the fuck!!!
twi = json.loads(twi)
(match_dbname, match_collection) = self.findmatch(twi['text'])
for i in range(0, len(match_dbname)):
self.db[match_dbname[i]][match_collection[i]].insert(twi)
# print tweet
#for match_dbname in matcher:
# if None == self.db[self.db][match].find_one({"id":tweet['id']}):
# self.db[]