sync.py 869 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/python3
  2. import os
  3. from whoosh import index
  4. from whoosh.fields import TEXT, NUMERIC, ID, Schema
  5. from . import api
  6. # Init whoosh
  7. schema = Schema(title=TEXT(stored=True), id=NUMERIC(stored=True), icon=ID(stored=True), description=TEXT)
  8. if not os.path.exists("data"):
  9. os.mkdir("data")
  10. ix = index.create_in("data", schema)
  11. writer = ix.writer()
  12. # Get achievements
  13. categories = api.get_json("/wow/data/character/achievements")['achievements']
  14. def find_achievements(categories):
  15. for category in categories:
  16. if 'categories' in category:
  17. find_achievements(category['categories'])
  18. for achievement in category['achievements']:
  19. achi_data = {k: v for k, v in achievement.items() if k in ('description', 'icon', 'id', 'title')}
  20. writer.add_document(**achi_data)
  21. find_achievements(categories)
  22. writer.commit()