コード例 #1
0
ファイル: loginII.py プロジェクト: R4M80MrX/eve-1
    def LoadMotd(self, hidden = False):
        ip = self.serverIP
        try:
            extraParam = sm.StartService('patch').GetWebRequestParameters()
            if boot.region == 'optic':
                url = WEB_EVE + '/motd.html?server=%s&%s'
                encoding = 'gbk'
            else:
                url = WEB_EVE + '/motd/%s?%s'
                encoding = 'utf-8'
            ret = corebrowserutil.GetStringFromURL(url % (ip, extraParam)).read()
        except Exception as e:
            log.LogError('Failed to fetch motd', e)
            sys.exc_clear()
            ret = ''

        if self.motdParent and not self.motdParent.destroyed:
            if ret and ret.startswith('MOTD '):
                ret = ret[5:]
                self.motdText = ret.decode(encoding, 'replace')
                if hidden:
                    self.motdParent.state = uiconst.UI_HIDDEN
                else:
                    self.motdParent.state = uiconst.UI_NORMAL
                self.motdLabel.text = self.motdText
                self.motdParent.height = max(32, self.motdLabel.textheight + 10)
            else:
                self.motdParent.state = uiconst.UI_HIDDEN
コード例 #2
0
ファイル: loginII.py プロジェクト: R4M80MrX/eve-1
    def CheckAds(self, hidden = False):
        alwaysShowAd = False
        try:
            extraParam = sm.GetService('patch').GetWebRequestParameters()
            if settings.public.ui.Get('usernames') is None and sm.GetService('patch').GetClientAffiliateID() != '':
                alwaysShowAd = True
            adUrl = WEB_EVE + '/ads.asp?%s' % extraParam
            sm.GetService('loading').LogInfo('ad URL:', adUrl)
            ads = corebrowserutil.GetStringFromURL(adUrl).read()
        except Exception as e:
            log.LogError('Failed to fetch ads', e)
            sys.exc_clear()
            self.CloseAd()
            return

        ads = [ ad for ad in ads.split('\r\n') if ad ]
        for ad in ads:
            imgpath, url = ad.split('|')
            didShowAd = settings.public.ui.Get(imgpath + 'Ad', 0)
            if not didShowAd or alwaysShowAd:
                try:
                    self.OpenAd(imgpath, url, hidden)
                except Exception as e:
                    log.LogError('Failed to display ad', e, imgpath, url)
                    sys.exc_clear()

                return
コード例 #3
0
    def FindAvailableAds(self):
        adUrl = csUtil.GetCharacterSelectionAdPageUrl(session.languageID)
        feed = corebrowserutil.GetStringFromURL(adUrl).read()
        root = ET.fromstring(feed)
        namespaces = csUtil.xmlNamespaces
        itemlist = root.findall('atom:entry', namespaces=namespaces)
        targetedAds = []
        nonTargetedAds = []
        if session.userType == const.userTypeTrial:
            target = csUtil.adTrialTerm
        else:
            charData = self.GetCharacterSelectionData()
            creationDate = charData.GetUserCreationDate()
            now = blue.os.GetWallclockTime()
            if now - 6 * const.MONTH30 < creationDate:
                target = csUtil.adMediumTerm
            else:
                target = csUtil.adAdvancedTerm
        for eachItem in itemlist:
            with ExceptionEater('Failed to parse ad'):
                imageEntry = eachItem.find('ccpmedia:group/ccpmedia:content', namespaces=namespaces)
                linkEntry = eachItem.find('ccpmedia:group/ccpmedia:description', namespaces=namespaces)
                adID = eachItem.find('atom:id', namespaces=namespaces).text
                link = linkEntry.text
                imageUrl = imageEntry.attrib['url']
                imageWidth = imageEntry.attrib['width']
                imageHeight = imageEntry.attrib['height']
                adInfo = uiutil.Bunch(link=link, imageUrl=imageUrl, width=int(imageWidth), height=int(imageHeight), adID=adID)
                if eachItem.find("atom:category[@term='%s']" % target, namespaces=namespaces) is not None:
                    targetedAds.append(adInfo)
                elif eachItem.find('atom:category', namespaces=namespaces) is None:
                    nonTargetedAds.append(adInfo)

        return (targetedAds, nonTargetedAds)
