Created
January 25, 2021 01:35
-
-
Save kaihendry/3066505b9ae1068599c021e3f8ba6bf9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ins)(dlsuite) [hendry@t14s docdl]$ python schedule-dl.py | |
b'PK\x03\x04\x14\x00\x08\x08\x08\x00'... | |
Traceback (most recent call last): | |
File "/home/hendry/tmp/docdl/schedule-dl.py", line 34, in <module> | |
df = pd.read_excel(r'test.xlsx') | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/util/_decorators.py", line 299, in wrapper | |
return func(*args, **kwargs) | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 344, in read_excel | |
data = io.parse( | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 1148, in parse | |
return self._reader.parse( | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 555, in parse | |
output[asheetname] = parser.read(nrows=nrows) | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/io/parsers.py", line 1052, in read | |
index, columns, col_dict = self._engine.read(nrows) | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/io/parsers.py", line 2491, in read | |
alldata = self._rows_to_cols(content) | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/io/parsers.py", line 3184, in _rows_to_cols | |
self._alert_malformed(msg, row_num + 1) | |
File "/home/hendry/.local/lib/python3.9/site-packages/pandas/io/parsers.py", line 2943, in _alert_malformed | |
raise ParserError(msg) | |
pandas.errors.ParserError: Expected 1 fields in line 4, saw 27 | |
(ins)(dlsuite) [hendry@t14s docdl]$ cat schedule-dl.py | |
from googleapiclient.discovery import build | |
from google.oauth2 import service_account | |
SCOPES = ['https://www.googleapis.com/auth/drive'] | |
# Your auth options https://dabase.com/blog/2021/gsuite-export/ | |
SERVICE_ACCOUNT_FILE = 'credentials.json' | |
# We use the SERVICE_ACCOUNT_FILE we just downloaded and the SCOPES we defined to create a Credentials object. | |
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES) | |
# Remember to share the document with this email address | |
credentials = credentials.with_subject('[email protected]') | |
# We build a drive_v3 service using the credentials we just created | |
service = build('drive', 'v3', credentials=credentials) | |
files = service.files() | |
service.files().get(fileId='1_bQAKskMdtaOM8z3tH4BF3w9cMURQG-M_7s1pXtLiGg').execute() | |
# https://developers.google.com/drive/api/v3/ref-export-formats | |
fconr = files.export(fileId='1_bQAKskMdtaOM8z3tH4BF3w9cMURQG-M_7s1pXtLiGg', | |
mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') | |
fcont = fconr.execute() | |
print('{}...'.format(fcont[:10])) | |
file = open("test.xlsx", "wb") | |
file.write(fcont) | |
file.close() | |
import pandas as pd | |
df = pd.read_excel(r'test.xlsx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment