fix news caching

This commit is contained in:
Open Toontown 2022-01-19 20:57:56 -05:00
parent cd0c03f83f
commit 0ca1e8eb62
2 changed files with 17 additions and 20 deletions

View file

@ -1,13 +1,10 @@
import os import os
import time
import datetime import datetime
import functools from panda3d.core import Filename, DSearchPath, ConfigVariableString, ConfigVariableBool
from pandac.PandaModules import Filename, DSearchPath, TextNode from panda3d.core import HTTPClient, Ramfile, DocumentSpec
from pandac.PandaModules import HTTPClient, Ramfile, DocumentSpec
from direct.showbase import DirectObject from direct.showbase import DirectObject
from direct.gui.DirectGui import DirectFrame, DGG from direct.gui.DirectGui import DirectFrame, DGG
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from direct.task.Task import Task
from direct.showbase import AppRunnerGlobal from direct.showbase import AppRunnerGlobal
from toontown.shtiker import IssueFrame from toontown.shtiker import IssueFrame
from toontown.shtiker import IssueFrameV2 from toontown.shtiker import IssueFrameV2
@ -17,15 +14,15 @@ class DirectNewsFrame(DirectObject.DirectObject):
TaskName = 'HtmlViewUpdateTask' TaskName = 'HtmlViewUpdateTask'
TaskChainName = 'RedownladTaskChain' TaskChainName = 'RedownladTaskChain'
RedownloadTaskName = 'RedownloadNewsTask' RedownloadTaskName = 'RedownloadNewsTask'
NewsBaseDir = config.GetString('news-base-dir', '/httpNews') NewsBaseDir = ConfigVariableString('news-base-dir', '/httpNews').value
NewsStageDir = config.GetString('news-stage-dir', 'news') NewsStageDir = ConfigVariableString('news-stage-dir', 'news').value
FrameDimensions = (-1.30666637421, FrameDimensions = (-1.30666637421,
1.30666637421, 1.30666637421,
-0.751666665077, -0.751666665077,
0.751666665077) 0.751666665077)
notify = DirectNotifyGlobal.directNotify.newCategory('DirectNewsFrame') notify = DirectNotifyGlobal.directNotify.newCategory('DirectNewsFrame')
NewsIndexFilename = config.GetString('news-index-filename', 'http_news_index.txt') NewsIndexFilename = ConfigVariableString('news-index-filename', 'http_news_index.txt').value
NewsOverHttp = config.GetBool('news-over-http', True) NewsOverHttp = ConfigVariableBool('news-over-http', True).value
CacheIndexFilename = 'cache_index.txt' CacheIndexFilename = 'cache_index.txt'
SectionIdents = ['hom', SectionIdents = ['hom',
'new', 'new',
@ -124,7 +121,7 @@ class DirectNewsFrame(DirectObject.DirectObject):
return fileA.getFilename().compareTo(fileB.getFilename()) return fileA.getFilename().compareTo(fileB.getFilename())
homeFileNames = list(homeFileNames) homeFileNames = list(homeFileNames)
homeFileNames.sort(key=functools.cmp_to_key(fileCmp)) homeFileNames.sort(cmp=fileCmp)
self.notify.debug('returned homeFileNames=%s' % homeFileNames) self.notify.debug('returned homeFileNames=%s' % homeFileNames)
return homeFileNames return homeFileNames
@ -253,7 +250,7 @@ class DirectNewsFrame(DirectObject.DirectObject):
self.newsFiles = [] self.newsFiles = []
filename = self.rf.readline() filename = self.rf.readline()
while filename: while filename:
filename = filename.strip() filename = filename.decode('utf-8').strip()
if filename: if filename:
self.newsFiles.append(filename) self.newsFiles.append(filename)
filename = self.rf.readline() filename = self.rf.readline()
@ -274,7 +271,7 @@ class DirectNewsFrame(DirectObject.DirectObject):
return self.downloadNextFile(task) return self.downloadNextFile(task)
def downloadNextFile(self, task): def downloadNextFile(self, task):
while self.nextNewsFile < len(self.newsFiles) and b'aaver' in self.newsFiles[self.nextNewsFile]: while self.nextNewsFile < len(self.newsFiles) and 'aaver' in self.newsFiles[self.nextNewsFile]:
self.nextNewsFile += 1 self.nextNewsFile += 1
if self.nextNewsFile >= len(self.newsFiles): if self.nextNewsFile >= len(self.newsFiles):
@ -295,7 +292,7 @@ class DirectNewsFrame(DirectObject.DirectObject):
self.percentDownloaded = float(self.nextNewsFile) / float(len(self.newsFiles)) self.percentDownloaded = float(self.nextNewsFile) / float(len(self.newsFiles))
self.filename = self.newsFiles[self.nextNewsFile] self.filename = self.newsFiles[self.nextNewsFile]
self.nextNewsFile += 1 self.nextNewsFile += 1
self.url = self.newsUrl + self.filename.decode('utf-8') self.url = self.newsUrl + self.filename
localFilename = Filename(self.newsDir, self.filename) localFilename = Filename(self.newsDir, self.filename)
self.notify.info('testing for %s' % localFilename.getFullpath()) self.notify.info('testing for %s' % localFilename.getFullpath())
doc = DocumentSpec(self.url) doc = DocumentSpec(self.url)
@ -323,7 +320,7 @@ class DirectNewsFrame(DirectObject.DirectObject):
del self.newsCache[self.filename] del self.newsCache[self.filename]
self.saveNewsCache() self.saveNewsCache()
return self.downloadNextFile(task) return self.downloadNextFile(task)
self.notify.info('downloaded %s' % self.filename.decode('utf-8')) self.notify.info('downloaded %s' % self.filename)
size = self.ch.getFileSize() size = self.ch.getFileSize()
doc = self.ch.getDocumentSpec() doc = self.ch.getDocumentSpec()
date = '' date = ''
@ -370,8 +367,8 @@ class DirectNewsFrame(DirectObject.DirectObject):
self.redownloadNews() self.redownloadNews()
def getInGameNewsUrl(self): def getInGameNewsUrl(self):
result = base.config.GetString('fallback-news-url', 'http://cdn.toontown.disney.go.com/toontown/en/gamenews/') result = ConfigVariableString('fallback-news-url', 'http://cdn.toontown.disney.go.com/toontown/en/gamenews/').value
override = base.config.GetString('in-game-news-url', '') override = ConfigVariableString('in-game-news-url', '').value
if override: if override:
self.notify.info('got an override url, using %s for in game news' % override) self.notify.info('got an override url, using %s for in game news' % override)
result = override result = override
@ -392,8 +389,8 @@ class DirectNewsFrame(DirectObject.DirectObject):
majorVer = 1 majorVer = 1
minorVer = 0 minorVer = 0
for entry in self.newsIndexEntries: for entry in self.newsIndexEntries:
if b'aaver' in entry and dateStr.encode('utf-8') in entry: if 'aaver' in entry and dateStr in entry:
parts = entry.split(b'_') parts = entry.split('_')
if len(parts) > 5: if len(parts) > 5:
try: try:
majorVer = int(parts[5]) majorVer = int(parts[5])

View file

@ -1,4 +1,4 @@
from pandac.PandaModules import Filename from panda3d.core import Filename
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from direct.gui.DirectGui import DGG, DirectFrame, DirectButton from direct.gui.DirectGui import DGG, DirectFrame, DirectButton
from toontown.shtiker import IssueFrame from toontown.shtiker import IssueFrame
@ -33,7 +33,7 @@ class IssueFrameV2(IssueFrame.IssueFrame):
def isSectionInIndex(self, sectionIdent): def isSectionInIndex(self, sectionIdent):
for name in self.newsIndexEntries: for name in self.newsIndexEntries:
if sectionIdent.encode('utf-8') in name and self.dateStr.encode('utf-8') in name: if sectionIdent in name and self.dateStr in name:
return True return True
return False return False