You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
483B

  1. import json
  2. from random import choice
  3. from sys import argv
  4. from collections import OrderedDict
  5. def generate_from_json(text):
  6. with open(text) as data_file:
  7. out_list = []
  8. data = json.load(data_file, object_pairs_hook=OrderedDict)
  9. out_string = " ".join(choice(data[keys])for keys in data)
  10. return out_string
  11. if __name__ == '__main__':
  12. if argv[1:]:
  13. print(generate_from_json(argv[1]))
  14. else:
  15. print('Usage:', argv[0], 'something_antani.json')