cslarsen / wpm

Typeracer-like console app for measuring your WPM
GNU Affero General Public License v3.0
322 stars 48 forks source link

Fixes json schema in examples.json file #38

Closed chdorb closed 6 years ago

chdorb commented 6 years ago

The entries were just list of values, I added the keys "text", "author" etc.

cslarsen commented 6 years ago

It's intentionally like that to save up space on useless keys; they're just a list of tuples encoded in JSON. Did you try the code with your change? I don't think it will work.

chdorb commented 6 years ago

Yes it works fine with my update. With your actual file, while this in list and a not a dictionnary, It don't work. Here is the result:

$ git clone https://github.com/cslarsen/wpm.git                                          
Clonage dans 'wpm'...
remote: Counting objects: 1974, done.
remote: Total 1974 (delta 0), reused 0 (delta 0), pack-reused 1974
Réception d'objets: 100% (1974/1974), 3.67 MiB | 2.09 MiB/s, fait.
Résolution des deltas: 100% (1287/1287), fait.
$ cd wpm/wpm/data 
$ gzip -d examples.json.gz && wpm --load-json examples.json    
Traceback (most recent call last):
  File "/home/pdorbais/venvs/misc/bin/wpm", line 13, in <module>
    main()
  File "/home/pdorbais/venvs/misc/lib64/python3.6/site-packages/wpm/commandline.py", line 297, in main
    quotes = load_json_quotes(opts.load_json)
  File "/home/pdorbais/venvs/misc/lib64/python3.6/site-packages/wpm/commandline.py", line 140, in load_json_quotes
    return wpm.quotes.Quotes.load_json(filename)
  File "/home/pdorbais/venvs/misc/lib64/python3.6/site-packages/wpm/quotes.py", line 179, in load_json
    author = quote["author"]
TypeError: list indices must be integers or slices, not str
chdorb commented 6 years ago

My bad I thank the file wasn't used because of the name "examples" and the encryption. You're right my change broke wpm.

 wpm                     
Traceback (most recent call last):
  File "/home/pdorbais/venvs/misc/bin/wpm", line 13, in <module>
    main()
  File "/home/pdorbais/venvs/misc/lib64/python3.6/site-packages/wpm/commandline.py", line 302, in main
    quotes = wpm.quotes.Quotes.load()
  File "/home/pdorbais/venvs/misc/lib64/python3.6/site-packages/wpm/quotes.py", line 200, in load
    with gzip.open(**args) as file_obj:
  File "/usr/lib64/python3.6/gzip.py", line 53, in open
    binary_file = GzipFile(filename, gz_mode, compresslevel)
  File "/usr/lib64/python3.6/gzip.py", line 163, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '/home/pdorbais/venvs/misc/lib64/python3.6/site-packages/wpm/data/examples.json.gz'
cslarsen commented 6 years ago

Thank you anyway for the effort! 😄