from ReadWeibo.account.models import Account from ReadWeibo.mainapp.models import Weibo from main import Config, WeiboCrawler from libweibo import weibo from time import sleep import itertools import datetime import thread import re _DEBUG = True _mimetype = u'application/javascript, charset=utf8' wclient = weibo.APIClient(app_key=Config.weibo_app_key, app_secret=Config.weibo_app_secret, redirect_uri=Config.callback_url) def home(request, category_id=0): template_var = {} print 'current login user: ', request.user if request.user.is_authenticated() and not request.user.is_superuser: user = Account.objects.get(w_name=request.user.username) # fetch new weibo if category_id == 0: thread.start_new_thread(WeiboCrawler.CrawleHomeTimeline, (user.w_uid, )) watch_weibo = user.watchweibo.filter( real_category__exact=category_id)[:20]
@author: plex ''' from ReadWeibo.account.models import Account from ReadWeibo.mainapp.models import Weibo from djangodb.CommentDao import CommentDao from djangodb.WeiboDao import WeiboDao from django.db.models import Count from libweibo import weibo from main import Config from datetime import datetime, timedelta from time import sleep import traceback import logging wclient = weibo.APIClient(app_key = '3826768764', app_secret = '7eb7e1c82280f31db8db14cbd0895505', redirect_uri = 'http://42.121.117.9/atRec/callback.jsp') wclient.set_access_token('2.00b6R5mBq3jyKE94bbf64dc40Z6k1J', '1394823602435') _request_interval = .5 # secodes def fetch_user_timeline(w_uid, append=True, max_count=1000): ''' 获取当前用户所发布的微博,需要授权 ''' try: user = Account.objects.get(w_uid=w_uid) except Exception: logging.error('no user found for id:%s' % w_uid) return
from ReadWeibo.account.models import Account from main import Config from ranking import DataUtil as du from ranking.ManifoldRank import ManifoldRank from libweibo import weibo from time import sleep import traceback import datetime import logging master = Account.objects.get(w_uid=3887027625) #underfitting target_category = Category.objects.get(category_id=1) wclient = weibo.APIClient(app_key=Config.WEIBO_API['app_key'], app_secret=Config.WEIBO_API['app_secret'], redirect_uri=Config.WEIBO_API['callback_url']) wclient.set_access_token(master.oauth.access_token, master.oauth.expires_in) def rank(): G = du.gen_graph(save_path=None, max_cnt=500) mr = ManifoldRank(G) mr.rank() mr.classify(update=True) def follow_others(): users_to_follow = Account.objects.order_by("-relevance")[:10]
from ReadWeibo.mainapp.models import Category, Weibo from ReadWeibo.account.models import Account from djangodb.WeiboDao import WeiboDao from djangodb.CommentDao import CommentDao from libweibo import weibo from main import Config from django.db.models import Count from django.db.models import F from datetime import datetime, timedelta import logging import time # use ggzz's app key and auth wclient = weibo.APIClient(app_key='3233912973', app_secret='289ae4ee3da84d8c4c359312dc2ca17d') wclient.set_access_token(u'2.00l9nr_DfUKrWDf655d3279arZgVvD', u'1539839324') #beidou #wclient = weibo.APIClient(app_key = '3826768764', # app_secret = '7eb7e1c82280f31db8db14cbd0895505', # redirect_uri = 'http://42.121.117.9/atRec/callback.jsp') #wclient.set_access_token('2.00Zr3qxBq3jyKEcaa408b07cWAXF7E', '1394823602178') _request_interval = .6 # secodes def crawl_cmt_repost(user, limit=10000, update_interval=timedelta(days=2)): weibos = user.ownweibo.filter(created_at__lt=datetime.now()-update_interval).\ filter(last_update_cmt_repost__lt=F('created_at')+ update_interval)[:limit]