#!/usr/bin/python
# -*- coding: utf-8 -*-

from urllib.request import urlopen

import os
import shutil
import sys
import twisted.python.runtime

try:
 os.remove("/etc/enigma2/xklass/x-playlists.json")
except OSError:
 pass
try:
 os.remove("/etc/enigma2/xklass/playlists.txt")
except OSError:
 pass 
 
 

with open('/usr/script/codeActivation') as f:
  code = f.read()
  response = urlopen('http://7c.ath.cx/clientapp/cl_dc_ws2.php?getE2Codes=' + code)
  tmp_path_pre = "/etc/enigma2/xklass/playlists.txt"
  target = open(tmp_path_pre, 'wb')
  content = response.read()
  target.write(content)
  target.close()
