예제 #1
0
class NewsMeDigestTweeter(object):
    def __init__(self, debug=True):
        self._oauth = None
        self._oauth_api = None

        self._oauth_init()
        self._debug = debug

        self.tweet_counter = 0

        self._model_queries = NewsMeModelQueries()

    def _oauth_init(self):
        self._oauth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY,
                                   social_keys.TWITTER_CONSUMER_SECRET)
        self._oauth.set_access_token(
            social_keys.TWITTER_APP_ACCESS_TOKEN,
            social_keys.TWITTER_APP_ACCESS_TOKEN_SECRET)
        self._oauth_api = API(self._oauth)

    def follow_digestion_user(self, digestion_user):
        pass
        #try:
        #    if self._oauth_api.exists_friendship(digestion_user, 'twixmit') == False:
        #        friend = self._oauth_api.create_friendship(digestion_user)
        #except TweepError, e:
        #    logging.error("TweepError: %s", e)
        #logging.info("following: %s" % digestion_user)

    def tweet_from_digestion(self, digest_articles, digestion_user):

        for k, v in digest_articles.iteritems():

            status_text = "%s %s" % (v, k)

            model_check = self._model_queries.check_model_for_tweet(
                digestion_user, k)

            logging.info("model check for user and link is %s" % model_check)

            if not self._debug and not model_check:
                try:
                    self._oauth_api.update_status(status=status_text,
                                                  source="twixmit")
                    self.tweet_counter = self.tweet_counter + 1
                except TweepError, e:
                    logging.error("TweepError: %s", e)

            if not model_check:
                self.save_tweet_to_model(digestion_user, k, v)
            else:
                logging.warn("link was already tweeted: %s" % k)
예제 #2
0
class NewsMeDigestTweeter(object):
    def __init__(self,debug=True):
        self._oauth = None
        self._oauth_api = None
        
        self._oauth_init()
        self._debug = debug
        
        self.tweet_counter = 0
        
        self._model_queries = NewsMeModelQueries()
    
    def _oauth_init(self):
        self._oauth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY, social_keys.TWITTER_CONSUMER_SECRET)
        self._oauth.set_access_token(social_keys.TWITTER_APP_ACCESS_TOKEN,social_keys.TWITTER_APP_ACCESS_TOKEN_SECRET)
        self._oauth_api = API(self._oauth)
    
    def follow_digestion_user(self,digestion_user):
	pass        
	#try:
        #    if self._oauth_api.exists_friendship(digestion_user, 'twixmit') == False:
        #        friend = self._oauth_api.create_friendship(digestion_user)
        #except TweepError, e:
        #    logging.error("TweepError: %s", e)
        #logging.info("following: %s" % digestion_user)
    
    def tweet_from_digestion(self,digest_articles, digestion_user):
        
        for k, v in digest_articles.iteritems():
            
            status_text = "%s %s" % (v,k)
            
            model_check = self._model_queries.check_model_for_tweet(digestion_user,k)
            
            logging.info("model check for user and link is %s" % model_check)
            
            if not self._debug and not model_check:
                try:
                    self._oauth_api.update_status(status=status_text,source="twixmit")
                    self.tweet_counter = self.tweet_counter + 1
                except TweepError, e:
                    logging.error("TweepError: %s", e)
            
            
            if not model_check:
                self.save_tweet_to_model(digestion_user,k,v)
            else:
                logging.warn("link was already tweeted: %s" % k)
예제 #3
0
파일: dailymix.py 프로젝트: twixmit/twixmit
    def get(self):

        auth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY, social_keys.TWITTER_CONSUMER_SECRET)
        auth.set_access_token(social_keys.TWITTER_APP_ACCESS_TOKEN, social_keys.TWITTER_APP_ACCESS_TOKEN_SECRET)

        api = API(auth)
        api_is_working = api.test()

        dt = datetime.datetime.fromtimestamp(time.time())

        logging.info("current time is: %s" % dt)

        one_day = datetime.timedelta(days=1)
        yesterday = dt - one_day

        logging.info("yesterday is: %s" % yesterday)
        logging.info("today is: %s" % dt)

        day_filter = datetime.datetime(yesterday.year, yesterday.month, yesterday.day, hour=0, minute=0)
        day_today = datetime.datetime(dt.year, dt.month, dt.day, hour=0, minute=0)

        logging.info("day filter point is: %s" % day_filter)
        logging.info("tomorrow move to point is: %s" % day_today)

        q = model.SocialPostsForUsers.all()
        q.filter("day_created >=", day_filter)

        # TODO the resubmits aren't being pulled here an need to be

        user_list = []
        post_list = []

        queries = helpers.Queries()
        query_count = q.count(limit=10)

        logging.info("query count limit check: %s" % query_count)

        if query_count > 10:

            counter = 0
            for result in q.run(config=queries.get_db_run_config_eventual()):

                if counter % 1000 == 0:
                    self.perform_mix(user_list, post_list, api, day_today)
                    user_list = []
                    post_list = []

                user_list.append(result.social_user)
                post_list.append(result)

                counter = counter + 1

            self.perform_mix(user_list, post_list, api, day_today)

            status_text = "there were %s mix ups on %s" % (counter, day_filter)
            logging.info(status_text)

            try:
                api.update_status(status=status_text, source="twixmit")
            except TweepError, e:
                logging.error("TweepError: %s", e)
