def update_share_holders(): db = dbcon.connect_torndb() mongo = dbcon.connect_mongo() investors = set(dbutil.get_online_investors(db)) & set( dbutil.get_famous_investors(db)) investors = { iid: [i[1] for i in dbutil.get_investor_gongshang_with_ids(db, iid)] for iid in investors } with codecs.open('cach/famous.new', 'w', 'utf-8') as fo: for iid, imajias in investors.iteritems(): iname = dbutil.get_investor_name(db, iid) for majia in imajias: try: gs = mongo.info.gongshang.find_one({'name': majia}) if not gs: continue share_holers = gs.get('investors', []) share_holers = [ i.get('name') for i in share_holers if i.get('name') not in imajias ] share_holers = [i for i in share_holers if len(i) > 5] if not share_holers: fo.write('%s\t%s\n' % (iname, majia)) else: for sh in share_holers: fo.write('%s\t%s\t%s\n' % (iname, majia, sh)) except Exception, e: print majia, e
def __source_gongshang(db, mongo, yesterday): global loggers known_vcs = dbutil.get_investor_alias_with_ids( db, *dbutil.get_famous_investors(db)) for tpc in db.query( 'select * from topic_company where topicId=44 and (active is null or active="Y") ' 'and publishTime>%s', yesterday): gongshang = db.get( 'select relateId, detailId from company_message where trackDimension=5001 and companyId=%s ' 'order by publishTime desc limit 1', tpc.companyId) try: changes = {} ginfo = mongo.info.gongshang.find_one({ '_id': ObjectId(gongshang.relateId) }).get('changeInfo', []) change = filter( lambda x: x.get('id', -1) == int(gongshang.detailId), ginfo)[0] for iid, vc in known_vcs: if vc in change.get('contentAfter', '') and vc not in change.get( 'contentBefore', ''): changes.setdefault(tpc.companyId, []).append(iid) for cid, iids in changes.items(): inames = ','.join( [dbutil.get_investor_name(db, iid) for iid in set(iids)]) dbutil.update_extract_source_company(db, 67003, None, cid, gongshang.relateId, True, inames) except Exception, e: loggers.exception('Failed gongshang, %s, %s' % (tpc.companyId, e))
def build_fund_organization(self, session): for iid, alias in dbutil.get_investor_gongshang_with_ids( self.db, *dbutil.get_famous_investors(self.db)): gs = self.mongo.info.gongshang.find_one({'name': alias}) if not gs: continue self.__merge_gongshang(gs, session) self.__merge_investor(iid, alias, session)
def cmp_fi(): fio = dicts.get_known_angels() db = dbcon.connect_torndb() fin = dbutil.get_famous_investors(db) diff = [i for i in fio if i not in fin] for i in diff: investor = dbutil.get_investor_info(db, i) if investor.active is None or investor.active == 'Y': print i, investor.name
def feed_invests(self): """ check investors' new invests companies """ vcs = { vc: iid for iid, vc in dbutil.get_investor_gongshang_with_ids( self.db, *dbutil.get_famous_investors(self.db)) } for gongshang in self.mongo.info.gongshang.find({ 'name': { '$in': vcs.keys() }, 'invests': { '$ne': [] } }): diffs = [ i.get('name') for i in gongshang.get('invests', []) if i.get('new') ] for diff in diffs: cids = dbutil.get_cid_from_gongshang(self.db, diff) # found one with gongshang change if cids: self.send_msg( 'gongshang_detect', json.dumps({ 'name': diff, 'type': 'update', 'investor_name': gongshang['name'], 'investor_id': vcs.get(gongshang['name']), 'posting_time': datetime.now().strftime('%Y-%m-%d:%H:%M:%S') })) else: self.send_msg( 'gongshang_detect', json.dumps({ 'name': diff, 'type': 'new', 'investor_name': gongshang['name'], 'investor_id': vcs.get(gongshang['name']), 'posting_time': datetime.now().strftime('%Y-%m-%d:%H:%M:%S') })) self.mongo.info.gongshang.update( { '_id': gongshang['_id'], 'invests': { '$elemMatch': { 'new': True } } }, {'$set': { 'invests.$.new': False }}, False, True)