Created
April 26, 2016 05:28
-
-
Save ronfe/4d52a2dccaa9fb79daac84b2a4c4b9f9 to your computer and use it in GitHub Desktop.
r-yaqi-courseuser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _*_ coding:utf-8 _*_ | |
from pymongo import MongoClient | |
db = MongoClient('10.8.8.111:27017')['onions-cb'] | |
chapters = db['chapters'] | |
x = chapters.find({"publisher": "北师大版", "semester": "七年级下", "status": "published"}) | |
topic_list = [] | |
for doc in x: | |
unit_topic = doc['topics'] | |
for each in unit_topic: | |
topic_list += each | |
f = open('bnu.txt', 'w+') | |
for each in topic_list: | |
f.write(each) | |
f.write('\n') | |
f.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _*_ coding:utf-8 _*_ | |
from pymongo import MongoClient | |
from bson.objectid import ObjectId | |
import codecs | |
db = MongoClient('10.8.8.111:27017')['ronfedb'] | |
course_db = MongoClient('10.8.8.111:27017')['onions-cb'] | |
challenge = db['challenge'] | |
topics = course_db['topics'] | |
publisher = 'renjiao' | |
f = open('./' + publisher + '.txt').readlines() | |
g = [] | |
for each in f: | |
g.append(each.strip()) | |
pipeline = [ | |
{"$match": {"eventValue.topicId": {"$in": g}}}, | |
{"$group": {"_id": "$user", "finishedTopics": {"$addToSet": "$eventValue.topicId"}}}, | |
{"$match": {"finishedTopics.29": {"$exists": True}}} | |
] | |
x = list(challenge.aggregate(pipeline)) | |
f = codecs.open('./' + publisher + "_users.txt", 'w+', 'utf-8') | |
for each in x: | |
f.write(str(each['_id'])) | |
f.write('\n') | |
# for unit_topic in each['finishedTopics']: | |
# y = topics.find_one({"_id": ObjectId(unit_topic)}) | |
# f.write(y['name']) | |
# f.write('\n') | |
# f.write('\n') | |
f.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _*_ coding:utf-8 _*_ | |
from pymongo import MongoClient | |
from bson.objectid import ObjectId | |
import codecs | |
import re | |
db = MongoClient('10.8.8.111:27017')['koalaBackupOnline'] | |
users = db['users'] | |
publisher = 'renjiao' | |
f = open('./' + publisher + '_users.txt').readlines() | |
g = [] | |
for each in f: | |
g.append(ObjectId(each.strip())) | |
phone_num = re.compile('^\d{11}$') | |
pipeline = [ | |
{"$match": {"publisher": "人教版", "_id": {"$in": g}, "name": {"$regex": phone_num}, "role": "student"}}, | |
{"$sample": {"size": 10}} | |
] | |
x = list(users.aggregate(pipeline)) | |
for each in x: | |
print '\"' + str(each["_id"]) + '\"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment