def mongo_query(search_contents):

    try:
            client = mongoclient(dbhost, dbport)
            authen_status = client.PornHub.authenticate(dbuser,dbpass)
            if authen_status is True:
                db = client[database]
                coll = db[collections]
                datas = coll.find({'video_title':re.compile(search_contents)})
                count = 0
                check_results  = []
                for data in datas:
                   count += 1
                   time.sleep(0.0001)
                   if int(data['video_duration']) > 3600:
                     tem = {}
                     tem[u'video_title'] = data['video_title'].encode("utf-8")
                     tem['video_durtion'] = int(data['video_duration'])
                     tem['video_viewkey'] = data['viewkey']
                     tem['image_url'] = data['image_url']
                     check_results.append(tem)
                return check_results
            else:
                print "Authentication failed"
    except:
            print "Error"
Exemple #2
0
import pymongo


conn = "mongodb://localhost;27017"
client = pymongo.mongoclient(conn)

db = client.travel

dest = db.destinations.find()


for countries in dest;
print (countries)

db.destinations.insert_one({
    "continent":"africa",
    'country':'madagaskar',
    'major_cities':'roderick Land'
})

count = db.destinations.count()
print ("total doc")
 def __init__(self):
     self.conn = mongoclient("172.16.255.252", 65533)
Exemple #4
0
 def __init__(self):
     self.conn = mongoclient("", )
Exemple #5
0
formatter = logging.Formatter('%(asctime)s %(levelname)-8s:%(message)s')
file_handler = logging.FileHandler("downloading.log")
file_handler.setFormatter(formatter)
console_handler = logging.StreamHandler(sys.stdout)
console_handler.formatter = formatter

logger.addHandler(file_handler)
logger.addHandler(console_handler)

logger.setLevel(logging.INFO)

dbhost = 'xxx'
dbpass = '******'
dbport = 'xxx'
dbuser = '******'
client = mongoclient(dbhost, dbport)
client.PornHub.authenticate(dbuser, dbpass)
db = client["PornHub"]
coll = db["PhRes"]
try:
    datas = coll.find()
    for data in datas:
        time.sleep(0.001)
        if int(data['video_duration']) > 1200:
            url = data['viewkey']
            html = requests.get(url).text
            try:
                _ph_info = re.findall('flashvars_.*?=(.*?);\n', html)
                _ph_info_json = json.loads(_ph_info[0])
                title = _ph_info_json.get('video_title').replace(" ", "-")
                logger.info(title)
Exemple #6
0
	number=math.floor(random.random()*100)
	x={"user_id":user_id,"name":name,"number":number};
	coll.inset(x);

docs=coll.find()
for i in docs:
	print(i)

# 2.
import pymongo
import math
import random

from pymongo import MongoClient

conn = pymongo.mongoclient("mongodb://localhost")

database = conn.pes
coll = database.mca

for i in range(10):
	coll.insert_one({"name":"Sampada"})

docs=coll.find()
for i in range(10):
	print(i)

# 3
import pymongo
import math
import random