I needs to convert base string to target string. I have a working code right now, but if there is a "," character where it says tvg-name, the code is broken and doesn't work. How can I fix this bug?
Base Working String: {tvg-id: , tvg-name: A beautiful Day - 2016, tvg-logo: https://image.tmdb.org/t/p/w600_and_h900_bestv2/hZgsmIYUAtdUOUFKROq6rNyWXVa.jpg, group-title: 2017-16-15 Germany Cinema}
Base Problem String: {tvg-id: , tvg-name: Antonio, ihm schmeckt's nicht! (2016), tvg-logo: https://image.tmdb.org/t/p/w600_and_h900_bestv2/dyLfGb1mF2PUd0Rz5kqKiYtQl3r.jpg, group-title: 2017-16-15 Germany Cinema}
Target: {"tvg-id": "None", "tvg-name": "Antonio, ihm schmeckt's nicht! (2016)", "tvg-logo": "https://image.tmdb.org/t/p/w600_and_h900_bestv2/dyLfGb1mF2PUd0Rz5kqKiYtQl3r.jpg", "group-title": "2017-16-15 Germany Cinema"}
My Convert Function
def convert(example):
#split the string into a list
example= example.replace("{", "").replace("}", "").split(",")
#create a dictionary
final = {}
#loop through the list
for i in example:
#split the string into a list
i = i.split(":")
#if http or https is in the list merge with next item
if "http" in i[1] or "https" in i[1]:
i[1] = i[1] + ":" + i[2]
i.pop(2)
#remove first char whitespace
if i[0][0] == " ":
i[0]=i[0][1:]
#remove first char whitespace
if i[1][0] == " ":
i[1]=i[1][1:]
final[i[0]] = i[1]
#return the dictionary
return final