Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gspread
- from oauth2client.service_account import ServiceAccountCredentials
- import requests
- from bs4 import BeautifulSoup
- import datetime
- import os
- this_folder = os.path.dirname(os.path.abspath(__file__))
- client_secret = os.path.join(this_folder, 'client_secret.json')
- # use creds to create a client to interact with the Google Drive API
- scope = ['https://spreadsheets.google.com/feeds']
- creds = ServiceAccountCredentials.from_json_keyfile_name(client_secret, scope)
- client = gspread.authorize(creds)
- # Stores Historical Data worksheet in historical_data_sheet variable
- historical_data_sheet = client.open("Budget").worksheet("Historical Data")
- # retrieves html, then processes it to find the current market price
- page = requests.get("https://www.google.co.uk/finance?q=MUTF_GB%3AVANG_LIFE_100_J10ZSC&ei=i7W2WfnOLILisQHBuqeICA")
- soup = BeautifulSoup(page.content, 'html.parser')
- price_data = soup.find(id="market-data-div")
- price = price_data.find(class_="pr").get_text()
- # inputs the price and date into the website in the next row down
- row = 2
- while historical_data_sheet.acell("AM" + str(row)).value != "":
- row += 1
- else:
- historical_data_sheet.update_acell("AM" + str(row), price)
- historical_data_sheet.update_acell("AN" + str(row), datetime.date.today())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement