Skip to content

Instantly share code, notes, and snippets.

@ronfe
Created April 26, 2016 05:28
Show Gist options
  • Save ronfe/4d52a2dccaa9fb79daac84b2a4c4b9f9 to your computer and use it in GitHub Desktop.
Save ronfe/4d52a2dccaa9fb79daac84b2a4c4b9f9 to your computer and use it in GitHub Desktop.
r-yaqi-courseuser
# _*_ 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()
# _*_ 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()
# _*_ 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