def wall(self): """ refresh the token from the API then call a Wallabag instance then store the token :return: wall instance """ us = UserService.objects.get(user=self.user, name='ServiceWallabag') params = { 'client_id': us.client_id, 'client_secret': us.client_secret, 'username': us.username, 'password': us.password, } try: token = Wall.get_token(host=us.host, **params) except Exception as e: update_result(self.trigger_id, msg=e, status=False) logger.critical('{} {}'.format(self.user, e)) return False wall = Wall(host=us.host, client_secret=us.client_secret, client_id=us.client_id, token=token) UserService.objects.filter(user=self.user, name='ServiceWallabag').update(token=token) return wall
def check(self, request, user): """ check if the service is well configured :return: Boolean """ us = UserService.objects.get(user=user, name='ServiceWallabag') params = {'username': us.username, 'password': us.password, 'client_id': us.client_id, 'client_secret': us.client_secret} try: Wall.get_token(host=us.host, **params) return True except requests.exceptions.HTTPError as e: return e
def check(self, request, user): """ check if the service is well configured :return: Boolean """ us = UserService.objects.get(user=user, name='ServiceWallabag') params = { 'username': us.username, 'password': us.password, 'client_id': us.client_id, 'client_secret': us.client_secret } try: Wall.get_token(host=us.host, **params) return True except requests.exceptions.HTTPError as e: return e
def _refresh_token(self): """ refresh the expired token get the token of the service Wallabag for the user that uses Wallabag :return: boolean """ us = UserService.objects.get(user=self.user, name='ServiceWallabag') params = {'username': us.username, 'password': us.password, 'client_id': us.client_id, 'client_secret': us.client_secret} return Wall.get_token(host=us.host, **params)
def auth(self, request): """ let's auth the user to the Service """ callback_url = 'http://%s%s' % (request.get_host(), reverse('wallabag_callback')) params = { 'username': settings.TH_WALLABAG['username'], 'password': settings.TH_WALLABAG['password'], 'client_id': settings.TH_WALLABAG['client_id'], 'client_secret': settings.TH_WALLABAG['client_secret'] } acces_token = Wallabag.get_token(host=settings.TH_WALLABAG['host'], **params) request.session['oauth_token'] = acces_token return callback_url
def auth(self, request): """ let's auth the user to the Service :param request: request object :return: callback url :rtype: string that contains the url to redirect after auth """ service = UserService.objects.get(user=request.user, name='ServiceWallabag') callback_url = '%s://%s%s' % (request.scheme, request.get_host(), reverse('wallabag_callback')) params = {'username': service.username, 'password': service.password, 'client_id': service.client_id, 'client_secret': service.client_secret} access_token = Wall.get_token(host=service.host, **params) request.session['oauth_token'] = access_token return callback_url
def auth(self, request): """ let's auth the user to the Service :param request: request object :return: callback url :rtype: string that contains the url to redirect after auth """ service = UserService.objects.get( user=request.user, name='ServiceWallabag') callback_url = 'http://%s%s' % ( request.get_host(), reverse('wallabag_callback')) params = {'username': service.username, 'password': service.password, 'client_id': service.client_id, 'client_secret': service.client_secret} access_token = Wall.get_token(host=service.host, **params) request.session['oauth_token'] = access_token return callback_url
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']))
def _get_wall_data(self): us = UserService.objects.get(user=self.user, name='ServiceWallabag') params = dict({'access_token': self.token, 'archive': 0, 'star': 0, 'delete': 0, 'sort': 'created', 'order': 'desc', 'page': 1, 'perPage': 30, 'tags': []}) responses = requests.get(us.host + '/api/entries.json', params=params) if responses.status_code == 401: params['access_token'] = Wall.get_token(host=us.host, **params) responses = requests.get(us.host + '/api/entries.json', params=params) elif responses.status_code != 200: raise HTTPError(responses.status_code, responses.json()) return responses
import requests import yaml from wallabag_api.wallabag import Wallabag 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"])
from wallabag_api.wallabag import Wallabag from pocket import Pocket, PocketException import os params = { 'username': os.environ['WALLABAG_USER'], 'password': os.environ['WALLABAG_PASS'], 'client_id': os.environ['WALLABAG_CLIENT'], 'client_secret': os.environ['WALLABAG_SECRET'], 'host': os.environ['WALLABAG_HOST'] } token = Wallabag.get_token(**params) wb = Wallabag(params['host'], token, params['client_id'], params['client_secret']) entries = wb.get_entries() urls = [] while entries['page'] <= entries['pages']: for item in entries['_embedded']['items']: urls.append(item['url']) entries = wb.get_entries(page=entries['page'] + 1) print(len(urls), "urls fetched from wallabag") p = Pocket(consumer_key=os.environ['POCKET_KEY'], access_token=os.environ['POCKET_TOKEN']) for i, url in enumerate(urls): print(i, url) p.add(url)