Exemplo n.º 1
0
 def __init__(self, filename, url, *args):
     data = self.__getData(filename, *args)
     os.chdir(os.path.dirname(os.path.abspath(__file__)))
     name = data.__class__.__name__.split('Data')[0]
     path = './' + name + '.atom'
     if (not os.path.exists(path) or os.path.getsize(path) == 0):
         feed = AtomFeed(name, url, 'http://feeds.click3.org/application/' + name + '.atom', ['sweetie'])
         feed.appendEntry({'title':'feed_create', 'url':'http://feeds.click3.org/application/' + name + '.atom', 'updated':datetime.datetime.utcnow(), 'summary':''})
         xml = feed.toXml().decode('utf-8')
         out = codecs.open(path, 'w', 'utf-8')
         out.write(xml)
         out.close()
     assert(isinstance(path, str))
     assert(isinstance(data, FeedUpdateData))
     self.__path = path
     self.__feed = AtomFeed(path)
     data.setFeed(self.__feed)
     self.__data = data
Exemplo n.º 2
0
 def editPage(self):
     id = self["config"].getCurrentIndex()
     if id < len(config.plugins.CurlyTx.pages):
         self.session.openWithCallback(self.pageEdited, CurlyTxPageEdit,
                                       config.plugins.CurlyTx.pages[id],
                                       False)
     elif config.plugins.CurlyTx.feedUrl.value:
         from AtomFeed import AtomFeed
         AtomFeed(config.plugins.CurlyTx.feedUrl.value,
                  self.feedPagesReceived, self.feedPagesFail)
     else:
         self.session.open(MessageBox, _("No page feed URL defined"),
                           MessageBox.TYPE_ERROR)
    def loadStaticConfig(self):
        """
        Always try to load the static config file from
        /etc/enigma2/curlytx-pagefeed.xml
        """
        staticFeedPath = Directories.resolveFilename(Directories.SCOPE_CONFIG, self.staticPageFeedFile)
        if not os.path.exists(staticFeedPath):
            return

        from AtomFeed import AtomFeed
        AtomFeed(
            'file://' + staticFeedPath,
            self.saveStaticConfig, self.loadStaticConfigFail
            )
Exemplo n.º 4
0
class FeedUpdate:
    def __getData(self, filename, *args):
        filename = os.path.basename(filename).split('.')[0]
        data_name = filename.split('_')[0] + 'Data'
        return getattr(__import__(filename), data_name)(*args)

    def __init__(self, filename, url, *args):
        data = self.__getData(filename, *args)
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        name = data.__class__.__name__.split('Data')[0]
        path = './' + name + '.atom'
        if (not os.path.exists(path) or os.path.getsize(path) == 0):
            feed = AtomFeed(name, url, 'http://feeds.click3.org/application/' + name + '.atom', ['sweetie'])
            feed.appendEntry({'title':'feed_create', 'url':'http://feeds.click3.org/application/' + name + '.atom', 'updated':datetime.datetime.utcnow(), 'summary':''})
            xml = feed.toXml().decode('utf-8')
            out = codecs.open(path, 'w', 'utf-8')
            out.write(xml)
            out.close()
        assert(isinstance(path, str))
        assert(isinstance(data, FeedUpdateData))
        self.__path = path
        self.__feed = AtomFeed(path)
        data.setFeed(self.__feed)
        self.__data = data

    def __httpGet(urlStr, charset):
        url = http.client.urlsplit(urlStr)
        conn = None
        if (url.scheme == 'http'):
            conn = http.client.HTTPConnection(url.netloc)
        elif (url.scheme == 'https'):
            conn = http.client.HTTPSConnection(url.netloc)
        assert(conn != None)
        conn.request('GET', url.path + '?' + url.query)
        response = conn.getresponse()
        if (response.status != 200):
            return None
        return response.readall().decode(charset)

    def run(self):
        url = self.__data.__class__.getCheckUrl()
        body = None
        if (url != None):
            body = FeedUpdate.__httpGet(url, self.__data.getCharset())
            if (body == None):
                return False
        self.__data.setBody(body)
        if (self.__data.isError()):
            return False
        if (not self.__data.updateExist()):
            return True
        entry = {}
        entry['title'] = self.__data.getTitle()
        entry['url'] = self.__data.getUrl()
        entry['updated'] = self.__data.getUpdated()
        entry['summary'] = self.__data.getSummary()
        if (self.__data.getContent() != None):
            entry['content'] = self.__data.getContent()
        self.__feed.appendEntry(entry)
        tmpPath = self.__path + '.tmp'
        if (os.path.exists(tmpPath)):
            os.remove(tmpPath)
        xml = self.__feed.toXml().decode('utf-8')
        out = codecs.open(tmpPath, 'w', 'utf-8')
        out.write(xml)
        out.close()
        os.remove(self.__path)
        os.rename(tmpPath, self.__path)
        return True