Skip to content

Commit 7e19d6a

Browse files
committed
Implemented MongoDB insert support for caching
1 parent 6537e01 commit 7e19d6a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/Site.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from Queue import Queue
22
import requests
33
import time
4+
from pymongo import MongoClient
45
from requests import ConnectionError
56
from twitter import TwitterError
7+
from settings import USE_DB, DB_HOST, DB_PORT
68
import logging
79
import helper
810

@@ -30,6 +32,10 @@ class Site(object):
3032
def __init__(self, queue=None):
3133
if queue is None:
3234
self.queue = []
35+
if USE_DB:
36+
# Lazily create the db and collection if not present
37+
self.db_client = MongoClient(DB_HOST, DB_PORT).paste_db.pastes
38+
3339

3440
def empty(self):
3541
return len(self.queue) == 0
@@ -67,14 +73,22 @@ def monitor(self, bot, t_lock):
6773
paste = self.get()
6874
self.ref_id = paste.id
6975
logging.info('[*] Checking ' + paste.url)
70-
# goober pastie - Not actually showing *raw* text.. Still need
71-
# to parse it out
7276
paste.text = self.get_paste_text(paste)
7377
tweet = helper.build_tweet(paste)
7478
if tweet:
7579
logging.info(tweet)
7680
with t_lock:
77-
helper.record(tweet)
81+
if USE_DB:
82+
self.db_client.save({
83+
'pid' : paste.id,
84+
'text' : paste.text,
85+
'emails' : paste.emails,
86+
'hashes' : paste.hashes,
87+
'num_emails' : paste.num_emails,
88+
'num_hashes' : paste.num_hashes,
89+
'type' : paste.type,
90+
'db_keywords' : paste.db_keywords
91+
})
7892
try:
7993
bot.statuses.update(status=tweet)
8094
except TwitterError:

0 commit comments

Comments
 (0)