def get_blog_reposts(cls, weibo_id, raw=False): """获得一条微博的转发""" db = DB.get_crawlerdb() cookies_id, cookies = Cookies.get_cookies(cls.cookies_policies, cls.cookies_type, db) if not cookies: return None params = { 'id': weibo_id } url = 'https://m.weibo.cn/api/statuses/repostTimeline' reposts = [] for page_id in range(1, 2): params['page'] = page_id r = requests.get(url, params=params, cookies=cookies, timeout=3) Cookies.update_cookies(cookies_id, cls.cookies_type, r, db) raw_result = r.json() if raw_result["ok"] is 0: raise RequestException(raw_result['msg']) else: raw_data = raw_result["data"] if raw: reposts += raw_data['data'] else: for l in raw_data['data']: reposts.append(WeiboAPI.parse_raw_blog(l)) return reposts
def get_blog_detail(cls, weibo_id, raw=False): """ 获得一条微博详细信息。 :param raw: 是否返回raw data :param weibo_id: 微博id """ db = DB.get_crawlerdb() cookies_id, cookies = Cookies.get_cookies(cls.cookies_policies, cls.cookies_type, db) if not cookies: return None url = 'https://m.weibo.cn/statuses/show?id={}'.format(weibo_id) r = requests.get(url, cookies=cookies, timeout=3) Cookies.update_cookies(cookies_id, cls.cookies_type, r, db) raw_result = r.json() if raw_result["ok"] is 0: raise RequestException(raw_result['msg']) else: if raw: return raw_result else: raw_blog = raw_result["data"] blog = WeiboAPI.parse_raw_blog(raw_blog) return blog
def get_user_blogs(cls, uid, raw=False): """Ta发的微博""" db = DB.get_crawlerdb() cookies_id, cookies = Cookies.get_cookies(cls.cookies_policies, cls.cookies_type, db) if not cookies: return None params = { 'type': uid, 'value': uid, 'containerid': '107603{}'.format(uid), 'uid': uid } blogs = [] for page_id in range(1, 2): params['page'] = page_id r = requests.get(cls.BASE_URL, params=params, cookies=cookies, timeout=3) Cookies.update_cookies(cookies_id, cls.cookies_type, r, db) raw_result = r.json() if raw_result["ok"] is 0: raise RequestException(raw_result['msg']) else: if raw: blogs.append(raw_result) else: for item in raw_result["data"]["cards"]: if item["card_type"] == 9: raw_blog = item["mblog"] blog = WeiboAPI.parse_raw_blog(raw_blog) blogs.append(blog) return blogs
def get_user_following(cls, uid): """Ta关注的人""" uid = '%d' % float(uid) db = DB.get_crawlerdb() cookies_id, cookies = Cookies.get_cookies(cls.cookies_policies, cls.cookies_type, db) if not cookies: return [] params = { 'luicode': '10000011', 'lfid': '100505{}'.format(uid), 'containerid': '231051_-_followers_-_{}'.format(uid), 'featurecode': '20000320', 'type': 'uid', 'value': uid } followed_id_list = [] for page_id in range(1, 2): params['page'] = page_id r = requests.get(cls.BASE_URL, params=params, cookies=cookies, timeout=3) Cookies.update_cookies(cookies_id, cls.cookies_type, r, db) raw_result = r.json() if raw_result["ok"] is 0: raise RequestException(raw_result['msg']) else: if raw_result['data'].get('cards'): for card in raw_result['data']['cards']: for u in card['card_group']: if u['card_type'] == 10: followed_id_list.append(u["user"]["id"]) return followed_id_list
def get_user_info(cls, uid, raw=False): """获取用户基础信息""" uid = '%d' % float(uid) db = DB.get_crawlerdb() cookies_id, cookies = Cookies.get_cookies(cls.cookies_policies, cls.cookies_type, db) if not cookies: return [] params = { 'containerid': '100505{}'.format(uid), 'type': 'uid', 'value': uid } r = requests.get(cls.BASE_URL, params=params, cookies=cookies, timeout=3) Cookies.update_cookies(cookies_id, cls.cookies_type, r, db) raw_result = r.json() if raw_result["ok"] is 0: raise RequestException(raw_result['msg']) else: if raw: return raw_result else: user_info_raw = raw_result["data"]["userInfo"] user_info = WeiboAPI.parse_user_info(user_info_raw) return user_info
def profile(user): if not cookies.contains('user'): return redirect(url_for('start')) profile_ctr.set_cookies(cookies) info = login.get_profile_data(user)[0] if profile_ctr.check_role_permissions(user, info, cookies): return redirect( url_for('index', user=cookies.get('user'), group=cookies.get('group'), page=1, month=datetime.now().month, year=datetime.now().year)) (current, rest) = profile_ctr.current_roles(user) if request.method == 'POST': if 'bonus' in request.form: if request.form['until'] != '' and request.form['comment'] != '': d = datetime.strptime(request.form['until'], '%Y-%m-%d') if request.form['bonus'].isnumeric() and int( request.form['bonus']) > 0 and d > datetime.today(): seconds = time_conversion.hours_to_seconds( int(request.form['bonus'])) profile_ctr.add_quota_bonus(user, seconds, request.form['comment'], request.form['until']) flash(msg.request_sent_successfully(cookies.get('lang'))) else: flash('error') else: flash('error') return redirect(url_for('profile', user=user)) flags = Cookies(cookies.get('is_field_mod')) profile_ctr.set_flags(flags, request.form) if profile_ctr.execute_if_modification(user, flags, request.form): return redirect(url_for('profile', user=user)) (flag, msg) = profile_ctr.save_profile_action(user, request.form, info[-1], cookies) if not msg == '': flash(msg) return redirect(url_for('profile', user=user)) info[2] = db.query( 'select areaname from Areas where area = \'{0}\''.format( info[2]))[0][0] return render_template( 'profile.html', word=get_words, data=info, rol=current, roles=rest, user=user, group=login.get_basic_info(user)[0][-1], is_modifyer=(info[0] == cookies.get('user') or not (cookies.get('roles')['is_dean'] or cookies.get('roles')['is_ddi'])), mod_pwd=cookies.get('modify'), flags=cookies.get('is_field_mod'))
def get_blog_comments(cls, weibo_id, raw=False): """ 获得一条微博下的评论。 分页接口,一次只拿20个。 :param weibo_id: 微博的id :param raw: 是否返回raw data """ db = DB.get_crawlerdb() cookies_id, cookies = Cookies.get_cookies(cls.cookies_policies, cls.cookies_type, db) if not cookies: return None params = { 'id': weibo_id, 'mid': weibo_id } url = 'https://m.weibo.cn/comments/hotflow' comments = [] for _ in range(1, 2): r = requests.get(url, params=params, cookies=cookies, timeout=3) Cookies.update_cookies(cookies_id, cls.cookies_type, r, db) raw_result = r.json() if raw_result["ok"] is 0: raise RequestException(raw_result['msg']) else: raw_data = raw_result["data"] params['max_id'] = raw_data["max_id"] params['max_id_type'] = raw_data['max_id_type'] if raw: comments += raw_data['data'] else: for c in raw_data['data']: comments.append(WeiboAPI.parse_raw_blog(c)) return comments
from languages.interface import get_words from utils import query_builder as qb from utils.cookies import Cookies import os from settings import database as db from settings import encryption as cr from utils import userinfo, time_conversion from datetime import datetime from controllers import main, login, index_ctr, request_ctr, profile_ctr, search_ctr, remove_ctr, create_ctr, pending_ctr, logout_ctr, authorize_ctr, password_ctr import pdfkit app = Flask(__name__) app.secret_key = str(os.urandom(24)) main.init_app(app) cookies = Cookies(session) mail = Mail(app) @app.route('/', methods=['GET', 'POST']) def start(): if cookies.contains('user'): return redirect( url_for('index', user=cookies.get('user'), group=cookies.get('group'), page=1, month=datetime.now().month, year=datetime.now().year)) login.set_cookies(cookies) if request.method == 'GET':