Beispiel #1
0
def scrape_btc():
    timer = threading.Timer(90.0, scrape_btc)
    timer.start()
    indexes_scraper = moneyMod1.Scraper(url, False)
    btcData = indexes_scraper.get_bitcoin()
    data = btcData.split("::")
    print("Taken at:", datetime.datetime.now().time())
    print("Bitcoin date:", data[3], data[5], data[6])
    print("Bitcoin:", data[0], "(" + data[1] + "/" + data[2] + ")")
    print("Bitcoin BASE:", str(round((float(data[0]) - float(data[1])), 4)))
    print('Press Ctrl+C to stop script!')
Beispiel #2
0
#              make sure the data is correct.
#
# Developer: Louis Lao
# Date: Jun 29, 2016
#
# Modified By: Louis Lao
# Date: Apr 29, 2017
# Reason: The Bank of Canada URL I accessed to extract US dollar exchange
#         rate from is changed, so I have to use the corrected URL.
#
# Modified By: Louis Lao
# Date: May 14, 2017
# Reason: Get the close date for the exchange rate for the report.

import os
import moneyMod1

# Scrape data to get canadian to USD currency exchange rate.
url = "http://www.bankofcanada.ca/rates/exchange/daily-exchange-rates/"
exchrate_scraper = moneyMod1.Scraper(url, True)

rateDate = exchrate_scraper.get_rateDate()
print("Close date:", rateDate)

exch_rate = exchrate_scraper.get_exchRate()
exch_rate_inverse = 1.0 / exch_rate
print("Exchange Rate: %6.4f (%6.4f)" % (exch_rate, exch_rate_inverse))

print()
input("Press Enter to exit.")
Beispiel #3
0
else:
    # This indicates that there is just one option on the command
    #  line, which is expected. Then I check whether is it one of
    #  two acceptable options.
    if (sys.argv[1] == "upd") or (sys.argv[1] == "noupd"):
        upd = sys.argv[1]

    else:
        print("Wrong arguments!")
        print("Usage: " + sys.argv[0] + " upd/noupd")
        sys.exit(2)

# Scrape data to get canadian to USD currency exchange rate.
url = "http://www.bankofcanada.ca/rates/exchange/daily-exchange-rates/"
exchrate_scraper = moneyMod1.Scraper(url)
exch_rate = exchrate_scraper.get_exchRate()
print("Exchange Rate: %6.4f (%6.4f)" % (exch_rate, 1.0 / exch_rate))

# Scrape quote date and value for TSX. The date is used as the date for
#  TSX as well as Dow Jones and exchange rate.
#url = "https://www.theglobeandmail.com/globe-investor/markets/"
url = "https://www.bloomberg.com/quote/SPTSX:IND"
indexes_scraper = moneyMod1.Scraper(url, False)
tsxData = indexes_scraper.get_dow_tsx()
data = tsxData.split("::")
idxDate = data[1]
tsx = data[2]
print("Close date:", idxDate)

# Scrape Dow Jones index value.
Beispiel #4
0
        print("Wrong arguments!")
        print("Usage: " + sys.argv[0] + " upd/noupd")
        sys.exit(2)

# 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)

# Get quote data for the specified security.
cursor = qry.get_security_quote_by_qry({"security_id": target_id})

# 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)
exch_rate = exchrate_scraper.get_exchRate()

# Note that there is only one document returned.
for item in cursor:
    print("\n   Looking up " + item["security_name"] + ":")

    if item["security_type"] == 'fund':
        # Get quote data for the specified mutual fund.
        try:
            data = qry.get_fund_quote_by_URL(item["security_url"])
        except Exception as e:
            # Error detected when scraping financial data from the given page.
            print("   *********Error detected...", e)
            continue
Beispiel #5
0
#
# Modified By: Louis Lao
# Date: Dec 04, 2017
# Reason: Scrape TSX and DOW indices from practically identical pages from
#         Bloomberg.
#
# Modified By: Louis Lao
# Date: Dec 29, 2017
# Reason: Add Bitcoin to be tracked like TSX and Dow Jones.

import moneyMod1

# Get TSX data from Bloomberg web site.
#url = "https://www.theglobeandmail.com/globe-investor/markets/"
url = "https://www.bloomberg.com/quote/SPTSX:IND"
indexes_scraper = moneyMod1.Scraper (url, True)

print ("Getting TSX ......\n")

# Firstly get the quotes date/time for TSX.
tsxData = indexes_scraper.get_dow_tsx ()

data = tsxData.split ("::")
print ("TSX quote date detail:", data[0])
print ("TSX quote date:", data[1])
print ("TSX:", data[2])
print ("TSX 1 Day Change:", data[3])
print ( )
print ( )

# Get Dow Jones data from Bloomberg web site.
Beispiel #6
0
    else:
        print("Wrong date format!")
        print("Date must be in the following format: 2017-04-24")
        sys.exit(2)

target_date = match.group(0)

# Because TSX index, Dow Jones index and exchange rate may have different
#  dates, therefore I have to choose one date as the date for all of them.
#  And since the "mymoney" database is Canadian based, I choose the quote
#  date for TSX index as the common date for the database. This date is
#  extracted from Globe and Mail financial web site.
#url = "https://www.theglobeandmail.com/globe-investor/markets/"
url = "https://www.bloomberg.com/quote/SPTSX:IND"
idxDate_scraper = moneyMod1.Scraper(url, False)
idxDate = idxDate_scraper.get_dow_tsx()
data = idxDate.split("::")
idxDate = data[1]

if (idxDate != target_date):
    print("TSX/Dow indexes and exchange rate date (" + idxDate +
          ") is bad. Exiting now.")
    print()
    sys.exit(2)

# Once the indexes and exchange rate date is validated, then the rest of
#  the checking process can proceed.
#
# Get access to the "mymoney" database.
hostDB = auth_mongodb.MongoDB_Login("localhost", "27017", "money_user",