Пример #1
0
    def setUp(self):
        self.pinboard = Pinboard(os.environ['PINBOARD_API_TOKEN'])

        response = self.pinboard.posts.recent(count=1,
                                              date=datetime.date.today())
        bookmark = response['posts'][0]
        self.url = bookmark.url
Пример #2
0
def mark_as_read():
    h = request.args.get('h')
    url = unquote(request.args.get('url'))
    if not h or not url:
        return '<h1>Error</h1>'
    if not validate_secret(h, url):
        return '<h1>Error</h1>'
    try:
        pb = Pinboard(os.environ.get('PINBOARD_TOKEN'))
        bookmark = pb.posts.get(url=url)['posts'][0]
        bookmark.toread = False
        bookmark.save()
    except:
        return '<h1>Error</h1>'
    return '<h1>Successfully marked as read.</h1>'
Пример #3
0
    def setUp(self):
        api_token = os.environ.get('PINBOARD_API_TOKEN', None)
        if api_token is None:
            try:
                config_file = os.path.expanduser("~/.pinboardrc")
                config = configparser.RawConfigParser()
                with open(config_file, "r") as f:
                    config.readfp(f)
            except:
                raise
            else:
                api_token = config.get("authentication", "api_token")

        self.pinboard = Pinboard(api_token)

        response = self.pinboard.posts.recent(count=1, date=datetime.date.today())
        bookmark = response['posts'][0]
        self.url = bookmark.url
Пример #4
0
def main():
    logging.basicConfig(
        format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
        level=logging.INFO,
    )

    pb = Pinboard(os.environ["PB_TOKEN"])
    authorized_user = int(os.environ["TELEGRAM_USER"])

    updater = Updater(token=os.environ["TELEGRAM_TOKEN"], use_context=True)
    dispatcher = updater.dispatcher

    message_handler = MessageHandler(
        Filters.text,
        lambda update, context: on_message(update, context, pb, authorized_user
                                           ),
    )
    dispatcher.add_handler(message_handler)

    updater.start_polling()