spread_test.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/python3
  2. import sys
  3. import codecs
  4. import traceback
  5. import requests
  6. import re
  7. import pandas as pd
  8. import random
  9. import urllib
  10. import json
  11. import gspread
  12. import datetime
  13. from gspread_pandas import Spread, Client
  14. from oauth2client.service_account import ServiceAccountCredentials
  15. import os
  16. def save_sheet(df,filename,tabname,startpos='A1'):
  17. scope = ['https://spreadsheets.google.com/feeds',
  18. 'https://www.googleapis.com/auth/drive']
  19. credentials = ServiceAccountCredentials.from_json_keyfile_name('c:\\keys\\innnews-d27b01472ba2.json', scope)
  20. gc = gspread.authorize(credentials)
  21. spread = Spread(filename,creds=credentials)
  22. spread.df_to_sheet(df, index=False, sheet=tabname, start=startpos, replace=False)
  23. def get_sheets(filename):
  24. scope = ['https://spreadsheets.google.com/feeds',
  25. 'https://www.googleapis.com/auth/drive']
  26. credentials = ServiceAccountCredentials.from_json_keyfile_name('c:\\keys\\innnews-d27b01472ba2.json', scope)
  27. gc = gspread.authorize(credentials)
  28. # files=gc.list_spreadsheet_files()
  29. # print(files)
  30. spread = Spread(filename,creds=credentials)
  31. for ws in spread.sheets:
  32. print(ws.title)
  33. get_sheets('引新聞xSEO團隊共用表單')
  34. # spread.df_to_sheet(df, index=False, sheet=tabname, start=startpos, replace=False)
  35. #