mc_flush(user_id) buzz_at_reply_rm(reply_id) mq_buzz_po_reply_rm = mq_client(buzz_po_reply_rm) def buzz_po_rm(po_id): for user_id in BuzzReply.where(po_id=po_id, state=BUZZ_REPLY_STATE_SHOW).col_list(col='user_id'): mc_flush(user_id) BuzzReply.where(po_id=po_id).update(state=BUZZ_REPLY_STATE_PO_RMED ) mq_buzz_po_rm = mq_client(buzz_po_rm) mc_po_id_list_by_buzz_reply_user_id = McCacheA('PoIdListByBuzzReplyUserId:%s') @mc_po_id_list_by_buzz_reply_user_id('{user_id}') def po_id_list_by_buzz_reply_user_id(user_id): return BuzzReply.where(user_id=user_id, state=BUZZ_REPLY_STATE_SHOW).order_by('update_time desc').col_list(7, 0, 'po_id') def buzz_reply_hide_or_rm(po_id, user_id): buzz = BuzzReply.get(po_id=po_id, user_id=user_id) if buzz: state = buzz.state if state == BUZZ_REPLY_STATE_SHOW : buzz.state = BUZZ_REPLY_STATE_RM buzz.save() from model.po_pos import po_pos_state_mute po_pos_state_mute(buzz.user_id, buzz.po_id)
# (4, '人物 / 对话'), # (5, '资料 / 知识'), # (REDIS_REC_CID_BUZZ, '碎语 / 片段'), ) REDIS_REC_CID_DICT = dict(REDIS_REC_CID_TUPLE) class TagAlias(McModel): #id, tag_id, name #tag_id->cluster index #name -> index pass mc_po_id_list_by_tag_id = McLimitA('PoIdListByTagId.%s', 512) mc_tag_id_list_by_po_id = McCacheA('TagIdListByPoId.%s') zsite_tag_po_count = McNum( lambda tag_id: PoZsiteTag.where(zsite_id=tag_id).count(), 'ZsiteTagPoCount:%s') REDIS_ALIAS = 'TagAlias:%s' REDIS_ALIAS_NAME2ID = 'AliasName2Id' REDIS_TAG_CID = 'TagCid:%s:%s' REDIS_TAG_CID_COUNT = 'TagCid=%s' REDIS_PO_ID2TAG_CID = 'PoId2TagCid' class PoZsiteTag(Model): pass
mc_zsite_id_list_by_zsite_id_state = McLimitA('ZsiteIdListByZsiteIdActive%s', MC_LIMIT_ZSITE_LIST) zsite_list_count_active = McNum( lambda owner_id, cid: ZsiteList.where( cid=cid, owner_id=owner_id, state=STATE_ACTIVE).count(), 'ZsiteListCount%s') zsite_list_count = McNum( lambda owner_id, cid: ZsiteList.where(cid=cid, owner_id=owner_id).where( STATE_EGT_ACTIVE).count(), 'ZsiteListCount%s') zsite_list_count_by_zsite_id = McNum( lambda zsite_id, cid: ZsiteList.where(cid=cid, zsite_id=zsite_id).where( 'owner_id>0').where(STATE_EGT_ACTIVE).count(), 'ZsiteListCountByZsiteId%s') mc_zsite_list_id_state = McCacheA('ZsiteListIdState:%s') class ZsiteList(McModel): pass def zsite_list_active(owner_id, cid, limit=None, offset=None): return Zsite.mc_get_list(zsite_id_list_active(owner_id, cid, limit, offset)) def zsite_list(owner_id, cid, limit=None, offset=None): return Zsite.mc_get_list(zsite_id_list(owner_id, cid, limit, offset))
#mc_pic_new_id_list = McCacheA('PoPicNewIdList.%s') # #@mc_pic_new_id_list('{user_id}') #def pic_new_id_list(user_id): # return PoPic.where(user_id=user_id, po_id=0).order_by('seq desc').col_list() # #def pic_new_list(user_id): # ids = pic_new_id_list(user_id) # li = PoPic.mc_get_list(ids) # for i in li: # i.src219 = fs_url_jpg(i.id, 219) # return li mc_pic_id_list = McCacheA('PoPicIdList.%s') @mc_pic_id_list('{user_id}_{po_id}') def pic_id_list(user_id, po_id): return PoPic.where(user_id=user_id, po_id=po_id).order_by('seq desc').col_list() def pic_list(user_id, po_id): ids = pic_id_list(user_id, po_id) li = PoPic.mc_get_list(ids) return li def pic_list_edit(user_id, po_id):
# -*- coding: utf-8 -*- from _db import Model, McModel, McCache, McCacheA from kv import Kv from txt import txt_property, txt_new from gid import gid from uuid import uuid4 from user_session import id_binary_encode, id_binary_decode import binascii from os import urandom import time oauth_client_uri = Kv('oauth_client_uri') oauth_authorize_code = Kv('oauth_authorize_code') mc_oauth_client_id_by_user_id = McCacheA('OauthClientIdListByUserId.%s') mc_oauth_access_token_verify = McCache('OauthAccessTokenVerify.%s') class OauthAccessToken(Model): pass class OauthClient(McModel): txt = txt_property @property def hex_secret(self): return binascii.hexlify(self.secret)
if po_id not in id_list: id_list.insert(0, po_id) po_review_show.set(id, id_list.tostring()) def po_review_show_rm(id, po_id): id_list = po_review_show_id_list(id) po_id = int(po_id) try: id_list.remove(po_id) except ValueError: pass po_review_show.set(id, id_list.tostring()) mc_po_review_id_list_active_by_zsite_id = McCacheA( 'PoReviewIdListActiveByZsiteId.%s') @mc_po_review_id_list_active_by_zsite_id('{id}') def po_review_id_list_active_by_zsite_id(id): qs = Po.where(zsite_id=id, cid=CID_REVIEW).where( 'state=%s' % STATE_ACTIVE).order_by('id desc') return qs.col_list() def po_review_list_active_by_zsite_id(id): return Po.mc_get_list(po_review_id_list_active_by_zsite_id(id)) if __name__ == '__main__': #po_review_show_id_list_new(1, 2)
from ico import pic_url_bind_with_default from operator import itemgetter from gid import gid from po import Po, po_rm, po_state_set from state import STATE_RM, STATE_SECRET, STATE_ACTIVE, STATE_PO_ZSITE_SHOW_THEN_REVIEW from feed_po import mc_feed_po_dict from mail import mq_rendermail, rendermail from notice import notice_event_yes, notice_event_no, notice_event_join_yes, notice_event_join_no from mq import mq_client from feed import feed_new, mc_feed_tuple, feed_rm from user_mail import mail_by_user_id from days import date_time_by_minute mc_event_id_list_by_zsite_id = McLimitA('EventIdListByZsiteId.%s', 128) mc_event_id_list_by_city_pid_cid = McLimitA('EventIdListByCityPidCid.%s', 128) mc_event_cid_count_by_city_pid = McCacheA('EventCidCountByCityPid.%s') mc_event_end_id_list_by_city_pid = McLimitA('EventEndIdListByCityPid.%s', 128) mc_event_all_id_list = McLimitA('EventAllIdList.%s', 128) event_joiner_new_count = McNum( lambda event_id: EventJoiner.where(event_id=event_id, state=EVENT_JOIN_STATE_NEW).count(), 'EventJoinerCheckCount!%s') mc_event_joiner_by_owner_id = McCacheM('EventJoinerByUserId&%s') event_joiner_feedback_normal_count = McNum( lambda event_id: EventJoiner.where( event_id=event_id, state=EVENT_JOIN_STATE_FEEDBACK_NORMAL).count(), 'EventJoinerFeedbackNormalCount:%s') event_joiner_feedback_good_count = McNum( lambda event_id: EventJoiner.where(
# `zsite_id` INTEGER UNSIGNED NOT NULL, # PRIMARY KEY (`id`), # INDEX `zsite_tag_id`(`zsite_tag_id`, `po_id`), # INDEX `po_id` ( `po_id`,`zsite_id`) #)ENGINE = MyISAM; ZSITE_TAG = ( 1, # 随笔杂记 2, # 愿景计划 3, # 职业感悟 4, # 知识整理 5, # 指点江山 6, # 转载收藏 ) mc_zsite_tag_id_list_by_zsite_id = McCacheA('ZsiteTagIdListByZsiteId.%s') mc_tag_id_list_by_zsite_id = McCacheA('TagIdListByZsiteId:%s') mc_tag_by_po_id = McCacheM('TagIdByPoId:%s') mc_po_id_list_by_zsite_tag_id = McLimitA('PoIdListByZsiteTagId:%s', 128) zsite_tag_count = McNum(lambda id: ZsiteTagPo.where(zsite_tag_id=id).count(), 'ZsiteTagCount:%s') zsite_tag_cid_count = McNum( lambda id, cid: ZsiteTagPo.where(zsite_tag_id=id, cid=cid).count(), 'ZsiteTagCount:%s') mc_po_id_list_by_zsite_tag_id_cid = McLimitA('PoIdListByTagIdCid:%s', 128) mc_zsite_tag_list_by_zsite_id_if_len = McCache('ZsiteTagListByZsiteIdIfLen*%s') class ZsiteTag(McModel): pass
from zkit.attrcache import attrcache from user_mail import mail_by_user_id from mail import rendermail from buzz_reply import mq_buzz_po_reply_rm, mq_buzz_po_reply_new REPLY_STATE = ( STATE_RM, STATE_APPLY, STATE_ACTIVE, ) mc_reply_id_list = McLimitA('ReplyIdList:%s', 512) mc_reply_id_list_reversed = McLimitA('ReplyIdListReversed:%s', 512) mc_reply_count = McCache('ReplyCount:%s') #mc_reply_in_1h = McCache('ReplyInOneHour.%s') mc_reply_zsite_id_list = McCacheA('ReplyZsiteIdList:%s') class ReplyMixin(object): reply_cursor = cursor_by_table('reply') @mc_reply_zsite_id_list('{self.cid}_{self.id}') def reply_zsite_id_list(self): id_set = set() id_set.update(i.user_id for i in self.reply_list()) return list(id_set) def reply_new(self, user, txt, state=STATE_ACTIVE, create_time=None): from zsite import user_can_reply user_id = user.id cid = self.cid
PoPos.where(po_id=po_id, state=STATE_BUZZ).col_list(col="user_id")) def po_pos_get_last_reply_id(user_id, po_id): return po_pos_get(user_id, po_id)[0] @mc_po_pos('{user_id}_{po_id}') def po_pos_get(user_id, po_id): p = PoPos.get(user_id=user_id, po_id=po_id) if p: return p.pos, p.state return -1, STATE_MUTE mc_po_viewed_list = McCacheA('PoViewedList.%s') @mc_po_viewed_list('{po_id}') def po_viewed_list(po_id): qs = PoPos.where(po_id=po_id).order_by('id desc').col_list(col="user_id") return qs def po_buzz_list(po_id): qs = PoPos.where(po_id=po_id, state=STATE_BUZZ) return [i.user_id for i in qs] def po_pos_mark(user_id, po): _po_pos(
# -*- coding: utf-8 -*- from _db import cursor_by_table, McModel, McCache, McNum, McCacheA from cid import CID_PRODUCT, CID_PRODUCT_PIC from state import STATE_SECRET, STATE_ACTIVE from spammer import is_same_post from po import Po, _po_rm, po_new, po_id_list, po_list_count, po_view_list import json from zsite_show import zsite_show_list from itertools import chain from txt import txt_new, txt_get, txt_property from pic import pic_new, pic_save, PicMixin from fs import fs_set_jpg, fs_url_jpg from zkit.pic import pic_fit_width_cut_height_if_large mc_product_id_list_by_com_id = McCacheA('ProductIdListByComId:%s') def po_product_new(user_id, name, _info_json, zsite_id=0, state=STATE_ACTIVE): if not name and not _info_json: return info_json = json.dumps(dict(iter(_info_json))) if not is_same_post(user_id, name, info_json, zsite_id): m = po_new(CID_PRODUCT, user_id, name, state, 0, None, zsite_id) if m: txt_new(m.id, info_json) mc_product_id_list_by_com_id.delete(zsite_id) return m def po_product_update(po_id, _info_json):
#!/usr/bin/env python # -*- coding: utf-8 -*- from _db import McModel, McCache, cursor_by_table, McCacheA, McCacheM from oauth_update import sync_by_oauth_id from config import SITE_DOMAIN from cid import CID_EVENT, CID_NOTE, CID_WORD, CID_AUDIO, CID_VIDEO, CID_PHOTO, CID_REVIEW from zkit.txt import cnencut from mq import mq_client from model.zsite import Zsite from oauth_follow import oauth_follow_by_oauth_id from model.po import Po mc_sync_state = McCache('SyncState:%s') mc_sync_state_all = McCacheA('SyncStateAll:%s') SYNC_CID_WORD = 1 SYNC_CID_NOTE = 2 SYNC_CID_EVENT = 3 SYNC_CID_SHARE = 4 SYNC_CID_REVIEW = 5 SYNC_CID_CN = ( (SYNC_CID_WORD, '游吟碎语'), (SYNC_CID_NOTE, '文章影音'), (SYNC_CID_EVENT, '线下活动'), (SYNC_CID_SHARE, '推荐分享'), (SYNC_CID_REVIEW, '公司评价'), ) SYNC_GET_CID = { CID_WORD: SYNC_CID_WORD,
#!/usr/bin/env python # -*- coding: utf-8 -*- from _db import Model, McModel, McCache, cursor_by_table, McCacheA, McLimitA, McNum, McCacheM from zsite import Zsite from gid import gid from days import ONE_DAY from zsite_url import name_dict_url_dict_by_zsite_id_list from model.cid import CID_USER from zkit.mc_func import mc_func_get_dict_with_key_pattern follow_count_by_to_id = McNum(lambda to_id: Follow.where(to_id=to_id).count(), 'FollowCountByToId.%s') follow_count_by_from_id = McNum(lambda from_id: Follow.where(from_id=from_id).count(), 'FollowCountByFromId.%s') mc_follow_id_list_by_to_id = McLimitA('FollowIdListByToId.%s', 128) mc_follow_id_list_by_from_id_cid = McCacheA('FollowIdListByFromIdCid.%s') mc_follow_id_list_by_from_id = McCacheA('FollowIdListByFromId.%s') mc_follow_get = McCache('FollowGet<%s') mc_following_id_rank_tuple = McCacheM('FollowingIdRankTuple.%s') class Follow(Model): pass follow_cursor = cursor_by_table('follow') @mc_follow_id_list_by_to_id('{to_id}') def follow_id_list_by_to_id(to_id, limit, offset): follow_cursor.execute('select from_id from follow where to_id=%s order by id desc limit %s offset %s', (to_id, limit, offset)) return [i for i, in follow_cursor] @mc_follow_id_list_by_from_id('{from_id}') def follow_id_list_by_from_id(from_id):
#!/usr/bin/env python # -*- coding: utf-8 -*- from _db import Model, McModel, McCache, McCacheA, McLimitM, McNum from gid import gid class BuzzSys(McModel): pass mc_buzz_sys_init_id_list = McCacheA('BuzzSysInitIdList.%s') @mc_buzz_sys_init_id_list('') def buzz_sys_init_id_list(): return BuzzSys.where('seq>0').order_by('seq').col_list() def buzz_sys_init_list(): id_list = buzz_sys_init_id_list() return BuzzSys.mc_get_list(id_list) def buzz_sys_list(limit, offset): return BuzzSys.where().order_by('id desc')[offset:limit + offset] def buzz_sys_count(): return BuzzSys.where().count()
#!/usr/bin/env python # -*- coding: utf-8 -*- from _db import McModel, McCache, cursor_by_table, McCacheA, McCacheM from zkit.algorithm.merge import imerge from state import STATE_ACTIVE from feed import PAGE_LIMIT mc_feed_user_dict = McCacheM('FeedUserDict.%s') mc_feed_po_iter = McCacheA('FeedPoIter.%s') mc_feed_po_dict = McCacheM('FeedPoDict.%s') cursor = cursor_by_table('po') FEED_PO_ID_LASTEST_SQL = 'select id from po where user_id=%%s and state=%s order by id desc limit %s' % ( STATE_ACTIVE, PAGE_LIMIT) FEED_PO_ID_ITER_SQL = 'select id from po where user_id=%%s and state=%s and id<%%s order by id desc limit %s' % ( STATE_ACTIVE, PAGE_LIMIT) @mc_feed_po_iter('{feed_id}') def feed_po_id_lastest(feed_id): cursor.execute(FEED_PO_ID_LASTEST_SQL, feed_id) return [i for i, in cursor.fetchall()] def feed_po_iter(zsite_id, start_id=None): if start_id is None: id_list = feed_po_id_lastest(zsite_id) if id_list: for i in id_list: yield i
#!/usr/bin/env python # -*- coding: utf-8 -*- from _db import Model, McModel, McCache, McLimitM, McNum, McCacheA, McCacheM, McCacheA from zkit.job import JOBKIND2CN from zkit.school_university import SCHOOL_UNIVERSITY, SCHOOL_UNIVERSITY_DEPARTMENT_ID2NAME, SCHOOL_DEGREE from json import dumps from model.zsite import Zsite from zkit.mc_func import mc_func_get_list from model.zsite_rank import zsite_rank mc_user_school_id_list = McCacheA('UserSchoolIdList:%s') mc_user_school_tuple = McCacheM('UserSchoolTuple:%s') mc_user_school_dict = McCacheM('UserSchoolDict<%s') class UserSchool(McModel): pass user_school_count = McNum( lambda school_id: UserSchool.raw_sql( 'select count(distinct(user_id)) from user_school where school_id=%s', school_id).fetchone()[0], 'UserSchoolCount:%s') user_school_year_count = McNum( lambda school_id, year: UserSchool.where(school_id=school_id, school_year=year).count(), 'UserSchoolYearCount:%s') def mc_flush(user_id, school_id=0, year=0):
def _po_event_notice_new(user_id, event_id, name): o = po_new(CID_EVENT_NOTICE, user_id, name, STATE_ACTIVE, event_id) return o def po_event_notice_new(user_id, event_id, name): o = _po_event_notice_new(user_id, event_id, name) if o: from notice import mq_notice_event_notice mq_notice_event_notice(user_id, event_id, o.id) mc_po_event_notice_id_list_by_event_id.delete(event_id) return o mc_po_event_notice_id_list_by_event_id = McCacheA( 'PoEventNoticeIdListByEventId:%s') @mc_po_event_notice_id_list_by_event_id('{event_id}') def po_event_notice_id_list_by_event_id(event_id): from state import STATE_ACTIVE return Po.where(cid=CID_EVENT_NOTICE, rid=event_id).where( 'state>=%s' % STATE_ACTIVE).order_by('id desc').col_list() def po_event_notice_list_by_event_id(event_id): return Po.mc_get_list(po_event_notice_id_list_by_event_id(event_id)) if __name__ == '__main__': pass
#!/usr/bin/env python # -*- coding: utf-8 -*- from _db import Model, McModel, McCache, McNum, McCacheA, McCacheM, McCacheA from zkit.job import JOBKIND2CN from zsite_com import pid_by_com_id from zkit.attrcache import attrcache mc_job_type_by_job_id = McCacheA('JobTypeByJobId:%s') mc_job_kind_by_job_id = McCacheA('JobKindByJobId:%s') mc_com_job_id_list_by_com_id_state = McCacheA('ComJobIdListByComIdState:%s') JOBTYPE = ( (1, '兼职'), (2, '实习生'), (3, '全职'), (4, '合伙人'), ) JOB_ACTIVE = 5 JOB_CLOSE = 3 JOB_RM = 0 JOB_STATE = (JOB_ACTIVE, JOB_CLOSE, JOB_RM) SALARY_TYPE = ((1, '月薪'), (2, '年薪')) SALARY_TYPE2CN = dict(SALARY_TYPE) JOBTYPE2CN = dict(JOBTYPE) class ComJobNeeds(McModel): pass
#!/usr/bin/env python # -*- coding: utf-8 -*- from _db import cursor_by_table, McModel, McCache, McNum, McCacheA from zsite import Zsite from model.cid import CID_SITE from zkit.algorithm.wrandom import sample_or_shuffle from model.zsite_list import zsite_list_new, STATE_ACTIVE, zsite_list_get, zsite_list_id_get, zsite_list_rm, zsite_list_count_by_zsite_id, zsite_list_id_state, ZsiteList, zsite_id_list_by_zsite_id, mc_zsite_list_id_state, STATE_ACTIVE, STATE_ADMIN, STATE_OWNER mc_zsite_id_list_by_admin_id = McCacheA('ZsiteIdListBYAdminId.%s') mc_admin_id_list_by_zsite_id = McCacheA('AdminIdListByZsiteId.%s') zsite_by_admin_id_count = McNum( lambda id: ZsiteList.where(cid=CID_SITE, owner_id=id).where( 'state>%s' % STATE_ADMIN).count(), 'ZsiteByAdminIdTotal.%s') def zsite_admin_new(zsite_id, admin_id, state=STATE_OWNER): if zsite_id and admin_id: cid = CID_SITE zsite = zsite_list_get(zsite_id, admin_id, cid) if not zsite: zsite = zsite_list_new(zsite_id, admin_id, cid, 1, state) else: zsite.state = state zsite.save() mc_flush(zsite_id, admin_id) def mc_flush(zsite_id, admin_id): mc_admin_id_list_by_zsite_id.delete(zsite_id) mc_zsite_id_list_by_admin_id.delete(admin_id)
from zkit.mc_func import mc_func_get_dict from spammer import anti_same_post from zkit.school_university import SCHOOL_UNIVERSITY, SCHOOL_UNIVERSITY_DEPARTMENT_ID2NAME CID_JOB = 1 CID_EDU = 2 CID_TUPLE = ( (CID_JOB, 'job'), # (CID_EDU, 'edu'), ) CID_NAME = dict(CID_TUPLE) CID_BY_STR = dict((v, k) for k, v in CID_TUPLE) mc_career_id_list = McCacheA('CareerIdListCid.%s') mc_career_current = McCacheM('CareerCurrent.%s') def end_cmp(a, b): if a == 0: if b == 0: return 0 return 1 if b == 0: return -1 return cmp(a, b) def begin_cmp(a, b): if a == 0: if b == 0: return 0
#coding:utf-8 from _db import cursor_by_table, McModel, McLimitA, McCache, McNum, Model, McCacheM, McCacheA from po import Po, PO_CID from model.state import STATE_PO_ZSITE_REVIEW_THEN_SHOW, STATE_PO_ZSITE_SHOW_THEN_REVIEW from model.feed_render import render_zsite_feed_list PAGE_LIMIT = 25 #mc_pos_id_list_by_cid = McCacheM("PosIdListByCid:%s") mc_po_count_by_zsite_id = McCacheA('PoCountByZsiteId:%s') mc_po_id_list_by_zsite_id = McLimitA('PoIdListByZsiteId.%s', 512) def _po_cid_count_by_zsite_id(zsite_id, cid): qs = Po.where(zsite_id=zsite_id).where('state>=%s' % STATE_PO_ZSITE_SHOW_THEN_REVIEW) if cid: qs = qs.where(cid=cid) return qs.count() po_cid_count_by_zsite_id = McNum(_po_cid_count_by_zsite_id, 'PoIdCount:%s') @mc_po_count_by_zsite_id('{zsite_id}') def _po_count_by_zsite_id(zsite_id): return tuple(po_cid_count_by_zsite_id(zsite_id, i) for i in PO_CID) def po_count_by_zsite_id(zsite_id): return zip(PO_CID, _po_count_by_zsite_id(zsite_id))