miurahr / pykakasi

Lightweight converter from Japanese Kana-kanji sentences into Kana-Roman.
https://codeberg.org/miurahr/pykakasi
GNU General Public License v3.0
421 stars 54 forks source link

The Error of pykakasi in Google Spreadsheet on Google Colaboratory #136

Closed Hikari-1999 closed 3 years ago

Hikari-1999 commented 3 years ago

Hi, I`m writing here to ask about error on the pykakasi.

[Back Ground] I want to use pykakasi to redeuce my routine work on Spreadsheet which change kanji to alphabet. Therefore I decided to use pykakasi.

[Problem] Actually, I'm a beginner at python, Im so sorry if my problem below is not a bug, but, just my lack of skill and knowledge. Python said the problem is "expected string or bytes-like object", but my spreadsheet`s character is string since only kanji is listed on my spreadsheet.

The below is the code I tried which doesn't work.

I really appreciate if you could tell me what is the problem with this. The error is caused by my code or Github's code?

[Source code]

pip install git+https://github.com/miurahr/pykakasi
from pykakasi import kakasi

from google.colab import auth
auth.authenticate_user()

import gspread
from oauth2client.client import GoogleCredentials

print(gspread.__version__)
!pip install --upgrade gspread

gc = gspread.authorize(GoogleCredentials.get_application_default())

ss_id = gc.open_by_key('key of spreadsheet').sheet1
worksheet = gc.open_by_url(ss_id)

row1 = worksheet.col_values(1)
for row in row1:

  kks = kakasi()
  kks.setMode('J', 'a')
  conv = kks.getConverter()
  conv.do(row)

[Result]

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-c4b40f1f5667> in <module>()
      2 
      3 ss_id = gc.open_by_key('1pGNCrstOBL7CSb4eIcz4zNmFbDGYTAbKIFeH3VNSRFw').sheet1
----> 4 worksheet = gc.open_by_url(ss_id)
      5 
      6 row1 = worksheet.col_values(1)

1 frames
/usr/local/lib/python3.7/dist-packages/gspread/client.py in open_by_url(self, url)
    157 
    158         :param str title: (optional) If specified can be used to filter
--> 159             spreadsheets by title.
    160 
    161         :returns: a list of :class:`~gspread.models.Spreadsheet` instances.

/usr/local/lib/python3.7/dist-packages/gspread/utils.py in extract_id_from_url(url)
    172     :param bool allow_underscores_in_numeric_literals: Whether or not to allow
    173         visual underscores in numeric literals
--> 174     :param list ignore: List of ints of indices of the row (index 1) to ignore
    175         numericising.
    176     """

TypeError: expected string or bytes-like object
miurahr commented 3 years ago

An error is unrelated with pykakasi.

----> 4 worksheet = gc.open_by_url(ss_id)

The error is happened in 5 lines before calling pykakasi.