def list_cmd(update: Update, context: CallbackContext): """Handles the /list <name> command. Sends a list of users the one requested is currently following Args: update (Update): update event context (CallbackContext): context passed by the handler """ info = EventInfo.from_message(update, context) if info is None: return if info.args is None or len(info.args) == 0: info.bot.send_message(chat_id=info.chat_id, text="use: /list <user_name> ...") return for user in info.args: following = DbManager.select_from(select="followed_id, followed_name", table_name="followed_users", where="follower_name = %s", where_args=(user, )) following = set( map( lambda row: twitter.User(id=row['followed_id'], screen_name=row['followed_name']), following)) notify_user(bot=info.bot, follower_name=user, new_following=following, user_id_list=[info.chat_id], start_message=f"follows {len(following)} users")
def get_removed_friends(bot: Bot, old_following: set, current_following: set, user: str): """Get following ids Args: api: twitter api bot: telegram bot old_following: the following already in memory user: user to check the following of """ removed_following = tuple(old_following.difference(current_following)) if len(removed_following) > 0: logger.info("Removing following of %s", user) where = f"followed_id IN ({', '.join(['%s' for _ in removed_following])})" removed_following_values = DbManager.select_from( select="DISTINCT followed_id, followed_name", table_name="followed_users", where=where, where_args=removed_following) removed_following_users = tuple( map( lambda user: twitter.User(id=user['followed_id'], screen_name=user['followed_name']), removed_following_values)) DbManager.delete_from(table_name="followed_users", where=where, where_args=removed_following) notify_user( bot=bot, follower_name=user, new_following=removed_following_users, start_message=f"stopped following {len(removed_following)} users")
def _GetSampleUser(self): return twitter.User(id=718443, name='Kesuke Miyagi', screen_name='kesuke', description=u'Canvas. JC Penny. Three ninety-eight.', location='Okinawa, Japan', url='https://twitter.com/kesuke', profile_image_url='https://twitter.com/system/user/profile_image/718443/normal/kesuke.png')
def testInit(self): '''Test the twitter.User constructor''' twitter.User(id=673483, name='DeWitt', screen_name='dewitt', description=u'Indeterminate things', url='https://twitter.com/dewitt', profile_image_url='https://twitter.com/system/user/profile_image/673483/normal/me.jpg', status=self._GetSampleStatus())
def _GetSampleUser(self): return twitter.User(id=673483, name='DeWitt', screen_name='dewitt', description=u'Indeterminate things', location='San Francisco, CA', url='http://unto.net/', profile_image_url='https://twitter.com/system/user/prof' 'ile_image/673483/normal/me.jpg', status=self._GetSampleStatus())
def testEq(self): '''Test the twitter.User __eq__ method''' user = twitter.User() user.id = 673483 user.name = 'DeWitt' user.screen_name = 'dewitt' user.description = 'Indeterminate things' user.location = 'San Francisco, CA' user.profile_image_url = 'https://twitter.com/system/user/profile_image/67' \ '3483/normal/me.jpg' user.url = 'http://unto.net/' user.status = self._GetSampleStatus() self.assertEqual(user, self._GetSampleUser())
async def on_tweet(tweet): if tweet.author == twitter.User(user="******"): word_list = tweet.content.split() output = "In this tweet, Mysticat {}".format(random.choice(vocabulary.synonym('says'))) for word in word_list: if word not in vocabulary.filler_word_list: continue elif word in vocabulary.common_word_list: output += random.choice(vocabulary.synonym('says')) elif word in vocabulary.future_smp: output += "{}, friend and fellow member of the Future SMP, ".format(word) else: output += "{}, which means {}, ".format(word, vocabulary.definition(word)) await explains.send(output)
def testProperties(self): '''Test all of the twitter.User properties''' user = twitter.User() user.id = 673483 self.assertEqual(673483, user.id) user.name = 'DeWitt' self.assertEqual('DeWitt', user.name) user.screen_name = 'dewitt' self.assertEqual('dewitt', user.screen_name) user.description = 'Indeterminate things' self.assertEqual('Indeterminate things', user.description) user.location = 'San Francisco, CA' self.assertEqual('San Francisco, CA', user.location) user.profile_image_url = 'https://twitter.com/system/user/profile_image/673483/normal/me.jpg' self.assertEqual('https://twitter.com/system/user/profile_image/673483/normal/me.jpg', user.profile_image_url) self.status = self._GetSampleStatus() self.assertEqual(4212713, self.status.id)
def get_user_data(screen_name): if screen_name not in user_dict: logging.debug("Looking up profile info for user: {}".format(screen_name)) try: user = api.GetUser(screen_name=screen_name, include_entities=True) except twitter.error.TwitterError: default = conf.settings.get("default_user_image") user = twitter.User(screen_name=screen_name, profile_image_url=default) profile_picture = "profile/{}.jpg".format(screen_name) path = os.path.join(conf.profile_path, "{}.jpg".format(screen_name)) if not os.path.exists(path): urllib.request.urlretrieve(user.profile_image_url, path) user_dict[screen_name] = {} user_dict[screen_name]["name"] = user.name user_dict[screen_name]["profile_picture"] = profile_picture return user_dict[screen_name]
def testGettersAndSetters(self): '''Test all of the twitter.User getters and setters''' user = twitter.User() user.SetId(673483) self.assertEqual(673483, user.GetId()) user.SetName('DeWitt') self.assertEqual('DeWitt', user.GetName()) user.SetScreenName('dewitt') self.assertEqual('dewitt', user.GetScreenName()) user.SetDescription('Indeterminate things') self.assertEqual('Indeterminate things', user.GetDescription()) user.SetLocation('San Francisco, CA') self.assertEqual('San Francisco, CA', user.GetLocation()) user.SetProfileImageUrl('https://twitter.com/system/user/profile_im' 'age/673483/normal/me.jpg') self.assertEqual('https://twitter.com/system/user/profile_image/673' '483/normal/me.jpg', user.GetProfileImageUrl()) user.SetStatus(self._GetSampleStatus()) self.assertEqual(4212713, user.GetStatus().id)
def test_parse_args(self): user = twitter.User(screen_name='__jcbl__') out = utils.parse_arg_list(user, 'screen_name') assert isinstance(out, (str, unicode)) assert out == '__jcbl__' users = ['__jcbl__', 'notinourselves'] out = utils.parse_arg_list(users, 'screen_name') assert isinstance(out, (str, unicode)) assert out == '__jcbl__,notinourselves' users2 = [user] + users out = utils.parse_arg_list(users2, 'screen_name') assert isinstance(out, (str, unicode)) assert out == '__jcbl__,__jcbl__,notinourselves' users = '__jcbl__' out = utils.parse_arg_list(users, 'screen_name') assert isinstance(out, (str, unicode)) assert out == '__jcbl__'
def get_friends(api: twitter.Api, user: str): """Get following users Args: api: twitter api user: user to check the following of """ new_following = set( map( lambda user: twitter.User(id=user.id, screen_name=user.screen_name ), api.GetFriends(screen_name=user))) if len(new_following) > 0: logger.info("Inserting new following of %s", user) new_following_values = tuple( map(lambda e: (user, e.id, e.screen_name), new_following)) DbManager.insert_into(table_name="followed_users", columns=("follower_name", "followed_id", "followed_name"), values=new_following_values, multiple_rows=True)
def mongo_user_to_user(user): user = twitter.User().NewFromJsonDict(user) return user
def get_user(cls, screen_name, **kwargs): return twitter.User(screen_name=screen_name, **kwargs)