def setUp(self): load_dotenv('.env') self.browser = Browser(os.environ.get('LINUX')) self.nairaland = Nairaland(self.browser) self.user = User(self.browser) self.category = 'politics' self.topic = '5460114' self.search = 'buhari' self.username = os.environ.get('NL_USERNAME') self.password = os.environ.get('NL_PASSWORD') self.logged_in = self.browser.login(self.username, self.password)
def category_topics(category): if request.args.get('page'): try: page = int(request.args.get('page')) except: page = 0 else: page = 0 browser = Browser(os.environ.get('LINUX')) nairaland = Nairaland(browser) response = jsonify(nairaland.category_topics(category, page)) browser.driver.quit() return response
def user_posts(user): if request.args.get('page'): try: page = int(request.args.get('page')) except: page = 0 else: page = 0 browser = Browser(os.environ.get('LINUX')) nairaland = Nairaland(browser) response = jsonify(nairaland.user_posts(user, page)) browser.driver.quit() return response
def topics_trending(): if request.args.get('page'): try: page = int(request.args.get('page')) except: page = 0 else: page = 0 browser = Browser(os.environ.get('LINUX')) nairaland = Nairaland(browser) response = jsonify(nairaland.trending_topics(page)) browser.driver.quit() return response
def categories(): if request.args.get('depth'): try: depth = int(request.args.get('depth')) except: depth = 0 else: depth = 0 browser = Browser(os.environ.get('LINUX')) nairaland = Nairaland(browser) response = jsonify(nairaland.categories(depth)) browser.driver.quit() return response
def user_post_share(): if not request.form.get('post_slug'): return jsonify({'error': 'Post Slug is required!'}), 422 # load browser for current request browser = Browser(os.environ.get('LINUX')) user = User(browser) # login first if not browser.login(username=os.environ.get('NL_USERNAME'), user_pass=os.environ.get('NL_PASSWORD')): browser.driver.quit() return jsonify({'error': 'Login failed'}) response = jsonify( user.like_post(request.form.get('post_slug'), request.form.get('unshare'))) browser.driver.quit() return response
def user_post_new(topic): if not request.form.get('content'): return jsonify({'error': 'Content is required!'}), 422 # load browser for current request browser = Browser(os.environ.get('LINUX')) user = User(browser) # login first if not browser.login(username=os.environ.get('NL_USERNAME'), user_pass=os.environ.get('NL_PASSWORD')): browser.driver.quit() return jsonify({'error': 'Login failed'}) response = jsonify( user.new_post(topic, request.form.get('content'), request.form.get('post_id'), request.form.get('follow'))) browser.driver.quit() return response
def user_topic_new(board): if not request.form.get('title') or not request.form.get('content'): return jsonify({'error': 'Title and Content are required!'}), 422 # load browser for current request browser = Browser(os.environ.get('LINUX')) user = User(browser) # login first if not browser.login(username=os.environ.get('NL_USERNAME'), user_pass=os.environ.get('NL_PASSWORD')): browser.driver.quit() return jsonify({'error': 'Login failed'}) response = jsonify( user.new_topic(board, request.form.get('title'), request.form.get('content'))) browser.driver.quit() return response
def search(): if not request.form.get('term'): return jsonify({'error': 'term is required!'}), 422 if request.args.get('page'): try: page = int(request.args.get('page')) except: page = 0 else: page = 0 browser = Browser(os.environ.get('LINUX')) nairaland = Nairaland(browser) board = request.form.get('board') if request.form.get('board') else 0 response = jsonify(nairaland.search(request.form.get('term'), board, page)) browser.driver.quit() return response
def user_shared_with(): # load browser for current request browser = Browser(os.environ.get('LINUX')) user = User(browser) # login first if not browser.login(username=os.environ.get('NL_USERNAME'), user_pass=os.environ.get('NL_PASSWORD')): browser.driver.quit() return jsonify({'error': 'Login failed'}) if request.args.get('page'): try: page = int(request.args.get('page')) except: page = 0 else: page = 0 response = jsonify(user.shared_with(page)) browser.driver.quit() return response
def home_route(): browser = Browser(os.environ.get('LINUX')) nairaland = Nairaland(browser) response = jsonify(nairaland.front_page_topics()) browser.driver.quit() return response
def user_profile(user): browser = Browser(os.environ.get('LINUX')) nairaland = Nairaland(browser) response = jsonify(nairaland.user(user)) browser.driver.quit() return response