zoukankan      html  css  js  c++  java
  • python操作Mongo数据库

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    import operator
    from pymongo import MongoClient
    import sys
    reload(sys)
    sys.setdefaultencoding("utf-8")

    DBC_W_RANK = MongoClient("192.168.1.10").game.weiboRank
    DBC_W_ANALYSE = MongoClient("192.168.1.10").game.weiboAnalyse

    def getZhangyixing():

    print "名称,id,粉丝数,评论总量,转发总量,发博总量,点赞总量,平均评论量,平均转发量,平均发博量,平均点赞量 "
    for item in DBC_W_ANALYSE.find({"weiboId":"2706896955"}):
    weiboId = str(item.get("weiboId"))
    postStats = item.get("postStat")
    leng = len(postStats)
    totalC = 0
    totalF = 0
    totalP = 0
    totalL = 0
    for item in postStats:
    totalC=item["commentCount"] + totalC
    totalF = item["forwardCount"] + totalF
    totalP = item["postCount"] + totalP
    totalL = item["likeCount"] + totalL
    avgC = totalC / float(leng)
    avgF = totalF / float(leng)
    avgP = totalP / float(leng)
    avgL = totalL / float(leng)
    string = "努力努力再努力x" + ","+str(weiboId)+","+" dd "+"," + str(totalC) + "," + str(totalF) + "," + str(totalP) + ","+ str(totalL)+ ","+ str(avgC) + "," + str(avgF) + "," + str(avgP)+ "," + str(avgL) + " "
    print string
    if __name__ == "__main__":
    getZhangyixing()

  • 相关阅读:
    springMVC学习--RESTful支持
    Java中的值传递和引用传递
    SpringMVC学习--json
    SpringMVC学习--文件上传
    SpringMVC学习--异常处理器
    SpringMVC学习--数据回显
    SpringMVC学习--校验
    SpringMVC学习--参数绑定
    SpringMVC学习--功能完善
    SpringMVC学习--springmvc和mybatis整合
  • 原文地址:https://www.cnblogs.com/sy-liu/p/7058283.html
Copyright © 2011-2022 走看看