Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

oracle.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import json
  2. with open('data/names.json') as file:
  3. names = json.load(file)
  4. namesToSearch = names.keys()
  5. with open('data/oracle.json') as file:
  6. oracleData = json.load(file)
  7. print('Registered {} card names and {} oracle entries'.format(len(namesToSearch), len(oracleData)))
  8. def get_matching_names(words):
  9. nameCandidates = [name for name in namesToSearch if all(word in name.casefold() for word in words)]
  10. term = ' '.join(words)
  11. if len(words) > 1:
  12. goodCandidates = [name for name in nameCandidates if term in name.casefold()]
  13. if goodCandidates:
  14. nameCandidates = goodCandidates
  15. bestCandidates = [name for name in nameCandidates if term == name.casefold()]
  16. if bestCandidates:
  17. return bestCandidates
  18. return nameCandidates
  19. def get_card(name):
  20. if name in oracleData:
  21. return oracleData[name]
  22. else:
  23. return None
  24. def get_oracle_names(name):
  25. if name in names:
  26. return names[name]
  27. else:
  28. return None
  29. def get_names_in_text(text):
  30. result = []
  31. for name in namesToSearch:
  32. if name.casefold() in text:
  33. result.append(name)
  34. return result