Good Reads

  1. # goodreads
  2. import json
  3. import os
  4. from datetime import datetime
  5.  
  6. fout = open('salida', 'w', encoding='utf-8')
  7. with open('review.json', 'r', encoding='utf-8') as file:
  8.     datos = json.load(file)  # Convierte el contenido JSON en un diccionario de Python
  9.     for linea in datos:
  10.         if "book" in linea:
  11.             u_libro  = linea["book"]
  12.             u_rating  = ''
  13.             u_review  = ''
  14.  
  15.             fecha_dt = datetime.strptime(linea["created_at"].replace(" UTC", ""), "%Y-%m-%d %H:%M:%S")
  16.             u_creado = fecha_dt.strftime("%d/%m/%Y")
  17.             if "rating" in linea:
  18.  
  19.                 if linea["rating"] != 0:
  20.                     for i in range(linea["rating"]):
  21.                         u_rating = u_rating + " ⭐"
  22.  
  23.             if linea["review"] != "(not provided)":
  24.                 u_review = linea["review"]
  25.  
  26.             fout.write("'''[[https://www.goodreads.com/search?q=" + u_libro + "|"+ u_libro +"]]'''" + u_rating + " " + u_creado + os.linesep )
  27.  
  28.             if u_review != '':
  29.                 u_review = u_review.replace("\n","\n--->")
  30.                 fout.write('--->'+u_review+os.linesep)
  31.  
  32.             fout.write(os.linesep)
  33.  
  34.  
  35. fout.close()    
  36.  
  37. #    "rating": 5,
  38. #    #"read_status": "read",
  39. #    "review": "(not provided)",
  40. #    "comments_count": 0,
  41. #    "last_comment_at": "(not provided)",
  42. #    "last_revision_at": "2013-10-05 05:10:08 UTC",
  43. #    "created_at": "2013-10-05 05:10:08 UTC",
  44. #    "updated_at": "2013-10-05 05:10:08 UTC",
  45. #    "user": "Alex Bergonzini",
  46. #    "book": "1984",
  47. #    "includes_spoilers": "No",
  48. #    "notes": "(not provided)",
  49. #    "likes_count": 0            
  50.