示例#1
0
    def get(self, **kw):
        helper = RequestHelper(self)
        result = {}

        today = datetime.combine(datetime.now(), time(0, 0, 0))
        result['timestamp'] = str(datetime.now())
        result['today'] = str(today)

        warnings = []
        result['warnings'] = warnings

        # source/artifact counts
        result[
            'source_artifact_counts'] = ArtifactSourceAccessor.find_artifact_counts(
            )

        # new artifacts
        result[
            'new_artifacts'] = ArtifactSourceAccessor.find_artifact_counts_newer(
                today)

        # newer_arts = ArtifactAccessor.find_newer(today, refresh=True)

        # new_art_stats = []
        # result['new_artifacts'] = new_art_stats

        # for art in newer_arts:
        #     new_art_stats.append(dict(guid=art.guid, source_name=art.source_name))

        # memcache stats
        result['memcache'] = memcache.get_stats()

        try:
            twactor = TwitterActor()

            # outgoing messages
            result['statuses_out'] = [
                describe_status_with_timestamp(s)
                for s in twactor.latest_statuses(5)
            ]

            # incoming messages
            direct_stats = []
            mention_stats = []
            result['directs'] = direct_stats
            result['mentions'] = mention_stats
            directs, mentions = twactor.messages(today)
            directs.reverse()
            mentions.reverse()
            direct_stats.extend(
                [describe_status_with_timestamp(s) for s in directs])
            mention_stats.extend(
                [describe_status_with_timestamp(s) for s in mentions])
        except TwitterException, ex:
            warnings.append(str(ex))
示例#2
0
def _create_actor_and_delegates(api, moxer):
    selector = moxer.CreateMock(ActionSelector)
    analyzer = moxer.CreateMock(TweetAnalyzer)
    actor = TwitterActor(selector=selector,
                         twitter_api=api,
                         reporter=Absorber(),
                         analyzer=analyzer)
    return Record(actor=actor, selector=selector, analyzer=analyzer)
示例#3
0
 def get(self, **kw):
     helper = RequestHelper(self)
     result = {}
     
     today = datetime.combine(datetime.now(), time(0, 0, 0))
     result['timestamp'] = str(datetime.now())
     result['today'] = str(today)
     
     warnings = []
     result['warnings'] = warnings
     
     # source/artifact counts
     result['source_artifact_counts'] = ArtifactSourceAccessor.find_artifact_counts()
     
     # new artifacts
     result['new_artifacts'] = ArtifactSourceAccessor.find_artifact_counts_newer(today)
     
     # newer_arts = ArtifactAccessor.find_newer(today, refresh=True)
     
     # new_art_stats = []
     # result['new_artifacts'] = new_art_stats
             
     # for art in newer_arts:
     #     new_art_stats.append(dict(guid=art.guid, source_name=art.source_name))
     
     # memcache stats
     result['memcache'] = memcache.get_stats()
     
     try:
         twactor = TwitterActor()
         
         # outgoing messages
         result['statuses_out'] = [describe_status_with_timestamp(s) for s in twactor.latest_statuses(5)]
         
         # incoming messages
         direct_stats = []
         mention_stats = []
         result['directs'] = direct_stats
         result['mentions'] = mention_stats
         directs, mentions = twactor.messages(today)
         directs.reverse()
         mentions.reverse()
         direct_stats.extend([describe_status_with_timestamp(s) for s in directs])
         mention_stats.extend([describe_status_with_timestamp(s) for s in mentions])
     except TwitterException, ex:
         warnings.append(str(ex))
示例#4
0
 def act(cls, handler):
     helper = RequestHelper(handler)
     if handler.request.get("mock", False):
         actor = TwitterActor(twitter_api=MockTwitterApi())
     else:
         actor = TwitterActor()
         
     force_act = handler.request.get("force", False)
     action = handler.request.get("action")
     skip_responses = handler.request.get("skip_responses", False)
     act_response = actor.act(force_act=force_act, action=action, skip_responses=skip_responses)
     logging.debug("act_response: %s" % str(act_response))
     action = act_response[0]
     
     result = dict(action=action)
     if len(act_response) > 1:
         result['detailed_action'] = act_response
     helper.write_json(result)
示例#5
0
 def respond(cls, handler):
     helper = RequestHelper(handler)
     directs, publics = TwitterActor().respond()
     
     if not directs:
         directs = 0
     if not publics:
         publics = 0
         
     result = dict(directs=directs, publics=publics)
     helper.write_json(result)        
示例#6
0
 def mix(cls, handler):
     helper = RequestHelper(handler)
     status = TwitterActor().mix()
     helper.write_json(status.asDict())