Ejemplo n.º 1
0
    def test_format_url_string(self):
        url = "https://lorem-rss.herokuapp.com/feed"
        url = FeedHandler.format_url_string(url)
        self.assertEqual(url, "https://lorem-rss.herokuapp.com/feed")

        url = "www.lorem-rss.herokuapp.com/feed"
        url = FeedHandler.format_url_string(url)
        self.assertEqual(url, "http://www.lorem-rss.herokuapp.com/feed")

        url = "lorem-rss.herokuapp.com/feed"
        url = FeedHandler.format_url_string(url)
        self.assertEqual(url, "http://lorem-rss.herokuapp.com/feed")
Ejemplo n.º 2
0
    def add_group(self, bot, update, args):
        if len(args) != 2:
            message = "Ja, daar snap ik dus helemaal niks van. Probeer dit eens:\n" \
                      "/addgroup <url> <groupame>"
            update.message.reply_text(message)
            return

        arg_url = FeedHandler.format_url_string(string=args[0])
        arg_channel = args[1]

        # Check if argument matches url format
        if not FeedHandler.is_parsable(url=arg_url):
            message = "Die url lijkt niet helemaal lekker!"
            update.message.reply_text(message)
            return

        if not arg_channel.startswith('@'):
            message = "Een groepnaam moet met @ starten"
            update.message.reply_text(message)
            return

        channels = self.db.get_channels()
        if any(channel[0] == arg_channel and channel[1] == arg_url
               for channel in channels):
            update.message.reply_text(
                "Deze url is al aanwezig voor deze groep!")
            return

        # Add the channel + url
        self.db.add_url(arg_url)
        self.db.add_channel(arg_channel, arg_url)
        message = "Channel en url zijn toegevoegd!"
        update.message.reply_text(message)
Ejemplo n.º 3
0
def feed_url(update, url, **chat_info):
    arg_url = FeedHandler.format_url_string(string=url)
    chat_id = update.chat.id

    # _check if argument matches url format
    if not FeedHandler.is_parsable(url=arg_url):
        text = "Sorry! It seems like '" + \
               str(arg_url) + "' doesn't provide an RSS news feed.. Have you tried another URL from that provider?"
        envia_texto(bot=bot, chat_id=chat_id, text=text)
        return
    chat_id = chat_info['chat_id']
    chat_name = chat_info.get('chat_name')
    user_id = update.from_user.id

    result = db.set_url_to_chat(chat_id=str(chat_id),
                                chat_name=str(chat_name),
                                url=url,
                                user_id=str(user_id))

    if result:
        text = "I successfully added " + arg_url + " to your subscriptions!"
    else:
        text = "Sorry, " + update.from_user.first_name + \
               "! I already have that url with stored in your subscriptions."
    envia_texto(bot=bot, chat_id=chat_id, text=text)
Ejemplo n.º 4
0
    def add(self, bot, update, args):
        """
        Adds a rss subscription to user
        """

        telegram_user = update.message.from_user

        if len(args) != 2:
            message = "Sorry! I could not add the entry! Please use the the command passing the following arguments:\n\n /add <url> <entryname> \n\n Here is a short example: \n\n /add http://www.feedforall.com/sample.xml ExampleEntry"
            update.message.reply_text(message)
            return

        arg_url = FeedHandler.format_url_string(string=args[0])
        arg_url = args[0]
        arg_entry = args[1]

        # Check if argument matches url format
        # if not FeedHandler.is_parsable(url=arg_url):
        #     message = "Sorry! It seems like '" + \
        #         str(arg_url) + "' doesn't provide an RSS news feed.. Have you tried another URL from that provider?"
        #     update.message.reply_text(message)
        #     return

        # Check if entry does not exists
        entries = self.db.get_urls_for_user(telegram_id=telegram_user.id)
        print(entries)

        if any(arg_url.lower() in entry for entry in entries):
            message = "Sorry, " + telegram_user.first_name + \
                "! I already have that url with stored in your subscriptions."
            update.message.reply_text(message)
            return

        if any(arg_entry in entry for entry in entries):
            message = "Sorry! I already have an entry with name " + \
                arg_entry + " stored in your subscriptions.. Please choose another entry name or delete the entry using '/remove " + arg_entry + "'"
            update.message.reply_text(message)
            return
        
        # get current web page content
        try:
            url_content = FeedHandler.get_url_content(arg_url)
        #print("found: " + url_content)
        except:
            message = "Sorry, cannot connect to that url, check for typos."
            update.message.reply_text(message)
            return

        print("start")
        self.db.add_user_bookmark(
            telegram_id=telegram_user.id, url=arg_url.lower(), alias=arg_entry, url_content=url_content)
        message = "I successfully added " + arg_entry + " to your subscriptions!"
        update.message.reply_text(message)
        print("finished")
Ejemplo n.º 5
0
    def add(self, bot, update, args):
        """
        Adds a rss subscription to user
        """

        telegram_user = update.message.from_user

        if len(args) != 2:
            message = "Ja, daar snap dus ik dus niks van. Probeer dit eens:\n" \
                      " /add <url> <naampje>"
            update.message.reply_text(message)
            return

        arg_url = FeedHandler.format_url_string(string=args[0])
        arg_entry = args[1]

        # Check if argument matches url format
        if not FeedHandler.is_parsable(url=arg_url):
            message = "Die url lijkt niet helemaal lekker!"
            update.message.reply_text(message)
            return

        # Check if entry does not exists
        entries = self.db.get_urls_for_user(telegram_id=telegram_user.id)

        if any(arg_url.lower() in entry for entry in entries):
            message = "Deze url heb je al toegevoegd!"
            update.message.reply_text(message)
            return

        if any(arg_entry in entry for entry in entries):
            message = "Je hebt hetzelfde naampje gebruikt als een andere url, da ga nie"
            update.message.reply_text(message)
            return

        self.db.add_user_bookmark(telegram_id=telegram_user.id,
                                  url=arg_url.lower(),
                                  alias=arg_entry)
        message = "Hij staat erbij! Gebruik /list als je me niet gelooft"
        update.message.reply_text(message)