No Description

skb.py 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from pprint import pprint
  5. import sys
  6. import codecs
  7. sys.stdout.reconfigure(encoding='utf-8')
  8. sys.stdin.reconfigure(encoding='utf-8')
  9. # reload(sys)
  10. # sys.setdefaultencoding('utf-8')
  11. path = 'skbchannel.txt'
  12. skb_channels = []
  13. channeljson = 'Channel.json'
  14. channeldatas = []
  15. #print (sys.stdin.encoding)
  16. #print (sys.stdout.encoding)
  17. with open(channeljson, encoding="utf-8") as json_data:
  18. channeldatas=json.load(json_data)
  19. json_data.close()
  20. with open(path, encoding="utf-8") as f:
  21. for line in f:
  22. inner_list = [elt.strip() for elt in line.split('\t')]
  23. skb_channels.append(inner_list)
  24. def getChanneldata(a):
  25. #print ("Search:" + a[1])
  26. try:
  27. findchannel=None
  28. for channeldata in channeldatas:
  29. channelnames=[(channeldata['SK Name']), (channeldata['KT Name']), channeldata['LG Name']]
  30. # print (channelnames)
  31. if(a[1] in channelnames):
  32. findchannel = channeldata
  33. break
  34. # print (findchannel['Source'])
  35. # if(findchannel['Source'] is "KT"):
  36. # print (findchannel)
  37. if(findchannel['Source']== "KT"):
  38. print (findchannel['Name'])
  39. if(len(a)<3):
  40. print ("ERR")
  41. findchannel['Name'] = a[1]
  42. findchannel['Id'] = int(a[0])
  43. findchannel['ServiceId'] = a[2]
  44. findchannel['SK Name']=a[1]
  45. findchannel['KT Name']=a[1]
  46. findchannel['LG Name']=a[1]
  47. if(findchannel['Source']== "NAVER"):
  48. print (findchannel['Name'])
  49. if(len(a)<3):
  50. print ("ERR")
  51. findchannel['Name'] = a[1]
  52. findchannel['Id'] = int(a[0])
  53. findchannel['ServiceId'] = a[2]
  54. findchannel['SK Name']=a[1]
  55. findchannel['KT Name']=a[1]
  56. findchannel['LG Name']=a[1]
  57. if(len(a)>2):
  58. findchannel = {"Id": 0,
  59. "Name": "",
  60. "KT Name": "",
  61. "KTCh": 0,
  62. "LG Name": "",
  63. "LGCh": 0,
  64. "SK Name": "",
  65. "SKCh": 0,
  66. "Radio Name": "",
  67. "RadioCh":0 ,
  68. "Icon_url": "",
  69. "Source": "SKB",
  70. "ServiceId": 0}
  71. findchannel['Name'] = a[1]
  72. findchannel['Id'] = int(a[0])
  73. findchannel['ServiceId'] = a[2]
  74. findchannel['SK Name']=a[1]
  75. findchannel['KT Name']=a[1]
  76. findchannel['LG Name']=a[1]
  77. # print (findchannel)
  78. if (findchannel==None):
  79. print ("error:" + a[1]+":"+a[0]+":"+str(len(a)))
  80. # print (findchannel)
  81. findchannel['Id']=int(a[0])
  82. findchannel['SK Name']=a[1]
  83. findchannel['SKCh']=int(a[0])
  84. except Exception as e:
  85. print ("error!!:" + a[1]+":"+a[0])
  86. print (e)
  87. return findchannel
  88. # else:
  89. # print (findchannel)
  90. MyChannelInfos = []
  91. for skb_channel in skb_channels:
  92. MyChannelInfo = getChanneldata(skb_channel)
  93. # print(MyChannelInfo)
  94. if(MyChannelInfo != None):
  95. # MyChannelInfo['Id']=str(skb_channel[0])
  96. # MyChannelInfo['SKCh']= skb_channel[0]
  97. # print(MyChannelInfo)
  98. MyChannelInfos.append(MyChannelInfo)
  99. # else:
  100. # print("None"+skb_channel[1])
  101. with open('Channel.json','w',encoding="utf-8") as outfile:
  102. json.dump(MyChannelInfos, outfile, indent=2,ensure_ascii=False)
  103. #print SKB_CHANNEL
  104. #print skb_channel[0][1]
  105. # //a = Channel name data
  106. # def getChannelNumber(a):
  107. # # print ("AAAA",a[0])
  108. # for skb_channel in skb_channels:
  109. # # print ("BBBB",skb_channel[1])
  110. # if((unicode(skb_channel[1]).find(a[0])>-1) and a[0]!=""):
  111. # return skb_channel[0]
  112. # elif((unicode(skb_channel[1]).find(a[1])>-1) and a[1]!=""):
  113. # return skb_channel[0]
  114. # elif((unicode(skb_channel[1]).find(a[2])>-1) and a[2]!=""):
  115. # return skb_channel[0]
  116. # return None
  117. #
  118. #
  119. # with open('Channel.json') as json_data:
  120. #
  121. # MyChannelInfo = []
  122. #
  123. # # print getChannelNumber('asf')
  124. # # getChannelNumber=""
  125. # for Channeldata in Channeldatajson:
  126. # test=[(Channeldata['SK Name']), (Channeldata['KT Name']), Channeldata['LG Name']]
  127. # channelNumber=getChannelNumber(test)
  128. # # print channelNumber
  129. # if(channelNumber is None):
  130. # print Channeldata['SK Name']
  131. # else :
  132. # # print channelNumber
  133. # Channeldata['Id']=channelNumber
  134. # MyChannelInfo.append(Channeldata)
  135. #
  136. # with open('data.txt','w') as outfile:
  137. # json.dump(MyChannelInfo, outfile)