Exemplo n.º 1
0
 def Add_Movie(self, movie):
     # add info to XML
     xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
     #check if movie info exists
     xml_movie = self.movies.find(xml_movie_hash)
     if xml_movie is None:   #-- create new record
         # create serial record in XML
         xml_movie = SubElement(self.movies, xml_movie_hash)
         xml_movie.text = movie['name']
         SubElement(xml_movie, "origin").text   = movie['origin']
         SubElement(xml_movie, "url").text      = movie['url']
         SubElement(xml_movie, "genre").text    = movie['genre']
         SubElement(xml_movie, "director").text = movie['director']
         SubElement(xml_movie, "actors").text   = movie['actor']
         SubElement(xml_movie, "text").text     = movie['descr']
         SubElement(xml_movie, "img").text      = movie['image']
         # add year info
         SubElement(xml_movie, "year").text     = movie['year']
         year_hash = self.Get_Movie_Year(movie['year'])
         # add movie category info
         SubElement(xml_movie, "categories")
         cat = xml_movie.find("categories")
         for cat_rec in movie['category']:
             cat_hash = self.Get_Movie_Type(cat_rec)
             if cat.find(cat_hash) is None:
                 SubElement(cat, cat_hash)
Exemplo n.º 2
0
def Save_Last_Serial_Info(tag, serial, serial_url, img, part):
    # get max history lenght
    try:
        max_history = (1, 5, 10, 20, 30, 50)[int(Addon.getSetting('history_len'))]
        if max_history > 99:
            max_history = 99
    except:
        max_history = 10

    sdate = today = date.today().isoformat()

    # load or create history file
    try:
        tree = ElementTree()
        tree.parse(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'))
        xml1 = tree.getroot()
    except:
        # create XML structure
        xml1 = Element("SERIALU_NET_HISTORY")

    # shrink history to limit
    if len(xml1) > max_history:
        idx = 1
        for rec in xml1:
            if idx >= max_history:
                xml1.remove(rec)
            idx = idx + 1

    # format name
    if part.find('[/COLOR]') > -1:
        part = re.compile('[COLOR FF00FF00](.+?)[/COLOR]', re.MULTILINE|re.DOTALL).find(part)

    xml_hist = None
    # update sequince number for history records
    for rec in xml1:
        if rec.tag == tag:
            rec.find("ID").text = str(0).zfill(2)
            xml_hist = rec
        else:
            rec.find("ID").text = str(int(rec.find("ID").text)+1).zfill(2)

    if xml_hist == None:
        xml_hist = SubElement(xml1, tag)
        SubElement(xml_hist, "ID").text     = str(0).zfill(2)
        SubElement(xml_hist, "Serial").text = unescape(serial)
        SubElement(xml_hist, "URL").text    = serial_url
        SubElement(xml_hist, "Date").text   = sdate
        SubElement(xml_hist, "Part").text   = unescape(part)
        SubElement(xml_hist, "Image").text  = img
    else:
        xml_hist.find("Part").text   = unescape(part)
        xml_hist.find("Date").text   = sdate

    # sort history by IDs
    xml1[:] = sorted(xml1, key=getkey)

    ElementTree(xml1).write(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'), encoding='utf-8')
Exemplo n.º 3
0
 def Get_Movie_Type(self, type_name):
     #-- store movie's category in XML
     xml_type_hash = 'st_' + self.f_md5(type_name)
     # check if type exists
     type = self.types.find(xml_type_hash)
     if type is None:
         type = SubElement(self.types, xml_type_hash)
         SubElement(type, "name").text = type_name
     #--
     return xml_type_hash
Exemplo n.º 4
0
 def Get_Movie_Year(self, year_name):
     #-- store movie's year in XML
     xml_type_hash = 'yr_' + self.f_md5(year_name)
     # check if year exists
     year = self.years.find(xml_type_hash)
     if year is None:
         year = SubElement(self.years, xml_type_hash)
         SubElement(year, "name").text = year_name
     #--
     return xml_type_hash
Exemplo n.º 5
0
def Save_History(name, url, img):
    tag = 'ch_'+f_md5(url).hexdigest()

    # get max history lenght
    try:
        max_history = (1, 5, 10, 20, 30, 50)[int(Addon.getSetting('history_len'))]
        if max_history > 99:
            max_history = 99
    except:
        max_history = 10

    sdate = today = date.today().isoformat()

    # load or create history file
    try:
        tree = ElementTree()
        tree.parse(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'))
        xml1 = tree.getroot()
    except:
        # create XML structure
        xml1 = Element("ULTIMATV_HISTORY")

    # shrink history to limit
    if len(xml1) > max_history:
        idx = 1
        for rec in xml1:
            if idx >= max_history:
                xml1.remove(rec)
            idx = idx + 1

    xml_hist = None
    # update sequince number for history records
    for rec in xml1:
        if rec.tag == tag:
            rec.find("ID").text = str(0).zfill(2)
            xml_hist = rec
        else:
            rec.find("ID").text = str(int(rec.find("ID").text)+1).zfill(2)

    if xml_hist == None:
        xml_hist = SubElement(xml1, tag)
        SubElement(xml_hist, "ID").text     = str(0).zfill(2)
        SubElement(xml_hist, "Channel").text = unescape(name)
        SubElement(xml_hist, "URL").text    = url
        SubElement(xml_hist, "Image").text  = img
        SubElement(xml_hist, "Date").text   = sdate
    else:
        xml_hist.find("Date").text   = sdate

    # sort history by IDs
    xml1[:] = sorted(xml1, key=getkey)

    ElementTree(xml1).write(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'), encoding='utf-8')
Exemplo n.º 6
0
    def __init__(self, mode):
        #--
        Addon = xbmcaddon.Addon(id='plugin.video.igru.net.ua')
        self.path = os.path.join(Addon.getAddonInfo('path'), r'resources', r'data')

        today = date.today()
        #--
        if mode == 'UPDATE':
            #load current serial list
            try:
                self.tree = ElementTree()
                self.tree.parse(os.path.join(self.path, 'movies.xml'))
                self.xml = self.tree.getroot()
                self.xml.find("LAST_UPDATE").text = today.isoformat()
                self.movies  = self.xml.find('MOVIES')
                self.types   = self.xml.find('TYPES')
                self.years   = self.xml.find('YEARS')
                self.info = "Update FEPCOM.NET Info"
                self.isUpdate= 1
                self.pinfo   = self.xml.find("LOADED_PAGES")
            except:
                # create XML structure
                self.xml = Element("IGRU_NET_UA")
                SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
                self.movies  = SubElement(self.xml, "MOVIES")
                self.types   = SubElement(self.xml, "TYPES")
                self.years   = SubElement(self.xml, "YEARS")
                self.info = "Reload FEPCOM.NET Info"
                self.isUpdate= 0
                self.pinfo   = SubElement(self.xml, "LOADED_PAGES")
        elif mode == 'READ':
             self.tree = ElementTree()
             self.tree.parse(os.path.join(self.path, 'movies.xml'))
             self.xml = self.tree.getroot()
             self.last_update = self.xml.find("LAST_UPDATE").text
             self.movies  = self.xml.find('MOVIES')
             self.types   = self.xml.find('TYPES')
             self.years   = self.xml.find('YEARS')
             self.info = "Update FEPCOM.NET Info"
             self.isUpdate= -1
             self.pinfo   = self.xml.find("LOADED_PAGES")
             self.pinfo.text = ''
        else:
            # create XML structure
            self.xml = Element("IGRU_NET_UA")
            SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
            self.movies  = SubElement(self.xml, "MOVIES")
            self.types   = SubElement(self.xml, "TYPES")
            self.years   = SubElement(self.xml, "YEARS")
            self.info = "Reload FEPCOM.NET Info"
            self.isUpdate= 0
            self.pinfo   = SubElement(self.xml, "LOADED_PAGES")
Exemplo n.º 7
0
Arquivo: update.py Projeto: serbra/ru
def Get_Film_Info(url, xml_serials, xml_types, xml_genres, serial_found, dp):
    html = get_HTML(url)
    if html == '':
        return False

    html_container = re.compile(
        '<div class="container">(.+?)<div class="navigation">',
        re.MULTILINE | re.DOTALL).findall(html)

    # -- parsing web page ----------------------------------------------------------

    soup = BeautifulSoup(''.join(html_container[0].replace('<p>',
                                                           '  ').replace(
                                                               '</p>', '')))

    serials = soup.findAll("div", {"class": "entry"})
    for ser in serials:
        #try:
        # check if process was cancelled
        if (dp.iscanceled()): return
        # --
        i_name = unescape(ser.find("h2").find("a").text.strip())
        i_url = ser.find("h2").find("a")["href"]
        xbmc.log(' ***    ' + i_name.encode('utf-8'))
        #-- detail info
        info = ser.find("div", {"class": "content"})
        try:
            i_image = info.find("img")["src"]
        except:
            ser_name = ser.find("h2").find("a").text.strip(
            )  #i_name.replace(u'”', u'"').replace(u'“',u'"').replace(u'«',u'"').replace(u'»',u'"')
            search_mask = '<p><img class="m_pic" alt="' + ser_name + '" align="left" src="(.+?)" /></p>'
            img_alt = re.compile(search_mask,
                                 re.MULTILINE | re.DOTALL).findall(html)
            try:
                i_image = img_alt[0]
            except:
                search_mask = '<p><img class="m_pic" alt="' + ser_name + '"" align="left" src="(.+?)" /></p>'
                img_alt = re.compile(search_mask,
                                     re.MULTILINE | re.DOTALL).findall(html)
                try:
                    i_image = img_alt[0]
                except:
                    i_image = '-'
                    xbmc.log(i_name.encode('utf-8') + ' - image not found')

        o_name = '-'
        i_year = '-'
        i_country = '-'
        i_genre = '-'
        i_director = '-'
        i_actors = '-'
        i_text = '-'

        for inf in info.findAll("strong"):
            if inf.text.encode('utf-8') == 'Оригинальное название:':
                o_name = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Год выхода на экран:':
                i_year = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Страна:':
                i_country = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Сериал относится к жанру:':
                i_genre = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Постановщик':
                i_director = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode(
                    'utf-8') == 'Актеры, принявшие участие в съемках:':
                i_actors = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Краткое описание:':
                i_text = unescape(str(inf.nextSibling))

        full_text = i_text
        if o_name != '':
            full_text = full_text + (u'\nОригинальное название: ') + o_name
        if i_actors != '':
            full_text = full_text + (u'\nАктеры: ') + i_actors

        # add info to XML
        xml_serial_hash = 'ser_' + f_md5(
            (i_name + i_year).encode('utf-8')).hexdigest()
        #check if serial info exists
        xml_serial = xml_serials.find(xml_serial_hash)
        if xml_serial is None:  #-- create new record
            # create serial record in XML
            xml_serial = SubElement(xml_serials, xml_serial_hash)
            xml_serial.text = i_name
            SubElement(xml_serial, "name").text = i_name
            SubElement(xml_serial, "url").text = i_url
            SubElement(xml_serial, "year").text = i_year
            SubElement(xml_serial, "genre").text = i_genre
            SubElement(xml_serial, "director").text = i_director
            SubElement(xml_serial, "text").text = full_text
            SubElement(xml_serial, "img").text = i_image
            SubElement(xml_serial, "categories")
            SubElement(xml_serial, "genres")

        isCategory_found = 'n'
        # add serial category info
        categories = xml_serial.find("categories")
        for cat in ser.find("div", {"class": "cat"}).findAll("a"):
            if cat.text.encode('utf-8') <> 'Сериалы':
                cur_type_hash = 'sc_' + f_md5(
                    cat.text.strip().lower().encode('utf-8')).hexdigest()
                # check if category exists
                if xml_types.find(cur_type_hash) is None:
                    type = SubElement(xml_types, cur_type_hash)
                    SubElement(type, "name").text = unescape(
                        cat.text.strip()).capitalize()
                if categories.find(cur_type_hash) is None:
                    SubElement(categories, cur_type_hash)
                isCategory_found = 'y'

        isMultserial = 'n'
        # add serial genre info
        genres = xml_serial.find("genres")
        for gen in i_genre.split(','):
            cur_genre_hash = 'sg_' + f_md5(
                gen.strip().lower().encode('utf-8')).hexdigest()
            # check if category exists
            if xml_genres.find(cur_genre_hash) is None:
                genre = SubElement(xml_genres, cur_genre_hash)
                SubElement(genre,
                           "name").text = unescape(gen.strip()).capitalize()
            if genres.find(cur_genre_hash) is None:
                SubElement(genres, cur_genre_hash)
            # check if it's multserial
            if gen.encode(
                    'utf-8') == 'Мультсериал' and isCategory_found == 'n':
                isMultserial = 'y'

        # add multserial or foreighn serial types
        if isCategory_found == 'n':
            if isMultserial == 'y':
                # add serial category info
                categories = xml_serial.find("categories")
                cur_type_hash = 'sc_' + f_md5(
                    (u'Мультсериалы').lower().encode('utf-8')).hexdigest()
                # check if category exists
                if xml_types.find(cur_type_hash) is None:
                    type = SubElement(xml_types, cur_type_hash)
                    SubElement(type, "name").text = u'Мультсериалы'
                if categories.find(cur_type_hash) is None:
                    SubElement(categories, cur_type_hash)
            else:
                if i_country.encode('utf-8') == 'Россия':
                    # add serial category info
                    categories = xml_serial.find("categories")
                    cur_type_hash = 'sc_' + f_md5(
                        (u'Русские сериалы'
                         ).lower().encode('utf-8')).hexdigest()
                    # check if category exists
                    if xml_types.find(cur_type_hash) is None:
                        type = SubElement(xml_types, cur_type_hash)
                        SubElement(type, "name").text = u'Русские сериалы'
                    if categories.find(cur_type_hash) is None:
                        SubElement(categories, cur_type_hash)
                else:
                    # add serial category info
                    categories = xml_serial.find("categories")
                    cur_type_hash = 'sc_' + f_md5(
                        (u'Зарубежные сериалы'
                         ).lower().encode('utf-8')).hexdigest()
                    # check if category exists
                    if xml_types.find(cur_type_hash) is None:
                        type = SubElement(xml_types, cur_type_hash)
                        SubElement(type, "name").text = u'Зарубежные сериалы'
                    if categories.find(cur_type_hash) is None:
                        SubElement(categories, cur_type_hash)

        # update info in progress dialog
        serial_found = serial_found + 1
        #except:
        #xbmc.log(formatExceptionInfo())

    return serial_found
Exemplo n.º 8
0
Arquivo: update.py Projeto: serbra/ru
def Update_Serial_XML(mode):
    #show Dialog
    dp = xbmcgui.DialogProgress()

    isUpdate = 0

    if mode == 'UPDATE':
        #load current serial list
        try:
            tree = ElementTree()
            tree.parse(os.path.join(path, r'serials.xml'))
            xml1 = tree.getroot()
            xml1.find("LAST_UPDATE").text = today.isoformat()
            xml_serials = xml1.find('SERIALS')
            xml_types = xml1.find('TYPES')
            xml_genres = xml1.find('GENRES')
            dp.create("Update SERIALU.NET Info")
            isUpdate = 1
        except:
            # create XML structure
            xml1 = Element("SERIALU_NET")
            SubElement(xml1, "LAST_UPDATE").text = today.isoformat()
            xml_serials = SubElement(xml1, "SERIALS")
            xml_types = SubElement(xml1, "TYPES")
            xml_genres = SubElement(xml1, "GENRES")
            dp.create("Reload SERIALU.NET Info")
    else:
        # create XML structure
        xml1 = Element("SERIALU_NET")
        SubElement(xml1, "LAST_UPDATE").text = today.isoformat()
        xml_serials = SubElement(xml1, "SERIALS")
        xml_types = SubElement(xml1, "TYPES")
        xml_genres = SubElement(xml1, "GENRES")
        dp.create("Reload SERIALU.NET Info")

    # grab serial's info from site
    url = 'http://serialu.net/'
    #start_time = datetime.now()
    serial_found = 0

    # get max page number for update
    print Addon.getSetting('update_len')
    try:
        max_page = (10, 20, 50, 100, 1000)[int(Addon.getSetting('update_len'))]
    except:
        max_page = 10

    # get number of webpages to grab information
    page_num = Get_Page_Number(url)

    if isUpdate == 1:
        page_num = min(page_num, max_page)

    # get all serials
    for count in range(1, page_num + 1):
        xbmc.log(' ***  page ' + str(count))
        serial_found = Get_Film_Info(url + '/page/' + str(count) + '/',
                                     xml_serials, xml_types, xml_genres,
                                     serial_found, dp)
        percent = min(count * 100 / page_num, 100)
        dp.update(percent, '',
                  'Loaded: ' + str(count) + ' of ' + str(page_num) + ' pages',
                  'Кол-во сериалов: ' + str(serial_found))

    # order sort serials/categories/genres by names
    xml_serials[:] = sorted(xml_serials, key=getkey)
    xml_types[:] = sorted(xml_types, key=getkey)
    xml_genres[:] = sorted(xml_genres, key=getkey)

    dp.close()
    ElementTree(xml1).write(os.path.join(path, r'serials.xml'),
                            encoding='utf-8')
Exemplo n.º 9
0
    def Make_GMP_File(self, save_gmp_path):
        GRMProject = Element("GRMProject")
        GRMProject.set("xmlns", "http://tempuri.org/GRMProject.xsd")
        ProjectSettings = SubElement(GRMProject, "ProjectSettings")
        SubElement(ProjectSettings, 'ProjectFile').text = save_gmp_path
        SubElement(ProjectSettings, 'GRMSimulationType').text = 'SingleEvent'
        SubElement(ProjectSettings, 'WatershedFile')
        SubElement(ProjectSettings, 'SlopeFile')
        SubElement(ProjectSettings, 'FlowDirectionFile')
        SubElement(ProjectSettings, 'FlowAccumFile')
        SubElement(ProjectSettings, 'StreamFile')
        SubElement(ProjectSettings, 'ChannelWidthFile')
        SubElement(ProjectSettings, 'InitialSoilSaturationRatioFile')
        SubElement(ProjectSettings, 'LandCoverDataType').text = 'File'
        SubElement(ProjectSettings, 'LandCoverFile')
        SubElement(ProjectSettings, 'LandCoverVATFile')
        SubElement(ProjectSettings, 'ConstantRoughnessCoeff')
        SubElement(ProjectSettings, 'ConstantImperviousRatio')
        SubElement(ProjectSettings, 'SoilTextureDataType').text = 'File'
        SubElement(ProjectSettings, 'SoilTextureFile')
        SubElement(ProjectSettings, 'SoilTextureVATFile')
        SubElement(ProjectSettings, 'ConstantSoilPorosity')
        SubElement(ProjectSettings, 'ConstantSoilEffPorosity')
        SubElement(ProjectSettings, 'ConstantSoilWettingFrontSuctionHead')
        SubElement(ProjectSettings, 'ConstantSoilHydraulicConductivity')
        SubElement(ProjectSettings, 'SoilDepthDataType').text = 'File'
        SubElement(ProjectSettings, 'SoilDepthFile')
        SubElement(ProjectSettings, 'SoilDepthVATFile')
        SubElement(ProjectSettings, 'ConstantSoilDepth')
        SubElement(ProjectSettings, 'InitialChannelFlowFile')
        SubElement(ProjectSettings,
                   'RainfallDataType').text = 'TextFileASCgrid'
        SubElement(ProjectSettings, 'RainfallInterval')
        SubElement(ProjectSettings, 'RainfallDataFile')
        SubElement(ProjectSettings,
                   'FlowDirectionType').text = 'StartsFromE_TauDEM'
        SubElement(ProjectSettings, 'GridCellSize')
        SubElement(ProjectSettings, 'IsParallel').text = 'true'
        SubElement(ProjectSettings, 'MaxDegreeOfParallelism').text = '-1'
        SubElement(ProjectSettings, 'SimulStartingTime').text = '0'
        SubElement(ProjectSettings, 'ComputationalTimeStep')
        SubElement(ProjectSettings, 'IsFixedTimeStep').text = 'false'
        SubElement(ProjectSettings, 'SimulationDuration')
        SubElement(ProjectSettings, 'OutputTimeStep')
        SubElement(ProjectSettings, 'SimulateInfiltration').text = 'true'
        SubElement(ProjectSettings, 'SimulateSubsurfaceFlow').text = 'true'
        SubElement(ProjectSettings, 'SimulateBaseFlow').text = 'true'
        SubElement(ProjectSettings, 'SimulateFlowControl').text = 'false'
        SubElement(ProjectSettings, 'CrossSectionType').text = 'CSSingle'
        SubElement(ProjectSettings,
                   'SingleCSChannelWidthType').text = 'CWGemeration'
        SubElement(ProjectSettings, 'ChannelWidthEQc').text = '1.698'
        SubElement(ProjectSettings, 'ChannelWidthEQd').text = '0.318'
        SubElement(ProjectSettings, 'ChannelWidthEQe').text = '0.5'
        SubElement(ProjectSettings, 'ChannelWidthMostDownStream')
        SubElement(ProjectSettings, 'LowerRegionHeight')
        SubElement(ProjectSettings, 'LowerRegionBaseWidth')
        SubElement(ProjectSettings, 'UpperRegionBaseWidth')
        SubElement(ProjectSettings, 'CompoundCSIniFlowDepth')
        SubElement(ProjectSettings, 'CompoundCSChannelWidthLimit')
        SubElement(ProjectSettings, 'BankSideSlopeRight').text = '1.5'
        SubElement(ProjectSettings, 'BankSideSlopeLeft').text = '1.5'
        SubElement(ProjectSettings, 'MakeIMGFile').text = 'false'
        SubElement(ProjectSettings, 'MakeASCFile').text = 'false'
        SubElement(ProjectSettings, 'MakeSoilSaturationDistFile').text = 'true'
        SubElement(ProjectSettings, 'MakeRfDistFile').text = 'true'
        SubElement(ProjectSettings, 'MakeRFaccDistFile').text = 'true'
        SubElement(ProjectSettings, 'MakeFlowDistFile').text = 'true'
        SubElement(ProjectSettings, 'PrintOption').text = 'All'
        SubElement(ProjectSettings, 'WriteLog').text = 'false'
        SubElement(ProjectSettings, 'AboutThisProject')
        SubElement(ProjectSettings, 'AboutWatershed')
        SubElement(ProjectSettings, 'AboutLandCoverMap')
        SubElement(ProjectSettings, 'AboutSoilMap')
        SubElement(ProjectSettings, 'AboutSoilDepthMap')
        SubElement(ProjectSettings, 'AboutRainfall')
        SubElement(ProjectSettings, 'ProjectSavedTime')

        # PC 이름 가져오기
        pc_name = os.getenv("COMPUTERNAME")

        # USER (로그인 된 계정) 이름 가져오기
        user_name = os.getenv("USERNAME")

        Path = os.path.dirname(os.path.realpath(__file__)) + "\DLL\GRMCore.dll"
        clsGRM = cGRM(Path)

        SubElement(ProjectSettings, 'ComputerName').text = pc_name
        SubElement(ProjectSettings, 'ComputerUserName').text = user_name
        SubElement(ProjectSettings,
                   'GRMVersion').text = str(clsGRM.BuildInfo.FileVersion)
        ElementTree(GRMProject).write(save_gmp_path,
                                      encoding="utf-8",
                                      xml_declaration=True)
Exemplo n.º 10
0
import urllib2, urllib, re, cookielib, sys, time

# load XML library
sys.path.append(r'g:\XBMC\resources\lib')
from ElementTree import Element, SubElement, ElementTree

window = Element("window")

title = SubElement(window, "title", font="large")
title.text = ("Проверка АБВГД..").decode('utf-8')

text = SubElement(window, "text", wrap="word")

box = SubElement(text, "buttonbox1")
SubElement(box, "button").text = ("OK").decode('utf-8')
SubElement(box, "button").text = ("Проба записи").decode('utf-8')

box = SubElement(text, "buttonbox2")
SubElement(box, "button").text = ("Error").decode('utf-8')
SubElement(box, "button").text = ("Але! Гараж").decode('utf-8')

ElementTree(window).write(r'g:\xbmc\resources\data\test.xml', encoding='utf-8')
Exemplo n.º 11
0
import urllib2, urllib, re, cookielib, sys, time

# load XML library
sys.path.append(r'g:\XBMC\resources\lib')
from ElementTree  import Element, SubElement, ElementTree

window = Element("window")

title = SubElement(window, "title", font="large")
title.text = ("Проверка АБВГД..").decode('utf-8')

text = SubElement(window, "text", wrap="word")

box = SubElement(text, "buttonbox1")
SubElement(box, "button").text = ("OK").decode('utf-8')
SubElement(box, "button").text = ("Проба записи").decode('utf-8')

box = SubElement(text, "buttonbox2")
SubElement(box, "button").text = ("Error").decode('utf-8')
SubElement(box, "button").text = ("Але! Гараж").decode('utf-8')

ElementTree(window).write(r'g:\xbmc\resources\data\test.xml', encoding='utf-8')



Exemplo n.º 12
0
    def __init__(self, mode):
        #--
        Addon = xbmcaddon.Addon(id='plugin.video.igru.net.ua')
        self.path = os.path.join(Addon.getAddonInfo('path'), r'resources',
                                 r'data')

        today = date.today()
        #--
        if mode == 'UPDATE':
            #load current serial list
            try:
                self.tree = ElementTree()
                self.tree.parse(os.path.join(self.path, 'movies.xml'))
                self.xml = self.tree.getroot()
                self.xml.find("LAST_UPDATE").text = today.isoformat()
                self.movies = self.xml.find('MOVIES')
                self.types = self.xml.find('TYPES')
                self.years = self.xml.find('YEARS')
                self.info = "Update FEPCOM.NET Info"
                self.isUpdate = 1
                self.pinfo = self.xml.find("LOADED_PAGES")
            except:
                # create XML structure
                self.xml = Element("IGRU_NET_UA")
                SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
                self.movies = SubElement(self.xml, "MOVIES")
                self.types = SubElement(self.xml, "TYPES")
                self.years = SubElement(self.xml, "YEARS")
                self.info = "Reload FEPCOM.NET Info"
                self.isUpdate = 0
                self.pinfo = SubElement(self.xml, "LOADED_PAGES")
        elif mode == 'READ':
            self.tree = ElementTree()
            self.tree.parse(os.path.join(self.path, 'movies.xml'))
            self.xml = self.tree.getroot()
            self.last_update = self.xml.find("LAST_UPDATE").text
            self.movies = self.xml.find('MOVIES')
            self.types = self.xml.find('TYPES')
            self.years = self.xml.find('YEARS')
            self.info = "Update FEPCOM.NET Info"
            self.isUpdate = -1
            self.pinfo = self.xml.find("LOADED_PAGES")
            self.pinfo.text = ''
        else:
            # create XML structure
            self.xml = Element("IGRU_NET_UA")
            SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
            self.movies = SubElement(self.xml, "MOVIES")
            self.types = SubElement(self.xml, "TYPES")
            self.years = SubElement(self.xml, "YEARS")
            self.info = "Reload FEPCOM.NET Info"
            self.isUpdate = 0
            self.pinfo = SubElement(self.xml, "LOADED_PAGES")
Exemplo n.º 13
0
class MovieDB:
    #-- init
    def __init__(self, mode):
        #--
        Addon = xbmcaddon.Addon(id='plugin.video.igru.net.ua')
        self.path = os.path.join(Addon.getAddonInfo('path'), r'resources',
                                 r'data')

        today = date.today()
        #--
        if mode == 'UPDATE':
            #load current serial list
            try:
                self.tree = ElementTree()
                self.tree.parse(os.path.join(self.path, 'movies.xml'))
                self.xml = self.tree.getroot()
                self.xml.find("LAST_UPDATE").text = today.isoformat()
                self.movies = self.xml.find('MOVIES')
                self.types = self.xml.find('TYPES')
                self.years = self.xml.find('YEARS')
                self.info = "Update FEPCOM.NET Info"
                self.isUpdate = 1
                self.pinfo = self.xml.find("LOADED_PAGES")
            except:
                # create XML structure
                self.xml = Element("IGRU_NET_UA")
                SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
                self.movies = SubElement(self.xml, "MOVIES")
                self.types = SubElement(self.xml, "TYPES")
                self.years = SubElement(self.xml, "YEARS")
                self.info = "Reload FEPCOM.NET Info"
                self.isUpdate = 0
                self.pinfo = SubElement(self.xml, "LOADED_PAGES")
        elif mode == 'READ':
            self.tree = ElementTree()
            self.tree.parse(os.path.join(self.path, 'movies.xml'))
            self.xml = self.tree.getroot()
            self.last_update = self.xml.find("LAST_UPDATE").text
            self.movies = self.xml.find('MOVIES')
            self.types = self.xml.find('TYPES')
            self.years = self.xml.find('YEARS')
            self.info = "Update FEPCOM.NET Info"
            self.isUpdate = -1
            self.pinfo = self.xml.find("LOADED_PAGES")
            self.pinfo.text = ''
        else:
            # create XML structure
            self.xml = Element("IGRU_NET_UA")
            SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
            self.movies = SubElement(self.xml, "MOVIES")
            self.types = SubElement(self.xml, "TYPES")
            self.years = SubElement(self.xml, "YEARS")
            self.info = "Reload FEPCOM.NET Info"
            self.isUpdate = 0
            self.pinfo = SubElement(self.xml, "LOADED_PAGES")

    #-- system functions -------------------------------------------------------
    def getkey(self, elem):
        return elem.text

    def getkey_name(self, elem):
        return elem.findtext("name")

    def f_md5(self, str):
        rez = md5(str.encode('utf8'))
        return rez.hexdigest()

    def movie_sort_compare(self, a, b):
        return cmp(a['name'], b['name'])

    #-- check if movie exists --------------------------------------------------
    def Is_Movie_Exists(self, url):
        is_found = 0

        for rec in self.movies:
            if rec.find('url').text == url:
                is_found = 1
                break

        return is_found

    #-- get number of loaded pages ---------------------------------------------
    def Get_Loaded_Pages(self, id):
        try:
            pages = int(self.pinfo.find('r' + str(id)).text)
        except:
            pages = 0

        return pages

    #-- set number of loaded pages ---------------------------------------------
    def Set_Loaded_Pages(self, id, pages):
        try:
            self.pinfo.find('r' + str(id)).text = str(pages)
        except:
            SubElement(self.pinfo, 'r' + str(id)).text = str(pages)

    #-- save to file -----------------------------------------------------------
    def Save_to_XML(self):
        #-- sort serials/categories/years
        self.movies[:] = sorted(self.movies, key=self.getkey)
        self.types[:] = sorted(self.types, key=self.getkey_name)
        self.years[:] = sorted(self.years, key=self.getkey_name, reverse=True)
        #-- save to XML file
        ElementTree(self.xml).write(os.path.join(self.path, 'movies.xml'),
                                    encoding='utf-8')

    #-- add movie --------------------------------------------------------------
    def Add_Movie(self, movie):
        # add info to XML
        xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
        #check if movie info exists
        xml_movie = self.movies.find(xml_movie_hash)
        if xml_movie is None:  #-- create new record
            # create serial record in XML
            xml_movie = SubElement(self.movies, xml_movie_hash)
            xml_movie.text = movie['name']
            SubElement(xml_movie, "origin").text = movie['origin']
            SubElement(xml_movie, "url").text = movie['url']
            SubElement(xml_movie, "genre").text = movie['genre']
            SubElement(xml_movie, "director").text = movie['director']
            SubElement(xml_movie, "actors").text = movie['actor']
            SubElement(xml_movie, "text").text = movie['descr']
            SubElement(xml_movie, "img").text = movie['image']
            # add year info
            SubElement(xml_movie, "year").text = movie['year']
            year_hash = self.Get_Movie_Year(movie['year'])
            # add movie category info
            SubElement(xml_movie, "categories")
            cat = xml_movie.find("categories")
            for cat_rec in movie['category']:
                cat_hash = self.Get_Movie_Type(cat_rec)
                if cat.find(cat_hash) is None:
                    SubElement(cat, cat_hash)

    #-- get type ---------------------------------------------------------------
    def Get_Movie_Type(self, type_name):
        #-- store movie's category in XML
        xml_type_hash = 'st_' + self.f_md5(type_name)
        # check if type exists
        type = self.types.find(xml_type_hash)
        if type is None:
            type = SubElement(self.types, xml_type_hash)
            SubElement(type, "name").text = type_name
        #--
        return xml_type_hash

    #-- get year ---------------------------------------------------------------
    def Get_Movie_Year(self, year_name):
        #-- store movie's year in XML
        xml_type_hash = 'yr_' + self.f_md5(year_name)
        # check if year exists
        year = self.years.find(xml_type_hash)
        if year is None:
            year = SubElement(self.years, xml_type_hash)
            SubElement(year, "name").text = year_name
        #--
        return xml_type_hash

    #-- get type list ----------------------------------------------------------
    def Get_List_Type(self):
        return self.types

    #-- get year list ---------------------------------------------------------
    def Get_List_Year(self):
        return self.years

    #-- get movie list ----------------------------------------------------------
    def Get_List_Movie(self, par_tag, par_year, par_type_hash):
        movie_list = []

        for rec in self.movies:
            #-- get movie info
            i = self.Get_Movie_Info(rec)

            if unicode(i['year']).isnumeric():
                i_year = int(i['year'])
            else:
                i_year = 0
            # checkout by category or name/year
            if par_tag <> '*' and par_tag <> '':
                if par_tag not in i['name']:
                    continue
            if par_year <> '':
                if int(par_year) <> i_year:
                    continue
            if par_type_hash <> '':
                if rec.find('categories').find(par_type_hash) is None:
                    continue

            movie_list.append(i)
        #-- sort list
        movie_list.sort(self.movie_sort_compare)

        return movie_list, len(movie_list)

    #---------- get movie info -----------------------------------------------------
    def Get_Movie_Info(self, rec):
        mi = []
        mi = {}
        #-- name
        mi['name'] = rec.text.encode('utf8')
        #-- origin name
        try:
            mi['origin'] = rec.find('origin').text.encode('utf8')
        except:
            mi['origin'] = ''
        #-- image
        try:
            mi['img'] = rec.find('img').text.encode('utf8')
        except:
            mi['img'] = ''
        #-- url
        try:
            mi['url'] = rec.find('url').text.encode('utf8')
        except:
            mi['url'] = ''
        #-- year
        try:
            mi['year'] = rec.find('year').text.encode('utf8')
        except:
            mi['year'] = ''
        if unicode(mi['year'].decode('utf8')).strip().isnumeric(): pass
        else:
            try:
                mi['year'] = re.compile('([0-9][0-9][0-9][0-9])', re.MULTILINE
                                        | re.DOTALL).findall(mi['year'])[0]
            except:
                mi['year'] = '0000'
        #-- genre
        try:
            mi['genre'] = rec.find('genre').text.encode('utf8')
        except:
            mi['genre'] = ''
        #-- director
        try:
            mi['director'] = rec.find('director').text.encode('utf8')
        except:
            mi['director'] = ''
        #-- actors
        try:
            mi['actors'] = rec.find('actors').text.encode('utf8')
        except:
            mi['actors'] = ''
        #-- description
        try:
            mi['text'] = rec.find('text').text.encode('utf8')
        except:
            mi['text'] = ''
        #-----
        return mi
Exemplo n.º 14
0
 def Add_Movie(self, movie):
     # add info to XML
     xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
     #check if movie info exists
     xml_movie = self.movies.find(xml_movie_hash)
     if xml_movie is None:  #-- create new record
         # create serial record in XML
         xml_movie = SubElement(self.movies, xml_movie_hash)
         xml_movie.text = movie['name']
         SubElement(xml_movie, "origin").text = movie['origin']
         SubElement(xml_movie, "url").text = movie['url']
         SubElement(xml_movie, "genre").text = movie['genre']
         SubElement(xml_movie, "director").text = movie['director']
         SubElement(xml_movie, "actors").text = movie['actor']
         SubElement(xml_movie, "text").text = movie['descr']
         SubElement(xml_movie, "img").text = movie['image']
         # add year info
         SubElement(xml_movie, "year").text = movie['year']
         year_hash = self.Get_Movie_Year(movie['year'])
         # add movie category info
         SubElement(xml_movie, "categories")
         cat = xml_movie.find("categories")
         for cat_rec in movie['category']:
             cat_hash = self.Get_Movie_Type(cat_rec)
             if cat.find(cat_hash) is None:
                 SubElement(cat, cat_hash)
Exemplo n.º 15
0
 def Set_Loaded_Pages(self, id, pages):
     try:
         self.pinfo.find('r' + str(id)).text = str(pages)
     except:
         SubElement(self.pinfo, 'r' + str(id)).text = str(pages)
Exemplo n.º 16
0
class MovieDB:
    #-- init
    def __init__(self, mode):
        #--
        Addon = xbmcaddon.Addon(id='plugin.video.igru.net.ua')
        self.path = os.path.join(Addon.getAddonInfo('path'), r'resources', r'data')

        today = date.today()
        #--
        if mode == 'UPDATE':
            #load current serial list
            try:
                self.tree = ElementTree()
                self.tree.parse(os.path.join(self.path, 'movies.xml'))
                self.xml = self.tree.getroot()
                self.xml.find("LAST_UPDATE").text = today.isoformat()
                self.movies  = self.xml.find('MOVIES')
                self.types   = self.xml.find('TYPES')
                self.years   = self.xml.find('YEARS')
                self.info = "Update FEPCOM.NET Info"
                self.isUpdate= 1
                self.pinfo   = self.xml.find("LOADED_PAGES")
            except:
                # create XML structure
                self.xml = Element("IGRU_NET_UA")
                SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
                self.movies  = SubElement(self.xml, "MOVIES")
                self.types   = SubElement(self.xml, "TYPES")
                self.years   = SubElement(self.xml, "YEARS")
                self.info = "Reload FEPCOM.NET Info"
                self.isUpdate= 0
                self.pinfo   = SubElement(self.xml, "LOADED_PAGES")
        elif mode == 'READ':
             self.tree = ElementTree()
             self.tree.parse(os.path.join(self.path, 'movies.xml'))
             self.xml = self.tree.getroot()
             self.last_update = self.xml.find("LAST_UPDATE").text
             self.movies  = self.xml.find('MOVIES')
             self.types   = self.xml.find('TYPES')
             self.years   = self.xml.find('YEARS')
             self.info = "Update FEPCOM.NET Info"
             self.isUpdate= -1
             self.pinfo   = self.xml.find("LOADED_PAGES")
             self.pinfo.text = ''
        else:
            # create XML structure
            self.xml = Element("IGRU_NET_UA")
            SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
            self.movies  = SubElement(self.xml, "MOVIES")
            self.types   = SubElement(self.xml, "TYPES")
            self.years   = SubElement(self.xml, "YEARS")
            self.info = "Reload FEPCOM.NET Info"
            self.isUpdate= 0
            self.pinfo   = SubElement(self.xml, "LOADED_PAGES")


    #-- system functions -------------------------------------------------------
    def getkey(self, elem):
        return elem.text

    def getkey_name(self, elem):
        return elem.findtext("name")

    def f_md5(self, str):
        rez = md5(str.encode('utf8'))
        return rez.hexdigest()

    def movie_sort_compare(self, a, b):
        return cmp(a['name'], b['name'])

    #-- check if movie exists --------------------------------------------------
    def Is_Movie_Exists(self, url):
        is_found = 0

        for rec in self.movies:
            if rec.find('url').text == url:
                is_found = 1
                break

        return is_found

    #-- get number of loaded pages ---------------------------------------------
    def Get_Loaded_Pages(self, id):
        try:
            pages = int(self.pinfo.find('r'+str(id)).text)
        except:
            pages = 0

        return pages

    #-- set number of loaded pages ---------------------------------------------
    def Set_Loaded_Pages(self, id, pages):
        try:
            self.pinfo.find('r'+str(id)).text = str(pages)
        except:
            SubElement(self.pinfo, 'r'+str(id)).text = str(pages)

    #-- save to file -----------------------------------------------------------
    def Save_to_XML(self):
        #-- sort serials/categories/years
        self.movies[:]  = sorted(self.movies, key=self.getkey)
        self.types[:]   = sorted(self.types,  key=self.getkey_name)
        self.years[:]   = sorted(self.years,  key=self.getkey_name, reverse=True)
        #-- save to XML file
        ElementTree(self.xml).write(os.path.join(self.path, 'movies.xml'), encoding='utf-8')

    #-- add movie --------------------------------------------------------------
    def Add_Movie(self, movie):
        # add info to XML
        xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
        #check if movie info exists
        xml_movie = self.movies.find(xml_movie_hash)
        if xml_movie is None:   #-- create new record
            # create serial record in XML
            xml_movie = SubElement(self.movies, xml_movie_hash)
            xml_movie.text = movie['name']
            SubElement(xml_movie, "origin").text   = movie['origin']
            SubElement(xml_movie, "url").text      = movie['url']
            SubElement(xml_movie, "genre").text    = movie['genre']
            SubElement(xml_movie, "director").text = movie['director']
            SubElement(xml_movie, "actors").text   = movie['actor']
            SubElement(xml_movie, "text").text     = movie['descr']
            SubElement(xml_movie, "img").text      = movie['image']
            # add year info
            SubElement(xml_movie, "year").text     = movie['year']
            year_hash = self.Get_Movie_Year(movie['year'])
            # add movie category info
            SubElement(xml_movie, "categories")
            cat = xml_movie.find("categories")
            for cat_rec in movie['category']:
                cat_hash = self.Get_Movie_Type(cat_rec)
                if cat.find(cat_hash) is None:
                    SubElement(cat, cat_hash)

    #-- get type ---------------------------------------------------------------
    def Get_Movie_Type(self, type_name):
        #-- store movie's category in XML
        xml_type_hash = 'st_'+self.f_md5(type_name)
        # check if type exists
        type = self.types.find(xml_type_hash)
        if type is None:
            type = SubElement(self.types, xml_type_hash)
            SubElement(type, "name").text = type_name
        #--
        return xml_type_hash

    #-- get year ---------------------------------------------------------------
    def Get_Movie_Year(self, year_name):
        #-- store movie's year in XML
        xml_type_hash = 'yr_'+self.f_md5(year_name)
        # check if year exists
        year = self.years.find(xml_type_hash)
        if year is None:
            year = SubElement(self.years, xml_type_hash)
            SubElement(year, "name").text = year_name
        #--
        return xml_type_hash

    #-- get type list ----------------------------------------------------------
    def Get_List_Type(self):
        return self.types

     #-- get year list ---------------------------------------------------------
    def Get_List_Year(self):
        return self.years

     #-- get movie list ----------------------------------------------------------
    def Get_List_Movie(self, par_tag, par_year, par_type_hash):
        movie_list = []

        for rec in self.movies:
            #-- get movie info
            i = self.Get_Movie_Info(rec)

            if unicode(i['year']).isnumeric():
                i_year      = int(i['year'])
            else:
                i_year      = 0
            # checkout by category or name/year
            if par_tag <> '*' and par_tag <> '':
                if par_tag not in i['name']:
                        continue
            if par_year <> '':
                if int(par_year) <> i_year:
                    continue
            if par_type_hash <> '':
                if rec.find('categories').find(par_type_hash) is None:
                    continue

            movie_list.append(i)
        #-- sort list
        movie_list.sort(self.movie_sort_compare)

        return movie_list, len(movie_list)

    #---------- get movie info -----------------------------------------------------
    def Get_Movie_Info(self, rec):
        mi = []
        mi = {}
        #-- name
        mi['name']     = rec.text.encode('utf8')
        #-- origin name
        try:    mi['origin']      = rec.find('origin').text.encode('utf8')
        except: mi['origin']      = ''
        #-- image
        try:    mi['img']          = rec.find('img').text.encode('utf8')
        except: mi['img']          = ''
        #-- url
        try:    mi['url']          = rec.find('url').text.encode('utf8')
        except: mi['url']          = ''
        #-- year
        try:    mi['year']         = rec.find('year').text.encode('utf8')
        except: mi['year']         = ''
        if unicode(mi['year'].decode('utf8')).strip().isnumeric(): pass
        else:
            try:
                mi['year'] = re.compile('([0-9][0-9][0-9][0-9])', re.MULTILINE|re.DOTALL).findall(mi['year'])[0]
            except:
                mi['year']= '0000'
        #-- genre
        try:    mi['genre']        = rec.find('genre').text.encode('utf8')
        except: mi['genre']        = ''
        #-- director
        try:    mi['director']     = rec.find('director').text.encode('utf8')
        except: mi['director']     = ''
        #-- actors
        try:    mi['actors']       = rec.find('actors').text.encode('utf8')
        except: mi['actors']       = ''
        #-- description
        try:    mi['text']         = rec.find('text').text.encode('utf8')
        except: mi['text']         = ''
        #-----
        return mi
    #---------------------------------------------------------------------------
Exemplo n.º 17
0
Arquivo: default.py Projeto: serbra/ru
def Save_Last_Serial_Info(tag, serial, serial_url, img, part):
    # get max history lenght
    try:
        max_history = (1, 5, 10, 20, 30,
                       50)[int(Addon.getSetting('history_len'))]
        if max_history > 99:
            max_history = 99
    except:
        max_history = 10

    sdate = today = date.today().isoformat()

    # load or create history file
    try:
        tree = ElementTree()
        tree.parse(
            os.path.join(Addon.getAddonInfo('path'), r'resources', r'data',
                         r'history.xml'))
        xml1 = tree.getroot()
    except:
        # create XML structure
        xml1 = Element("SERIALU_NET_HISTORY")

    # shrink history to limit
    if len(xml1) > max_history:
        idx = 1
        for rec in xml1:
            if idx >= max_history:
                xml1.remove(rec)
            idx = idx + 1

    # format name
    if part.find('[/COLOR]') > -1:
        part = re.compile('[COLOR FF00FF00](.+?)[/COLOR]',
                          re.MULTILINE | re.DOTALL).find(part)

    xml_hist = None
    # update sequince number for history records
    for rec in xml1:
        if rec.tag == tag:
            rec.find("ID").text = str(0).zfill(2)
            xml_hist = rec
        else:
            rec.find("ID").text = str(int(rec.find("ID").text) + 1).zfill(2)

    if xml_hist == None:
        xml_hist = SubElement(xml1, tag)
        SubElement(xml_hist, "ID").text = str(0).zfill(2)
        SubElement(xml_hist, "Serial").text = unescape(serial)
        SubElement(xml_hist, "URL").text = serial_url
        SubElement(xml_hist, "Date").text = sdate
        SubElement(xml_hist, "Part").text = unescape(part)
        SubElement(xml_hist, "Image").text = img
    else:
        xml_hist.find("Part").text = unescape(part)
        xml_hist.find("Date").text = sdate

    # sort history by IDs
    xml1[:] = sorted(xml1, key=getkey)

    ElementTree(xml1).write(os.path.join(Addon.getAddonInfo('path'),
                                         r'resources', r'data',
                                         r'history.xml'),
                            encoding='utf-8')