def index(request, page='1', edit=None): page = int(page) cols = MongoClient().prikoso_2016.tweets users = [] for name, num in sorted(space_nums, key=lambda x: x[1]): # numでソート # ページ外のユーザを除外 if not 10 * (page - 1) <= num < 10 * page: # ex. page=2 ならば #10-19 を表示 continue user = cols.find_one({'tweet.user.screen_name': name}) if user: user = user['tweet']['user'] if edit: # 編集するときは全件表示する pins = cols.find({ 'tweet.user.screen_name': name, 'tweet.extended_entities': {'$exists': True}, 'tweet.text': {'$not': re.compile(r'^RT ')}, 'pin': {'$exists': True}, }).sort('tweets.id') tweets = cols.find({ 'tweet.user.screen_name': name, 'tweet.extended_entities': {'$exists': True}, 'tweet.text': {'$not': re.compile(r'^RT ')}, 'pin': {'$exists': False}, }).sort('tweets.id') print(name, pins.count() + tweets.count()) else: # 通常時はdisabaleされたものを除外する pins = cols.find({ 'tweet.user.screen_name': name, 'tweet.extended_entities': {'$exists': True}, 'tweet.text': {'$not': re.compile(r'^RT ')}, 'disable': {'$exists': False}, 'pin': {'$exists': True}, }).sort('tweets.id') tweets = cols.find({ 'tweet.user.screen_name': name, 'tweet.extended_entities': {'$exists': True}, 'tweet.text': {'$not': re.compile(r'^RT ')}, 'disable': {'$exists': False}, 'pin': {'$exists': False}, }).sort('tweets.id') if edit: users.append({ 'space_num': num, 'user': user, 'tweets_list': [pins, tweets[:30 - pins.count()]], }) else: # editモードでない時は、表示ツイート数を制限する users.append({ 'space_num': num, 'user': user, 'tweets_list': [pins, tweets[:max(0, 6 - pins.count())]], }) return render(request, 'prikoso_2016_circle_checker/index.html', {'users': users, 'edit': edit})
def getByFirstName(self, firstName): collection = MongoClient("localhost").contactDatabase.contactCollection for v in collection.find({'firstName':firstName}): print('matched: ' + str(v))
def getAllDocs(self): collection = MongoClient("localhost").contactDatabase.contactCollection print("find all documents") for v in collection.find(): print('\t' + str(v))