facebook_module.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:stephanie-va 作者: SlapBot 项目源码 文件源码
def get_birthday_reminders(self):
        """
            Responds to user-input, typically speech text, by listing the user's
            Facebook friends with birthdays today.
            Arguments:
            text -- user-input, typically transcribed speech
            self.assistant -- used to interact with the user (for both input and output)
            profile -- contains information related to the user (e.g., phone
                       number)
        """
        try:
            results = self.graph.request("me/friends",
                                         args={'fields': 'id,name,birthday'})
        except facebook.GraphAPIError:
            response = ("I have not been authorized to query your Facebook. If you " +
                        "would like to check birthdays in the future, please visit " +
                        "the Jasper dashboard.")
            return response
        except:
            return "I apologize, there's a problem with that service at the moment."

        needle = datetime.datetime.now(tz=pytz.utc).strftime("%m/%d")

        people = []
        for person in results['data']:
            try:
                if needle in person['birthday']:
                    people.append(person['name'])
            except:
                continue

        if len(people) > 0:
            if len(people) == 1:
                output = people[0] + " has a birthday today."
            else:
                output = "Your friends with birthdays today are " + \
                         ", ".join(people[:-1]) + " and " + people[-1] + "."
        else:
            output = "None of your friends have birthdays today."

        return output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号