Skip to content

Commit

Permalink
add remove_question_before.py
Browse files Browse the repository at this point in the history
  • Loading branch information
laike9m committed Mar 19, 2016
1 parent b4ab39a commit 0f5bb2e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions query/remove_question_before.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
移除某个时间点之后提出的问题, 以及它们的答案. 在程序出问题时使用
"""

from datetime import datetime

import pymongo

t = datetime(2016,3,11,18,0,0)

db = pymongo.MongoClient('127.0.0.1', 27017).zhihu_data
q_colls = ["19550517_q", "19551147_q", "19561087_q", "19553298_q"]

for q_coll in q_colls:
coll = db.get_collection(q_coll)
acoll = db.get_collection(q_coll[:-1] + 'a')
for qdoc in coll.find():
if qdoc['time'] < t:
result = coll.delete_one({'qid': qdoc['qid']})
assert result.deleted_count == 1
print("question %s removed" % qdoc['qid'])
result = acoll.delete_many({'qid': qdoc['qid']})
print("%d answers removed" % result.deleted_count)

0 comments on commit 0f5bb2e

Please sign in to comment.