示例#1
0
文件: webapp.py 项目: thinkluffy/nfg
def get_newsfeed():
    signed_request = request.form.get('signed_request')
    logging.info('signed_request=' + signed_request)
    result = get_token(signed_request, FB_APP_SECRET)
    if not result:
        return render_template('login.html', app_id=FB_APP_ID, namespace='newsfeedguardian')

    (user_id, access_token, expires) = result

    logging.info('access_token=' + str(access_token))

    channel_url = url_for('get_channel', _external=True)
    channel_url = channel_url.replace('http:', '').replace('https:', '')
    
    if access_token:
        db.insert_user_info(user_id, access_token, expires)
        last_scan_time = db.get_last_scan_time(user_id)

        feeds = fb_call('me/home', args={'access_token': access_token})

        scaned_feeds = scan_feeds(feeds, access_token, last_scan_time)
        db.update_last_scan_time(user_id, int(time.time()))
        return render_template('newsfeedlist.html', app_id=FB_APP_ID, token=access_token, url=request.url, 
            channel_url=channel_url, name=FB_APP_NAME, feeds=scaned_feeds)
    else:
        return render_template('login.html', app_id=FB_APP_ID, url=request.url, 
            channel_url=channel_url, name=FB_APP_NAME, namespace='newsfeedguardian')
示例#2
0
文件: rating.py 项目: thinkluffy/nfg
	def run(self):
		logging.info('[worker] worker started')
		while not self.stop:
			logging.debug('[worker] perform one loop')

			uri = db.mongodb_uri()
			conn = Connection(uri)
			users = conn.db['users']

			current = int(time.time())

			for user in users.find():
				user_id = user.get('user_id')
				access_token = user.get('access_token')
				expires = user.get('expires')
				last_scan_time = user.get('last_scan_time', 0)
				if not access_token:
					continue

				if expires > 0  and expires < current:
					logging.debug('[worker] expires time smaller than current time')
					continue

				# logging.debug('[worker] last_scan_time={0}, current={1}'.format(last_scan_time, current))
				# if last_scan_time > current:
				# 	logging.debug('[worker] last_scan_time:{0} greater than current time'.format(last_scan_time))
				# 	continue

				logging.info('[worker] scan news feed for user_id: ' + user_id)
				feeds = fb_call('me/home', args={'access_token': access_token})
				scan_feeds(feeds, access_token, last_scan_time)
				db.update_last_scan_time(user_id, int(time.time()))

			time.sleep(30)