# Import custom module. import auth_mongodb import moneyMod1 # Custom module for "mymoney" web app. # This parameter is the 'query' to the MongoDB collection find() method. secID = 8 # Global variables for MongoDB access. __db_auth__ = "mymoney" __login__ = "money_user" __password__ = "LLadmin8" __host__ = "localhost" __port__ = "27017" hostDB = auth_mongodb.MongoDB_Login (__host__, __port__, __login__, __password__, __db_auth__) userDB = hostDB.connect_via_host () qry = moneyMod1.Queries_Money (userDB) pipeline = [ { "$match" : {"security_id":secID} }, { "$unwind" : "$quotes" }, { "$sort" : {"quotes.date":-1} }, { "$group" : { "_id": "$_id", "security_id" : {"$max" : "$security_id"}, "security_name" : {"$max" : "$security_name"}, "owners" : {"$max" : "$owners"}, "quotes" : {"$push" : {"quote" : "$quotes.close", "date" : {"$dateToString" : {'format':"%Y-%m-%d", 'date':"$quotes.date" } },
# # Modified By: Louis Lao # Date: Dec 11, 2017 # Reason: For stocks or bonds that are quoted in USD but are reported to us # converted to CAD, I have coded to deal with that by multiplying # it by the current exchange rate. I modify the report to show both # original quote in USD and the converted quote in CAD together. import sys import re import auth_mongodb import moneyMod1 # Get access to the "mymoney" database. hostDB = auth_mongodb.MongoDB_Login("localhost", "27017", "money_user", "LLadmin8", "mymoney") userDB = hostDB.connect_via_host() qry = moneyMod1.Queries_Money(userDB) # Prepare the query filter to retrieve the security/ies you want to # check. flt_docs = {"security_id": 8} flt_docs = {"security_name": re.compile(r"edgepoint", re.IGNORECASE)} flt_docs = {"security_name": re.compile(r"shares", re.IGNORECASE)} cursor = qry.get_security_quote_by_qry(flt_docs) # Scrape data to get canadian to USD currency exchange rate. url_rate = "http://www.bankofcanada.ca/rates/exchange/daily-exchange-rates/" exchrate_scraper = moneyMod1.Scraper(url_rate, True) exch_rate = exchrate_scraper.get_exchRate()