def ca_nhan(): if "token" in session: user = session["token"] info = User.objects(username=user).first() att = Attribute.objects(username=user).first() hstr_list = All_history.objects(user=user) qt_list = Quote.objects(username=user) if request.method == "GET": return render_template("ca_nhan.html", info=info, att=att, quotes=qt_list, history=hstr_list) else: form = request.form quote = form["quote"] author = form["author"] if author == "": q = Quote(username=user, quote=quote) else: q = Quote(username=user, quote=quote, author=author) q.save() return render_template("ca_nhan.html", info=info, att=att, quotes=qt_list, history=hstr_list) else: return redirect(url_for("sign_in"))
def delete(self, quoteId): bogey = Quote("", "", quoteId) try: self.quotes.remove(bogey) except: pass
def save_quote(text, author, quoteTags): #saves the quote to db # todo: add logic to only save tags we have not seen before quote = Quote(author, text) db.session.add(quote) db.session.commit() for qTag in quoteTags: tag = Tag(qTag, quote.id) db.session.add(tag) # commit all the information db.session.commit()
def post(self): data = request.get_json() quote_text = data['quote'] quote = Quote(quote_text) try: quote.save_to_database() except Exception as e: print(e) return {'message': 'An error occurred inserting the quote'}, 500 return quote.json(), 201
def doAdd(quotes): logging.debug("Received doAdd command.") saying = verify("What is the quote?") if saying == COMMAND_ABORT: return author = verify("Who said it?") if author == COMMAND_ABORT: return newQuote = Quote( saying, author ) logging.debug( "Adding quote <%s>." % newQuote ) quotes.add( newQuote )
def __scraping_task(self): date_now = datetime.datetime.now() list_quote = [] print(f'Initializing capture at {date_now}') for stock in self.__stocks: print(f'Getting value from {stock.codigo}...') value = self.__scraping.get_stock_value(stock) list_quote.append(Quote(stock.codigo, date_now, value)) Mongo().insert_quotes(list_quote) print('Values inserted in MongoDB database')
def test_getLastSaid(self): self.assertEqual( \ self.quotelist.quotes[0], \ self.quotelist.getLastSaid() \ ) # Any time we add a new quote, it should be the most recently said time.sleep(0.01) self.quotelist.add( Quote("Hello again", "Someone else") ) self.assertEqual( \ self.quotelist.quotes[1], \ self.quotelist.getLastSaid() \ ) self.quotelist.quotes[0].say() self.assertEqual( \ self.quotelist.quotes[0], \ self.quotelist.getLastSaid() \ )
with open( fileName,'rb' ) as f: quotes = pickle.load( f ) logging.debug("Loaded quotes successfully.") except IOError: logging.warn("Unable to load <%s>." % fileName) """ """ quotes.add( Quote( \ "", \ "" \ )) """ quotes.add( Quote( \ "By providing more opportunities for people to feel part of something bigger than themselves, we can more strongly stitch together the fabric of our nation.", \ "MacKenzie Moritz" \ )) quotes.add( Quote( \ "Service is the American way to change America.", \ "Shirley Sagawa" \ )) quotes.add( Quote( \ "Through a serious commitment to bridging our differences and restoring our confidence in solving big challenges together, America can reignite the energy needed to make our country what it can be.", \ "General Stanley McChrystal" \ )) quotes.add( Quote( \ "We need to think bigger to leverage the human capital represented by the half a million young adults who want to serve.", \ "Shirley Sagawa" \
def setUp(self): self.quotelist = QuoteList() self.quotelist.add( Quote("Hi", "Me") )
def setUp(self): self.newQuote = Quote("Hello World!", "My Computer")