my code stock.com

Snippet-Optionen

Download: Snippet als ggts_map_reducepy.py herunterladen.
Snippet kopieren: Für diese Aktion benötigst du einen kostenlosen my code stock.com Account
Embed-Code : Du findest den Embed-Code für dieses Snippet am Ende der Seite, wenn du es in eine Webseite oder einen Blog einbinden möchtest!

#! c:/Python26/python.exe
# coding: utf-8 

import sys
import codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)

import pymongo
from pymongo import Connection #@UnresolvedImport
from pymongo.code import Code #@UnusedImport

def activities_m_r():
    con = Connection()
    coll = con.ggts.activities
    m = pymongo.code.Code("""function(){ emit({published:this.published_jst_d,name :this.actor.displayName}, {count: 1, replies: this.object.replies.totalItems}); }""")
    r = pymongo.code.Code("""
        function(key, values) {
            var result = {count: 0, replies: 0};

            values.forEach(function(value) {
            result.count += value.count;
            result.replies += value.replies;
            });

            return result;
            }
        """)    
    results = coll.map_reduce(m, r,"myresult")
    return results

def comments_m_r():
    con = Connection()
    coll = con.ggts.comments
    m = pymongo.code.Code("""function(){ emit({published:this.published_jst_d,name :this.actor.displayName}, {count: 1, replies: this.object.replies.totalItems}); }""")
    r = pymongo.code.Code("""
        function(key, values) {
            var result = {count: 0, replies: 0};

            values.forEach(function(value) {
            result.count += value.count;
            result.replies += value.replies;
            });

            return result;
            }
        """)    
    results = coll.map_reduce(m, r,"myresult")
    return results

if __name__ == '__main__':
    print 'activities'
    results = activities_m_r()
    for result in results.find():
        print str(result['_id']['published']) + ',' + str(result['_id']['name']) + ',' + str(result['value']['count']) + ',' + str(result['value']['replies'])
    print '--------------------'

    print 'comments'
    results = comments_m_r()
    for result in results.find():
        print str(result['_id']['published']) + ',' + str(result['_id']['name']) + ',' + str(result['value']['count']) + ',' + str(result['value']['replies'])
    print '--------------------'

Jetzt kostenlosen my code stock.com Account anlegen

my code stok.com ist ein kostenloser Dienst zum Speichern und Verwalten von Code-Snippets jeglicher Art und Programmiersprache. Wir bieten dir viele Vorteile für die tägliche Arbeit mit Code-Snippets und der gemeinsamen Arbeit im Team, probier es aus!

Jetzt informieren und registrieren

Du kannst die Höhe des iFrame-Codes beliebig anpassen! Mehr Infos findest du in unserer Embed-Code API Referenz.