コード例 #4
0
ファイル: holoscreenSvc.py プロジェクト: R4M80MrX/eve-1
    def GetNewsTickerData(self):
        newsData = []
        for url in self.RSS_FEEDS:
            try:
                rssData = corebrowserutil.GetStringFromURL(url)
            except urllib2.HTTPError:
                failData = util.KeyVal()
                failData.date = blue.os.GetWallclockTime()
                failData.link = 'http://www.eveonline.com'
                failData.title = 'The news service is temporarily unavailable.'
                newsData = [failData]
                clickFuncList = [ uicore.cmd.OpenBrowser for entry in newsData ]
                funcKeywordsList = [ {'url': entry.link} for entry in newsData ]
                return (newsData, clickFuncList, funcKeywordsList)
            except:
                log.LogException('Uncaught (non-http) error with the mainscreen news ticker in GetNewsTickerData()')
                failData = util.KeyVal()
                failData.date = blue.os.GetWallclockTime()
                failData.link = 'http://www.eveonline.com'
                failData.title = 'The news service is unavailable.'
                newsData = [failData]
                clickFuncList = [ uicore.cmd.OpenBrowser for entry in newsData ]
                funcKeywordsList = [ {'url': entry.link} for entry in newsData ]
                return (newsData, clickFuncList, funcKeywordsList)

            while True:
                line = rssData.readline()
                if not line:
                    break
                line = line.strip()
                if not line.startswith('<item rdf:about='):
                    continue
                entry = util.KeyVal()
                urlRaw = line.lstrip('<item rdf:about="').rstrip('">')
                entry.link = urlRaw.replace('&amp;', '&')
                while line != '</item>':
                    line = rssData.readline()
                    if not line:
                        break
                    line = line.strip()
                    if line.startswith('<title>'):
                        entry.title = line.lstrip('<title>').rstrip('</title>')
                    elif line.startswith('<dc:date>'):
                        line = line.lstrip('<dc:date>').rstrip('</dc:date>')
                        year, month, line = line.split('-')
                        day, line = line.split('T')
                        hour, line, temp = line.split(':')
                        minute, line = line.split('+')
                        entry.date = blue.os.GetTimeFromParts(int(year), int(month), int(day), int(hour), int(minute), 0, 0)
                    elif line.startswith('<dc:extra'):
                        temp, temp2, string = line.partition('mode="')
                        if string.startswith('solarsystem'):
                            temp, temp2, string = string.partition('id="3">')
                            string, temp, temp2 = string.partition('</dc:extra')
                            entry.solarsystem = string
                        elif string.startswith('region'):
                            temp, temp2, string = string.partition('id="5">')
                            string, temp, temp2 = string.partition('</dc:extra')
                            entry.region = string

                if not hasattr(entry, 'date'):
                    entry.date = 0
                newsData.append(entry)
                if not line:
                    break

        newsData.sort(key=lambda x: x.date, reverse=True)
        newsData = newsData[:15]
        clickFuncList = [ uicore.cmd.OpenBrowser for entry in newsData ]
        funcKeywordsList = [ {'url': entry.link} for entry in newsData ]
        return (newsData, clickFuncList, funcKeywordsList)
コード例 #5
0
ファイル: evePhotosvc.py プロジェクト: connoryang/1v1dec
    def GetTextureFromURL(self,
                          path,
                          currentURL=None,
                          ignoreCache=0,
                          dontcache=0,
                          fromWhere=None,
                          sizeonly=0,
                          retry=1):
        if path.endswith('.blue'):
            return self.GetPic_blue(path)
        fullPath = corebrowserutil.ParseURL(path, currentURL)[0]
        if path.startswith('res:'):
            try:
                surface = trinity.Tr2HostBitmap()
                surface.CreateFromFile(path)
                w, h = surface.width, surface.height
                bw, bh = uiutil.GetBuffersize(w), uiutil.GetBuffersize(h)
                if sizeonly:
                    return (path, w, h, bw, bh)
                return self.ReturnTexture(path, w, h, bw, bh)
            except:
                self.LogError('Failed to load image', path)
                if self.urlloading.has_key(fullPath):
                    del self.urlloading[fullPath]
                sys.exc_clear()
                return self.ErrorPic(sizeonly)

        if ignoreCache:
            sm.GetService('browserCache').InvalidateImage(fullPath)
        while self.urlloading.has_key(fullPath):
            blue.pyos.BeNice()

        if not dontcache:
            cacheData = sm.GetService('browserCache').GetFromCache(fullPath)
            if cacheData and os.path.exists(cacheData[0].replace(
                    'cache:/', blue.paths.ResolvePath(u'cache:/'))):
                if sizeonly:
                    return cacheData
                return self.ReturnTexture(*cacheData)
        try:
            self.urlloading[fullPath] = 1
            ret = corebrowserutil.GetStringFromURL(fullPath)
            cacheID = int(
                str(blue.os.GetWallclockTime()) +
                str(uthread.uniqueId() or uthread.uniqueId()))
            imagestream = ret.read()
            ext = None
            if 'content-type' in ret.headers.keys(
            ) and ret.headers['content-type'].startswith('image/'):
                ext = ret.headers['content-type'][6:]
            if ext == None or ext == 'png':
                header = imagestream[:16]
                for sig, sext in [('PNG', 'PNG'), ('GIF', 'GIF'),
                                  ('JFI', 'JPEG'), ('BM8', 'BMP')]:
                    for i in xrange(0, 12):
                        if header[i:i + 3] == sig:
                            ext = sext
                            break

                if not ext:
                    header = imagestream[-16:]
                    for sig, sext in [('XFILE', 'TGA')]:
                        for i in xrange(0, 10):
                            if header[i:i + 5] == sig:
                                ext = sext
                                break

            if ext:
                filename = '%sBrowser/Img/%s.%s' % (
                    blue.paths.ResolvePath(u'cache:/'), cacheID, ext)
                resfile = blue.classes.CreateInstance('blue.ResFile')
                if not resfile.Open(filename, 0):
                    resfile.Create(filename)
                resfile.Write(imagestream)
                resfile.Close()
                if ext.upper() == 'GIF':
                    g = DrawArea()
                    g.setBgColor(Transparent)
                    g.loadGIF(filename.replace(u'/', u'\\').encode('utf8'))
                    ext = 'PNG'
                    filename = u'%sBrowser/Img/%s.%s' % (
                        blue.paths.ResolvePath(u'cache:/'), cacheID, ext)
                    g.outPNG(filename.replace(u'/', u'\\').encode('utf8'))
                surface = trinity.Tr2HostBitmap()
                surface.CreateFromFile(filename)
                w, h = surface.width, surface.height
                bw, bh = uiutil.GetBuffersize(w), uiutil.GetBuffersize(h)
                cachePath = 'cache:/Browser/Img/%s.%s' % (cacheID, ext)
                if 'pragma' not in ret.headers.keys(
                ) or ret.headers['Pragma'].find('no-cache') == -1:
                    sm.GetService('browserCache').Cache(
                        fullPath, (cachePath, w, h, bw, bh))
                del self.urlloading[fullPath]
                if sizeonly:
                    return (cachePath, w, h, bw, bh)
                return self.ReturnTexture(cachePath, w, h, bw, bh)
            del self.urlloading[fullPath]
            return self.ErrorPic(sizeonly)
        except Exception as e:
            if retry:
                sys.exc_clear()
                if self.urlloading.has_key(fullPath):
                    del self.urlloading[fullPath]
                return self.GetTextureFromURL(path, currentURL, ignoreCache,
                                              dontcache, fromWhere, sizeonly,
                                              0)
            self.LogError(e, 'Failed to load image', repr(path))
            if self.urlloading.has_key(fullPath):
                del self.urlloading[fullPath]
            sys.exc_clear()
            return self.ErrorPic(sizeonly)
