def predictor(self): if self.sc == None: self.sc = scraper(self.keyword).results self.articles = len(self.sc) for i in self.sc: value = Classify(i["title"]).classify() self.score += value self.final_pred = self.score / self.articles
def predictor(self): sc = scraper(self.keyword).results self.articles = len(sc) for i in sc: value = Classify(i["title"]).classify() if value == "Positive": self.score += 1 self.final_pred = self.score / self.articles
async def websocket_handler(ws: WebSocket): await ws.accept() while True: query = await ws.receive_text() if query is None or query == "": await ws.send_json({"message": "Invalid query"}) await ws.close(code=1003) break try: news = scraper(query) news_score = predict1(query, news.results).final_pred except InvalidQuery as e: await ws.send_json({"message": str(e)}) await ws.close(code=1003) break pool = ThreadPool(processes=4) inter1 = pool.apply_async(pre, (1, news_score)) inter7 = pool.apply_async(pre, (7, news_score)) inter15 = pool.apply_async(pre, (15, news_score)) inter30 = pool.apply_async(pre, (30, news_score)) list_predicted = {} list_predicted[1] = inter1.get() list_predicted[7] = inter7.get() list_predicted[15] = inter15.get() list_predicted[30] = inter30.get() try: stg = stock_graph(query, [list_predicted[i] for i in [1, 7, 15, 30]]) except InvalidTicker as e: await ws.send_json({"message": str(e)}) await ws.close(code=1003) break responseObj = { "predictedPrice": { 1: stg.predict_price_value.iloc[1]["price"], 7: stg.predict_price_value.iloc[2]["price"], 15: stg.predict_price_value.iloc[3]["price"], 30: stg.predict_price_value.iloc[4]["price"], }, "graph": stg.graphSocket(), "summary": Summarize(news.get_title(), 3).generate_summary() } await ws.send_json(responseObj) await ws.close(code=1000) break
def get_summary(): query = request.args.get('query', type=str) if query is None: return Response("{'Message': 'Send query in get query'}", status=404, mimetype='application/json') query = query.replace("%20", " ") # Whitespace url resolve try: news = scraper(query).get_title() except Exception as e: return Response("{'Message': '" + str(e) + "'}", status=404, mimetype='application/json') pointers = 3 return jsonify(Summarize(news, pointers).generate_summary())
def test_invalid_scraper(self): self.assertRaises(InvalidQuery, lambda: scraper("icneidisneafebf"))
def test_empty_scaper(self): self.assertRaises(AssertionError, lambda: scraper(""))
def setUp(self): self.scr = scraper("Tesla")