Exemplo n.º 1
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)
Exemplo n.º 2
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 = args[0]
        arg_entry = args[1]

        # Check if argument matches url format
        feed=FeedHandler.is_parsable(url=arg_url)
        if not feed:
            message = f"Sorry! It seems like {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)
        if any(arg_url.lower() in entry.lower() for entry,_ in entries):
            message = f"Sorry, {telegram_user.first_name}" + \
                "! I already have that url stored in your subscriptions."
            update.message.reply_text(message)
            return

        if any(arg_entry in entry for entry in entries):
            message = f"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

        urls = self.db.get_all_urls()
        if not (arg_url in urls):
            items = {}
            for item in feed:
                for key in ['summary', 'title', 'link']:
                    if not(key in item.keys()):
                        item[key]=''
                hash=CityHash64(item['summary']+item['title']+item['link'])
                items[hash] = {'active': True, 'last_date': DateHandler.get_datetime_now()}
            self.db.add_url(url=arg_url, items=items)

        self.db.add_user_bookmark(telegram_id=telegram_user.id, url=arg_url, alias=arg_entry)
        message = f"I successfully added {arg_entry} to your subscriptions!"
        update.message.reply_text(message)
Exemplo n.º 3
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)
Exemplo n.º 4
0
from util.database import DatabaseHandler
from util.feedhandler import FeedHandler
from util.datehandler import DateHandler
from cityhash import CityHash64

db = DatabaseHandler("resources/datastore.db")

arg_url = 'http://yle.fi/uutiset/rss/paauutiset.rss'

feed = FeedHandler.is_parsable(url=arg_url)

items = {}
for item in feed:
    hash = CityHash64(item['summary'] + item['title'] + item['link'])
    if (hash in items):
        print(item['link'], item['summary'], items[hash])
    items[hash] = {
        'active': True,
        'last_date': DateHandler.get_datetime_now(),
        'link': item['link']
    }
#self.db.add_url(url=arg_url, items=items)

url_items = db.get_url_items(url=arg_url)
for item in url_items:
    url_items[item]['active'] = False

new_items = []
for item in feed:
    hash = CityHash64(item['summary'] + item['title'] + item['link'])
    if not (str(hash) in url_items):