コード例 #6
0
    def GetNewsTickerData(self):
        newsData = []
        for url in self.RSS_FEEDS:
            try:
                rssData = corebrowserutil.GetStringFromURL(url)
            except urllib2.HTTPError:
                failData = util.KeyVal()
                failData.date = blue.os.GetWallclockTime()
                failData.link = 'http://www.eveonline.com'
                failData.title = 'The news service is temporarily unavailable.'
                newsData = [failData]
                clickFuncList = [uicore.cmd.OpenBrowser for entry in newsData]
                funcKeywordsList = [{'url': entry.link} for entry in newsData]
                return (newsData, clickFuncList, funcKeywordsList)
            except:
                log.LogException(
                    'Uncaught (non-http) error with the mainscreen news ticker in GetNewsTickerData()'
                )
                failData = util.KeyVal()
                failData.date = blue.os.GetWallclockTime()
                failData.link = 'http://www.eveonline.com'
                failData.title = 'The news service is unavailable.'
                newsData = [failData]
                clickFuncList = [uicore.cmd.OpenBrowser for entry in newsData]
                funcKeywordsList = [{'url': entry.link} for entry in newsData]
                return (newsData, clickFuncList, funcKeywordsList)

            while True:
                line = rssData.readline()
                if not line:
                    break
                line = line.strip()
                if not line.startswith('<entry>'):
                    continue
                entry = util.KeyVal()
                while line != '</entry>':
                    line = rssData.readline()
                    if not line:
                        break
                    line = line.strip()
                    if line.startswith('<title'):
                        entry.title = line.lstrip(
                            '<title type="html">').rstrip('</title>')
                        entry.title = entry.title.decode('ascii', 'ignore')
                    elif line.startswith('<id>'):
                        entry.link = line.lstrip('<id>').rstrip('</id>')
                    elif line.startswith('<updated>'):
                        line = line.lstrip('<updated>').rstrip('</updated>')
                        year, month, line = line.split('-')
                        day, line = line.split('T')
                        hour, minute, line = line.split(':')
                        second = line.rstrip('Z')
                        entry.date = blue.os.GetTimeFromParts(
                            int(year), int(month), int(day), int(hour),
                            int(minute), 0, 0)

                if not hasattr(entry, 'date'):
                    entry.date = 0
                newsData.append(entry)
                if not line:
                    break

        newsData.sort(key=lambda x: x.date, reverse=True)
        newsData = newsData[:15]
        clickFuncList = [uicore.cmd.OpenBrowser for entry in newsData]
        funcKeywordsList = [{'url': entry.link} for entry in newsData]
        return (newsData, clickFuncList, funcKeywordsList)