def onClose(self, wasClean, code, reason): try: self.user[communication_keys.websocket_ts_end] = int(time.time()) self.user.save() print 'connection close', fixed.lingo_since( self.user, communication_keys.websocket_ts_start), self.user._data except Exception as e: print 'disassociate exception:', e try: print self.user._data except: pass self.factory.disassociate(self)
def process_add(self, new_player, curator, league): print 'try to find old cut-', curator[user_keys.user_role], league[ keys.entity_league] history_last_cut = EntityHistory().last_cut( new_player[keys.entity_profile], league[keys.entity_league]) if history_last_cut: print 'found cut instance:', fixed.lingo_since( history_last_cut, time_keys.ts_cut) for key in [ k for k in history_last_cut.keys() if k in keys.social_keys ]: if history_last_cut[key] and key != keys.entity_match_twitter: print 'cut player with key:', key, 'adding to new player:', history_last_cut[ key] if key == keys.entity_twitter_id: new_player[key] = str(history_last_cut[key]) else: new_player[key] = history_last_cut[key] else: print 'never been cut' new_player[keys.entity_league] = league[keys.entity_league] new_player[keys.entity_site] = curator[user_keys.user_role] print new_player try: Entity().put_item(new_player) addtweet = tweets.add_tweet(new_player, curator, league) try: print 'add tweet:', addtweet except: pass message = {} message.update(new_player) message[twitter_keys.message_tweet] = addtweet return message except Exception as e: print 'already exists:', e
def scout_report(sr): for index, league in enumerate(sr): print '{:3s}'.format(str(index+1)), '{:6s}'.format('True' if league[user_keys.user_locked] else 'False'), '{:20s}'.format(league[user_keys.user_role]), 'since scouted:', fixed.lingo_since(league, time_keys.ts_pin)
def bible_report(sr): for index, league in enumerate(sr): print '{:3s}'.format(str(index + 1)), '{:20s}'.format( league[user_keys.user_role]), 'since scraped:', fixed.lingo_since( league, time_keys.ts_bible)
def stalk_report(sl): for index, league in enumerate(sl): print '{:3s}'.format(str(index + 1)), '{:20s}'.format( league[user_keys.user_role]), 'since stalked:', fixed.lingo_since( league, time_keys.ts_stalked)
def start(self): self.twitter_initialize() print 'called stalk:', self.role[1], fixed.lingo_since( self.user, time_keys.ts_stalked) self.signin()
def stalk_done(self): print 'stalk_done previous:', fixed.lingo_since( self.user, time_keys.ts_stalked) self.user[time_keys.ts_stalked] = int(time.time()) print 'considered stalked' self.user.partial_save()
def stalk_analysis(league_name): mutuals = [] extras = [] for mf in Entity().query_2(league__eq=league_name): if 'twitter' in mf and 'ts_followers_' + league_name in mf: try: ts_add = None if mf[time_keys.ts_scout]: ts_add = mf[time_keys.ts_scout] slt = ProfileTwitter().profile_last(mf[keys.entity_twitter_id], None, ts_add) if slt is not None: print 'append:', mf[keys.entity_twitter], 'since:', fixed.lingo_since_date(ts_add) mutuals.append( (mf, slt) ) else: print 'no last stats:', mf[keys.entity_twitter], mf[keys.entity_twitter_id] except Exception as e: print 'missing:', e, 'https://twitter.com/' + mf[keys.entity_twitter], fixed.lingo_since(mf, twitter_keys.league_ts_followers(league_name)) else: extras.append(mf._data) print 'extras length:', len(extras) for mutual_seq in mutuals: try: mutual = mutual_seq[0] mutual_slt = mutual_seq[1] print 'mutual:', mutual[keys.entity_twitter] tf = set([]) for other_seq in [others for others in mutuals if others[0] != mutual and twitter_keys.league_mutual(league_name) in others[1]]: if mutual[keys.entity_twitter_id] in other_seq[1][twitter_keys.league_mutual(league_name)]: tf.add(other_seq[0][keys.entity_twitter_id]) if len(tf) > 0: print mutual[keys.entity_twitter], 'follows:', len(tf), 'following:', 0 if twitter_keys.league_mutual(league_name) not in mutual_slt else len(mutual_slt[twitter_keys.league_mutual(league_name)]) mutual_slt[twitter_keys.league_follows(league_name)] = tf mutual_slt.partial_save() else: print 'not following anyone:', mutual[keys.entity_twitter], mutual[keys.entity_twitter_id] except Exception as e: print 'mutual exception:', e publish = [] curator = User().get_curator(league_name) for mutual_seq_2 in mutuals: try: p = {} mutual = mutual_seq_2[0] p.update(mutual._data) mutual_slt = mutual_seq_2[1] p.update(mutual_slt._data) publish.append(p) except: print 'mutual exception:', e b = s3.bucket_straight(curator[user_keys.user_role]) filename = league_name + '/db/bible.json' meta = shared.entity_filter(curator._data) output = shared.dump(publish + extras) s3.save_s3(b, filename, output , None, content_type='application/json', acl='public-read', meta=meta, encode='gzip')