|
@@ -16,6 +16,7 @@ class db():
|
|
|
self.client = MongoClient('localhost', 27017)
|
|
self.client = MongoClient('localhost', 27017)
|
|
|
self.c_sources = self.client[self.DB]["sources"]
|
|
self.c_sources = self.client[self.DB]["sources"]
|
|
|
self.c_articles = self.client[self.DB]["articles"]
|
|
self.c_articles = self.client[self.DB]["articles"]
|
|
|
|
|
+ self.c_kw = self.client[self.DB]["keywords"]
|
|
|
|
|
|
|
|
def change_timezone(self, el):
|
|
def change_timezone(self, el):
|
|
|
#gmt = pytz.timezone("America/Buenos_Aires") # FIXME
|
|
#gmt = pytz.timezone("America/Buenos_Aires") # FIXME
|
|
@@ -159,11 +160,11 @@ class db():
|
|
|
return [re.compile('\\b' + w.lower() + '\\b') for w in arr]
|
|
return [re.compile('\\b' + w.lower() + '\\b') for w in arr]
|
|
|
|
|
|
|
|
def get_keywords_list(self):
|
|
def get_keywords_list(self):
|
|
|
- kw = self.client[self.DB]["keywords"]
|
|
|
|
|
|
|
+ kw = self.c_kw
|
|
|
return [k["keyword"] for k in kw.find({})]
|
|
return [k["keyword"] for k in kw.find({})]
|
|
|
|
|
|
|
|
def get_keywords(self, category):
|
|
def get_keywords(self, category):
|
|
|
- kw = self.client[self.DB]["keywords"]
|
|
|
|
|
|
|
+ kw = self.c_kw
|
|
|
ret = [{"weight": k["weight"],
|
|
ret = [{"weight": k["weight"],
|
|
|
"kw": k["keyword"],
|
|
"kw": k["keyword"],
|
|
|
"pattern": self.to_regex(k["keyword"].split("|"))} for k in kw.find({})]
|
|
"pattern": self.to_regex(k["keyword"].split("|"))} for k in kw.find({})]
|
|
@@ -171,7 +172,7 @@ class db():
|
|
|
return ret
|
|
return ret
|
|
|
|
|
|
|
|
def add_keyword(self, kw, weight):
|
|
def add_keyword(self, kw, weight):
|
|
|
- kwdb = self.client[self.DB]["keywords"]
|
|
|
|
|
|
|
+ kwdb = self.c_kw
|
|
|
try:
|
|
try:
|
|
|
data = {'keyword': kw, 'weight': weight}
|
|
data = {'keyword': kw, 'weight': weight}
|
|
|
kwdb.insert_one(data)
|
|
kwdb.insert_one(data)
|
|
@@ -185,7 +186,7 @@ class db():
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
kw["pattern"] = self.to_regex(kw["keyword"].split("|"))
|
|
kw["pattern"] = self.to_regex(kw["keyword"].split("|"))
|
|
|
- kwdb = self.client[self.DB]["keywords"]
|
|
|
|
|
|
|
+ kwdb = self.c_kw
|
|
|
try:
|
|
try:
|
|
|
kwdb.update({'keyword': kw['keyword']}, {'$set': kw})
|
|
kwdb.update({'keyword': kw['keyword']}, {'$set': kw})
|
|
|
return True
|
|
return True
|
|
@@ -194,7 +195,7 @@ class db():
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
def delete_keyword(self, kw):
|
|
def delete_keyword(self, kw):
|
|
|
- kwdb = self.client[self.DB]["keywords"]
|
|
|
|
|
|
|
+ kwdb = self.c_kw
|
|
|
try:
|
|
try:
|
|
|
kwdb.remove({'keyword': kw})
|
|
kwdb.remove({'keyword': kw})
|
|
|
return True
|
|
return True
|