Last active
June 14, 2017 10:34
-
-
Save ronfe/f8269ad23665682372189b2faac65a9a to your computer and use it in GitHub Desktop.
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
from pymongo import MongoClient | |
conn = MongoClient('localhost:27017') | |
questions = conn['mintNew']['questions'] | |
users = conn['mintNew']['users'] | |
repeated = [ | |
{ "_id" : "According to a survey in May, about 9.8 percent of the 93,420 graduates surveyed said they wouldn’t begin working right after graduation. This phenomenon is called “delayed employment”. One reason is that young people want to find a job that is related to their personal interests, and they are not willing to give in and take jobs they don’t like. Another reason is that some have opted to delay finding work is to avoid the fierce competition of the job market. And some Chinese college students have chosen to travel or volunteer instead of finding jobs. ", "c" : 2 }, | |
{ "_id" : "While we all try to find happiness, sometimes we still end up feeling low. While most people can control this feeling, low moods (情绪) can stay with some, leading to depression. There are three age groups that are particularly likely to develop depression. One group is the elderly, while another group is women who are pregnant or have just given birth. In addition, young people are another group known to suffer with depression. In China, depression among young people is on the rise. Competition to outperform others, especially in education, can cause a lot of pressure for Chinese youth. ", "c" : 2 }, | |
{ "_id" : "Chinese web novels have recently been gaining popularity among foreign readers. According to a 2016 report from Novel Updates, a website that translates popular Asian novels for Western readers, among the site’s 10 most popular web novels, five were written by Chinese authors. Foreign readers are attracted by the Chinese culture and history in the novels. Chinese online literature has a cultural charm and is easily accessible to young foreign audiences with the help of Internet. It is a good channel to spread Chinese culture.", "c" : 2 }, | |
{ "_id" : "China has nominated tai chi to be included in the UNESCO List of Intangible Cultural Heritage (联合国教科文组织非物质文化遗产名录). A final decision will be made later this year. Tai chi, a kind of martial art, has been practiced in China for centuries. It combines slow movements, deep breathing and meditation. Every movement in tai chi represents an important part of traditional Chinese philosophy – harmony. Although it’s popular, the idea that tai chi is for the elderly has stopped many young people practicing the ancient martial art. ", "c" : 2 }, | |
{ "_id" : "The damaging effects of shift work on the body are well known. This study also shows the impact on the mind.Three thousand people had tests of memory and speed of thought. Those with more than ten years of shift work under their belts (已获得的经历) had the same results as those who didn't do shifts but were six-and-a-half years older.", "c" : 2 }, | |
{ "_id" : "With an announcement made on April 1, Xiongan has risen from nowhere to become a famous name in China overnight. The establishment of the Xiongan New Area is “the latest step in China’s efforts to cure severe urban ills”. It’s hoped that the plans will help ease problems such as traffic congestion (拥堵) and air pollution in Beijing. Meanwhile, by advancing the coordinated development of the Beijing-Tianjin-Hebei region, the Xiongan New Area could promote the rapid development of North China.", "c" : 2 }, | |
{ "_id" : "Buried beneath the golden sands of Folkestone are 30 tiny pieces of not silver, but gold. It’s part of a project by the German artist Michael Sailstorfer, who buried the treasure by hand and there’s no map. There are two sizes – one worth around £250 and the other around £500 – and it’s finders keepers for anyone lucky enough to unearth (挖掘) one. Beachcombers with metal detectors (探测器) are out in force. But the artist has also buried metal washers (垫片) to try to level the playing field.", "c" : 2 }, | |
{ "_id" : " The authors acknowledge that a transition from fossil fuels to renewable energy is necessary to achieve. Many countries are locked into using fuels like coal. Here in Germany coal provides nearly half the electricity. But because greenhouse gases are building up in the atmosphere so rapidly, the conclusion is that it’s better to make the change sooner rather than later. Professor Jim Skea at Imperial College is a leading figure on the panel (专家组).", "c" : 2 }, | |
{ "_id" : "Some birds perform remarkable feats (功绩,手艺) of navigation, migrating halfway around the world. And it’s thought that a built-in compass, which senses the Earth’s magnetic field, helps them to find their way. But this latest study suggests that low frequency waves produced by devices plugged (插入) into the mains electricity, could be interfering with this ‘inner satnav (卫星定位)’. Scientists found that migratory birds exposed to this electromagnetic noise lost all sense of direction. But when the field was blocked out, they found their bearings again.", "c" : 2 }, | |
] | |
def remove_repeat(doc, has_reviewed=False): | |
uid = doc['createdBy'] | |
qid = doc['_id'] | |
users.update_one({"_id": uid}, {"$pull": {"authoredQuestions": qid}}) | |
if has_reviewed: | |
users.update_one({"_id": doc["reviewedBy"]}, {"$pull": {"reviewedQuestions": qid}}) | |
questions.delete_one({"_id": qid}) | |
print(qid) | |
# backup | |
pipeline = [ {"$match": {}}, | |
{"$out": "usersBackup"}, | |
] | |
users.aggregate(pipeline) | |
pipeline = [ {"$match": {}}, | |
{"$out": "questionsBackup"}, | |
] | |
questions.aggregate(pipeline) | |
r = [t['_id'] for t in repeated] | |
for item in r: | |
x1, x2 = list(questions.find({"passage": item}))[0], list(questions.find({"passage": item}))[1] | |
if x2['status'] == 'published' and x1['status'] == 'published': | |
remove_repeat(x2, True) | |
continue | |
if x2['status'] == 'published' and x1['status'] == 'needReview': | |
remove_repeat(x1) | |
continue | |
remove_repeat(x2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment