Example #1
0
    def follow_clicked(self, widget, data=None):
        """follow all poeple in textview1 by name"""
        #~ iterate through the text buffer
        buf = self.textview1.get_buffer()
        (iter_first, iter_last) = buf.get_bounds()
        text = buf.get_text(iter_first, iter_last)
        #~ remove spaces and build a list to follow
        text = text.replace(' ', '')
        fol = []
        #~ create fol list
        for x in text.split('@')[1:]:
            if x not in fol:
                fol.append(x)
        #~ ask
        if self.warn and (not dialog.ok("Follow %s people.\n"
                                        "Are you sure?" % len(fol))):
            return
        else:
            self.warn = False
        # load nofollow list if it exists
        me = self.me.screen_name
        nofol = []
        cachedir = self.get_cachedir()
        nofollow = cachedir + me + '.nofollow'
        if os.path.exists(nofollow):
            with open(nofollow) as f:
                nofol = [x.strip() for x in f.readlines()]
        nofollen = len(nofol)
        #~ friend everybody unless nofol, add to nofol
        for a in fol:
            if a not in nofol:
                try:
                    api.CreateFriendship(a)
                    print('followed %s' % a)
                except TwitterError as err:
                    print(err)
                    if 'follow-limits' in str(err):
                        dialog.alert(
                            "You have reached Twitter's follow limit!")
                        break
                nofol.append(a)

        #~ Write nofol to disk. These could be invalid names,
        #~ existing friends, or blocked accounts.
        #~ We don't care. We just don't follow them.
        if nofollen < len(nofol):
            with open(nofollow, 'a') as f:
                f.writelines([x + '\n' for x in nofol[nofollen:]])
Example #2
0
    def unfollow_non_followers(self, widget, data=None):
        """unfollow everybody who is not following me
        
        todo: add safelist"""
        if not self.get_friendIDs():
            return
        me = self.me.screen_name

        # load safelist
        cachedir = self.get_cachedir()
        safefile = cachedir + me + '.safe'
        safe = []
        unsub = []
        if os.path.exists(safefile):
            with open(safefile) as f:
                safe = [x.strip() for x in f.readlines()]

        #~ safety feature in case twitter f*s up
        if len(followerIDs) < 100:
            print('Need at least 100 followers to use this feature.')
            return
        for a in friendIDs:
            if (a not in followerIDs) and (a not in safe):
                unsub.append(a)
        #~ unsub.remove(self.me.id)
        #~ save nofollow list so we do not re-follow
        #~ (unless they follow us, of course)
        unsub_names = []
        if dialog.ok('Unfriend all ' + str(len(unsub)) + ' non-followers?'):
            #UNSUB EVERYBODY IN unsub
            for a in unsub:
                try:
                    u = api.DestroyFriendship(a)
                    print('unfriended %s' % u.screen_name)
                    unsub_names.append(u.screen_name)
                except TwitterError as err:
                    print(err)
        nofollow = cachedir + me + '.nofollow'
        with open(nofollow, 'a') as f:
            f.writelines([x + '\n' for x in unsub_names])