Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import gspread
  2. from oauth2client.service_account import ServiceAccountCredentials
  3. import requests
  4. from bs4 import BeautifulSoup
  5. import datetime
  6. import os
  7.  
  8. this_folder = os.path.dirname(os.path.abspath(__file__))
  9. client_secret = os.path.join(this_folder, 'client_secret.json')
  10.  
  11. # use creds to create a client to interact with the Google Drive API
  12. scope = ['https://spreadsheets.google.com/feeds']
  13. creds = ServiceAccountCredentials.from_json_keyfile_name(client_secret, scope)
  14. client = gspread.authorize(creds)
  15.  
  16. # Stores Historical Data worksheet in historical_data_sheet variable
  17. historical_data_sheet = client.open("Budget").worksheet("Historical Data")
  18.  
  19. # retrieves html, then processes it to find the current market price
  20. page = requests.get("https://www.google.co.uk/finance?q=MUTF_GB%3AVANG_LIFE_100_J10ZSC&ei=i7W2WfnOLILisQHBuqeICA")
  21. soup = BeautifulSoup(page.content, 'html.parser')
  22. price_data = soup.find(id="market-data-div")
  23. price = price_data.find(class_="pr").get_text()
  24.  
  25. # inputs the price and date into the website in the next row down
  26. row = 2
  27.  
  28. while historical_data_sheet.acell("AM" + str(row)).value != "":
  29.     row += 1
  30. else:
  31.     historical_data_sheet.update_acell("AM" + str(row), price)
  32.     historical_data_sheet.update_acell("AN" + str(row), datetime.date.today())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement