Exemplo n.º 1
0
import json
from util.mongo import MongoClient

# from search import Search
from daytest import Test

# from redpacket import RedPacket
from convertion import Rate
import time

try:
    jf = open("config_db.json")
except IOError:
    print "Don't exist the file config_db.json"
config_json = json.load(jf)
con = MongoClient(config_json["host"], config_json["port"], config_json["dbname"])
re = con.authenticate(config_json["user"], config_json["passwd"])
if re is not True:
    print "Connection is fail"
jf.close()
# s = Search()
# s.mys(con, "giftRecord", {"ctime": {"$gte": begintime, "$lte": endtime}})
# s.printvalue()
# s.myfind(con)
# s.printvalue2()
def translatetime(timestr):
    """
    :param timestr: {int,float,string}
    :return: { int 13bit}
    """
    if timestr is None:
Exemplo n.º 2
0

h = "db.ali.ppweb.com.cn"
p = 30000
dbname = "zhibo"
user = "******"
pwd = "rs@pw"

# h = "10.11.12.31"
# p = 27017
# dbname = "zhangyu"
# user = "******"
# pwd = "testpw"


mc = MongoClient(host=h, port=p, dbName=dbname)
re = mc.authenticate(user, pwd)
if re is False:
    print "sorry,it is fail"

con = {
    "ctime": {
        "$gte": btime, "$lte": etime
    }
}
cursor = mc.get("giftRecord", con)
mytest(cursor)



Exemplo n.º 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from util.mongo import MongoClient
import time
def trantime(t):
    c = long(time.mktime(time.strptime(t,"%a %b %d %H:%M:%S %Y")))
    return c

ar = {"43": 1000}
h = "10.11.12.31"
p = 27017
dbname = "zhangyu"
user = "******"
passwd = "testpw"
m = MongoClient(host=h,port=p,dbName=dbname)
c = m.authenticate(user, passwd)
if c != True:
    print "fail"
con = {
}
g = m.get("money", con)
a = g.distinct("_id")
print len(a), g.count()
for gc in g:
    if gc.get("_id") in ar.keys():
        print ar[gc.get("_id")]



btime = trantime("Wed Jul 15 00:00:00 2015")
etime = trantime("Thu Jul 16 00:00:00 2015")