예제 #4
0
파일: dailymix.py 프로젝트: twixmit/twixmit
    def perform_mix(self, user_list, post_list, api, move_to):

        logging.info("list sized for users and posts are: %s" % len(user_list))

        if len(user_list) > 1:

            logging.info("starting user and post list shuffle")
            random.shuffle(user_list)
            random.shuffle(post_list)

            logging.info("done with user and post list shuffle")

            logging.info("starting mix assignments")

            for index in range(len(user_list)):

                logging.info("next user index is %s" % index)

                user = user_list[index]
                post = post_list[index]

                logging.info("next user to is: %s" % user.user_id)
                logging.info("next post is: %s" % post.key())

                status_text = "i just mixed the post from @%s to @%s" % (
                    post.social_user.shortcut_social_username,
                    user.shortcut_social_username,
                )
                logging.info(status_text)

                posted_to_twitter = True

                try:

                    per_user_auth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY, social_keys.TWITTER_CONSUMER_SECRET)
                    per_user_auth.set_access_token(user.access_token_key, user.access_token_secret)

                    per_user_api = API(per_user_auth)

                    if per_user_api.test():
                        per_user_api.update_status(status=post.text, source="twixmit")
                    else:
                        logging.error("failed to access api with user: %s" % user.user_id)
                        api.update_status(
                            status="hey @%s i can't access your twitter feed!" % user.shortcut_social_username,
                            source="twixmit",
                        )

                except TweepError, e:
                    logging.error("TweepError: %s", e)
                    posted_to_twitter = False

                mix_model = model.SocialPostMixesForUsers(
                    origin_post=post,
                    posted_to_user=user,
                    posted_from_user=post.social_user,
                    posted_to_twitter=posted_to_twitter,
                )
                mix_model.put()

                if post.resubmit == True:
                    post.day_created = move_to
                    post.put()
예제 #5
0
파일: dailymix.py 프로젝트: twixmit/twixmit
    def get(self):

        auth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY,
                            social_keys.TWITTER_CONSUMER_SECRET)
        auth.set_access_token(social_keys.TWITTER_APP_ACCESS_TOKEN,
                              social_keys.TWITTER_APP_ACCESS_TOKEN_SECRET)

        api = API(auth)
        api_is_working = api.test()

        dt = datetime.datetime.fromtimestamp(time.time())

        logging.info("current time is: %s" % dt)

        one_day = datetime.timedelta(days=1)
        yesterday = dt - one_day

        logging.info("yesterday is: %s" % yesterday)
        logging.info("today is: %s" % dt)

        day_filter = datetime.datetime(yesterday.year,
                                       yesterday.month,
                                       yesterday.day,
                                       hour=0,
                                       minute=0)
        day_today = datetime.datetime(dt.year,
                                      dt.month,
                                      dt.day,
                                      hour=0,
                                      minute=0)

        logging.info("day filter point is: %s" % day_filter)
        logging.info("tomorrow move to point is: %s" % day_today)

        q = model.SocialPostsForUsers.all()
        q.filter("day_created >=", day_filter)

        #TODO the resubmits aren't being pulled here an need to be

        user_list = []
        post_list = []

        queries = helpers.Queries()
        query_count = q.count(limit=10)

        logging.info("query count limit check: %s" % query_count)

        if query_count > 10:

            counter = 0
            for result in q.run(config=queries.get_db_run_config_eventual()):

                if counter % 1000 == 0:
                    self.perform_mix(user_list, post_list, api, day_today)
                    user_list = []
                    post_list = []

                user_list.append(result.social_user)
                post_list.append(result)

                counter = counter + 1

            self.perform_mix(user_list, post_list, api, day_today)

            status_text = "there were %s mix ups on %s" % (counter, day_filter)
            logging.info(status_text)

            try:
                api.update_status(status=status_text, source="twixmit")
            except TweepError, e:
                logging.error("TweepError: %s", e)
예제 #6
0
파일: dailymix.py 프로젝트: twixmit/twixmit
    def perform_mix(self, user_list, post_list, api, move_to):

        logging.info("list sized for users and posts are: %s" % len(user_list))

        if len(user_list) > 1:

            logging.info("starting user and post list shuffle")
            random.shuffle(user_list)
            random.shuffle(post_list)

            logging.info("done with user and post list shuffle")

            logging.info("starting mix assignments")

            for index in range(len(user_list)):

                logging.info("next user index is %s" % index)

                user = user_list[index]
                post = post_list[index]

                logging.info("next user to is: %s" % user.user_id)
                logging.info("next post is: %s" % post.key())

                status_text = "i just mixed the post from @%s to @%s" % (
                    post.social_user.shortcut_social_username,
                    user.shortcut_social_username)
                logging.info(status_text)

                posted_to_twitter = True

                try:

                    per_user_auth = OAuthHandler(
                        social_keys.TWITTER_CONSUMER_KEY,
                        social_keys.TWITTER_CONSUMER_SECRET)
                    per_user_auth.set_access_token(user.access_token_key,
                                                   user.access_token_secret)

                    per_user_api = API(per_user_auth)

                    if per_user_api.test():
                        per_user_api.update_status(status=post.text,
                                                   source="twixmit")
                    else:
                        logging.error("failed to access api with user: %s" %
                                      user.user_id)
                        api.update_status(
                            status="hey @%s i can't access your twitter feed!"
                            % user.shortcut_social_username,
                            source="twixmit")

                except TweepError, e:
                    logging.error("TweepError: %s", e)
                    posted_to_twitter = False

                mix_model = model.SocialPostMixesForUsers(
                    origin_post=post,
                    posted_to_user=user,
                    posted_from_user=post.social_user,
                    posted_to_twitter=posted_to_twitter)
                mix_model.put()

                if post.resubmit == True:
                    post.day_created = move_to
                    post.put()