예제 #1
0
    def check_wallabag(self):
        params = {
            'username': self.config['w_username'],
            'password': self.config['w_password'],
            'client_id': self.config['w_client_id'],
            'client_secret': self.config['w_client_secret']
        }
        # get token
        token = Wallabag.get_token(host=self.config['w_host'], **params)

        wall = Wallabag(host=self.config['w_host'],
                        client_secret=self.config['w_client_secret'],
                        client_id=self.config['w_client_id'],
                        token=token)

        params = {
            'archive': 0,
            'star': 0,
            'delete': 0,
            'sort': 'created',
            'order': 'desc',
            'page': 1,
            'perPage': 30,
            'tags': []
        }

        data = wall.get_entries(**params)
        for post in data['_embedded']['items']:
            if 'domain_name' in post:
                if post['domain_name'] is not None:
                    if 'boards.4chan.org' in post['domain_name']:
                        if not db.session.query(
                                exists().where(db.UrlsTable.url == unicode(
                                    post['url']))).scalar():
                            self.logger.info("adding {}".format(post['url']))
                            u = db.UrlsTable()
                            u.url = unicode(post['url'])
                            db.session.add(u)
                            db.session.commit()
                            wall.delete_entries(post['id'])
            else:
                self.logger.warning("no domain_name in {}".format(post['url']))
예제 #2
0
with open("config.yaml", 'r') as stream:
    try:
        config = yaml.load(stream)
    except (yaml.YAMLError, FileNotFoundError) as exception:
        print(exception)
        config = None
        exit(1)

token = Wallabag.get_token(**config["wallabag"])

wall = Wallabag(host=config["wallabag"]["host"],
                client_secret=config["wallabag"]["client_secret"],
                client_id=config["wallabag"]["client_id"],
                token=token)

a = wall.get_entries(tags=["Golem"])
print(a)
b = a["_embedded"]
c = b["items"]
print(c)
exit()

try:
    for i in c[1:]:
        print(i["id"])
        wall.delete_entries(i["id"])
        print(i["id"])
except requests.exceptions.HTTPError as a:
    print(a)
    pass