def get_author_name(cls, user_id, token): if not cls.url: info, code = cls._mock_get_info(user_id) return info["display_name"] msg, code = Requester.auth_fetch('GET', cls.url + f'/users/{user_id}', cls.tkn_hdr(token), payload={}) return msg["display_name"]
def register_user(cls, fullname, email, phone, avatar, token, password=""): if not cls.url: return cls._mock_register(fullname, email, phone, avatar) payload = {'email': email, 'display_name': fullname, 'phone_number': phone, 'image_location': avatar, 'password': password} return Requester.auth_fetch('POST', cls.url + '/users', cls.tkn_hdr(token), payload)
def delete_vid(cls, vid_id): if not cls.url: return cls.mock_db msg, code = Requester.media_fetch('DELETE', cls.url + '/videos/' + str(vid_id), {}, {}) if code != 200: cls.logger().error(f"Error deleting video {vid_id}")
def get_uuid_from_token(cls, token): if not cls.url: cls._mock_get_info(int(token)) return int(token) msg, code = Requester.auth_fetch('GET', cls.url + '/users/id', cls.tkn_hdr(token), payload={}) if code != 200: raise NotFoundError(f"User with token {token[:10]}... not found") return msg["uid"]
def is_valid_token(cls, token): if not cls.url: return True msg, code = Requester.auth_fetch('POST', cls.url + '/sign-in', cls.tkn_hdr(token), payload={}) if code == 200: return True if code == 400: return False
def send_url(cls, vid_id, fb_url): if not cls.url: return cls._mock_send(vid_id, fb_url) payload = {'videoId': vid_id, 'url': fb_url} msg, code = Requester.media_fetch('POST', cls.url + '/videos', {}, payload) if code != 201: cls.logger().error( f"Error uploading video for ID: {vid_id}. Response: {msg}, code {code}" ) return msg['url'], msg['timestamp']
def get_info(cls, vid_id): if not cls.url: return cls._mock_get(vid_id) msg, code = Requester.media_fetch('GET', cls.url + '/videos/' + str(vid_id), {}, {}) if code != 200: cls.logger().error( f"Error getting video info for ID: {vid_id}. Response: {msg}, code {code}" ) return msg['url'], msg['timestamp']
def get_answer(self, client_message: str): request_params = {'method': 'POST', 'url': self._get_answer_url, 'headers': self._headers, 'data': self._get_request_data(client_message)} status, response_data = Requester.request_and_parse(request_params, session=self._session) try: answer = response_data['answer'] except KeyError: answer = 'pbErr (%d)' % status else: self._history.append(client_message, answer) return answer
def find_user(cls, token, name=None, email=None, phone=None, per_page=None, page=None): if not cls.url: return cls._mock_find(name, email, phone) query = "?" if name: query += f"name={name}" if email: query += f"&email={email}" if phone: query += f"&phone={phone}" if per_page: query += f"&per_page={per_page}" if page: query += f"&page={page}" msg, code = Requester.auth_fetch('GET', cls.url + '/users' + query, cls.tkn_hdr(token), payload={}) return msg, code
def modify_user(cls, user_id, args_dict): if not cls.url: return cls._mock_modify(user_id, args_dict) msg, code = Requester.auth_fetch('PUT', cls.url + '/users/' + str(user_id), cls.tkn_hdr(args_dict["x-access-token"]), args_dict) return msg, code
def get_user_info(cls, user_id, token): if not cls.url: return cls._mock_get_info(user_id) return Requester.auth_fetch('GET', cls.url + f'/users/{user_id}', cls.tkn_hdr(token), payload={})
def is_admin(cls, token): if not cls.url: return {"admin":False}, 200 msg, code = Requester.auth_fetch('GET', cls.url + '/users/admin', cls.tkn_hdr(token), payload={}) return msg, code
def send_new_password(cls, email, reset_code, password): payload = {"email":email, "code": reset_code, "password": password} msg, code = Requester.auth_fetch('POST', cls.url + '/change-password-with-reset-code', {}, payload=payload) return msg, code
def send_reset_code(cls, email): msg, code = Requester.auth_fetch('POST', cls.url + '/reset-codes', {}, payload={"email":email}) return msg, code
def delete_user(cls, user_id, token): if not cls.url: cls.mock_db[user_id-1] = {"DELETED":True} return msg, code = Requester.auth_fetch('DELETE', cls.url + f'/users/{user_id}', cls.tkn_hdr(token), payload={}) return msg, code
def scrape(self, url): failed = [] response = Requester(url, timeout=self.timeout).make_request(self.failed) self.add_soup(response) return self.soup
from flask import Flask, render_template from utils.requester import Requester app = Flask('HiyobiViewer') requester = Requester() @app.route('/') def home(): title = 'Pyhobi - Page 1' mlist = requester.get_list(1) data = { 'title': title, 'mlist': mlist } return render_template('list.html', data=data) @app.route('/list/<page>') def list_page(page): title = f'Pyobi - Page {page}' mlist = requester.get_list(page) data = { 'title': title, 'mlist': mlist } return render_template('list.html', data=data) @app.route('/reader/<index>')
def is_user_admin(cls, uuid): if not cls.url: return {"admin":False}, 200 msg, code = Requester.auth_fetch('GET', cls.url + '/users/' + str(uuid) + '/admin', {}, payload={}) return msg, code