fork download
  1. import re
  2.  
  3. strings = [
  4. "{tvg-id: , tvg-name: A beautiful Day - 2016, tvg-logo: https://i...content-available-to-author-only...b.org/t/p/w600_and_h900_bestv2/hZgsmIYUAtdUOUFKROq6rNyWXVa.jpg, group-title: 2017-16-15 Germany Cinema}",
  5. "{tvg-id: , tvg-name: Antonio, ihm schmeckt's nicht! (2016), tvg-logo: https://i...content-available-to-author-only...b.org/t/p/w600_and_h900_bestv2/dyLfGb1mF2PUd0Rz5kqKiYtQl3r.jpg, group-title: 2017-16-15 Germany Cinema}"
  6. ]
  7.  
  8. def convert(example):
  9. pattern = r"([^\s:,{}]+):\s*([^,{}]*)"
  10. dct = {}
  11. if example.endswith and example.startswith:
  12. for t in re.findall(pattern, example):
  13. if t[1].strip():
  14. dct[t[0]] = t[1]
  15. else:
  16. dct[t[0]] = None
  17. return dct
  18.  
  19. for s in strings:
  20. print(convert(s))
Success #stdin #stdout 0.03s 9264KB
stdin
Standard input is empty
stdout
{'tvg-id': None, 'tvg-name': 'A beautiful Day - 2016', 'tvg-logo': 'https://i...content-available-to-author-only...b.org/t/p/w600_and_h900_bestv2/hZgsmIYUAtdUOUFKROq6rNyWXVa.jpg', 'group-title': '2017-16-15 Germany Cinema'}
{'tvg-id': None, 'tvg-name': 'Antonio', 'tvg-logo': 'https://i...content-available-to-author-only...b.org/t/p/w600_and_h900_bestv2/dyLfGb1mF2PUd0Rz5kqKiYtQl3r.jpg', 'group-title': '2017-16-15 Germany Cinema'}