예제 #1
0
    def DownloadConSeries(self, seriesname) -> bool:  # MainConSeriesFrame

        # Clear out any old information
        self._grid.Datasource = ConSeries()

        if seriesname is None or len(seriesname) == 0:
            # Nothing to load. Just return.
            return False

        if self._basedirectoryFTP is None:
            assert False  # Never take this branch.  Delete when I'm sure.

        ProgressMessage(self).Show("Loading " + self.Seriesname +
                                   "/index.html from fanac.org")
        file = FTP().GetFileAsString("/" + self.Seriesname, "index.html")

        pathname = self.Seriesname + "/index.html"
        if len(self._basedirectoryFTP) > 0:
            pathname = self._basedirectoryFTP + "/" + pathname

        if file is not None:

            # Get the JSON from the file
            j = FindBracketedText(file, "fanac-json")[0]
            if j is None or j == "":
                Log("DownloadConSeries: Can't load convention information from "
                    + pathname)
                wx.MessageBox("Can't load convention information from " +
                              pathname)
                return False

            try:
                self.FromJson(j)
            except (json.decoder.JSONDecodeError):
                Log("DownloadConSeries: JSONDecodeError when loading convention information from "
                    + pathname)
                wx.MessageBox(
                    "JSONDecodeError when loading convention information from "
                    + pathname)
                return False
        else:
            # Offer to download the data from Fancy 3
            self.Seriesname = seriesname
            resp = wx.MessageBox(
                "Do you wish to download the convention series " + seriesname +
                " from Fancyclopedia 3?", 'Shortcut',
                wx.YES | wx.NO | wx.ICON_QUESTION)
            if resp == wx.YES:
                self.DownloadConSeriesFromFancy(seriesname)

        if self.TextFancyURL is None or len(self.TextFancyURL) == 0:
            self.TextFancyURL = "fancyclopedia.org/" + WikiPagenameToWikiUrlname(
                seriesname)

        self._grid.MakeTextLinesEditable()
        self.RefreshWindow()
        ProgressMessage(self).Show(self.Seriesname + " Loaded",
                                   close=True,
                                   delay=0.5)
        return True
예제 #2
0
    def DownloadConInstancePage(self) -> None:

        # Clear out any old information
        self._grid.Datasource = ConInstancePage()

        # Read the existing CIP
        ProgressMessage(self).Show("Downloading " + self._FTPbasedir + "/" +
                                   self._coninstancename + "/index.html")
        file = FTP().GetFileAsString(
            self._FTPbasedir + "/" + self._coninstancename, "index.html")
        if file is None:
            Log("DownloadConInstancePage: " + self._FTPbasedir + "/" +
                self._coninstancename +
                "/index.html does not exist -- create a new file and upload it"
                )
            #wx.MessageBox(self._FTPbasedir+"/"+self._coninstancename+"/index.html does not exist -- create a new file and upload it")
            ProgressMessage(self).Close()
            return  # Just return with the ConInstance page empty

        # Get the JSON
        j = FindBracketedText(file, "fanac-json")[0]
        if j is not None and j != "":
            self.FromJson(j)

        self.Title = "Editing " + self._coninstancename

        ProgressMessage(self).Show(self._FTPbasedir + "/" +
                                   self._coninstancename +
                                   "/index.html downloaded",
                                   close=True,
                                   delay=0.5)
        self._grid.MakeTextLinesEditable()
        self.MarkAsSaved()
        self.RefreshWindow()
예제 #3
0
    def Load(self):            # ConEditorFrame
        # Clear out any old information
        self._grid.Datasource=ConList()

        Log("Loading root/index.html")
        file=FTP().GetFileAsString("", "index.html")
        if file is None:
            # Present an empty grid
            self.RefreshWindow()
            return

        # Get the JSON
        j=FindBracketedText(file, "fanac-json")[0]
        if j is None or j == "":
            wx.MessageBox("Can't load convention information from conpubs' index.html")
            return

        try:
            self.FromJson(j)
        except (json.decoder.JSONDecodeError):
            wx.MessageBox("JSONDecodeError when loading convention information from conpubs' index.html")
            return

        self._grid.MakeTextLinesEditable()
        self.MarkAsSaved()
        self.RefreshWindow()
예제 #4
0
def ExtractCountry(h: str) -> str:
    temp=FindBracketedText(h, "fanac-type")
    if temp[0] is None or len(temp[0]) == 0:
        return ""

    loc=Locale(temp[0])
    Log(f'ExtractCountry: "{temp[0]}" --> {loc}')
    return loc.Country
예제 #5
0
    def __init__(self, seriesname, coninstancename):

        self.Datasource = ConInstancePage()

        self._coninstancename = coninstancename

        # Read the existing CIP
        Log("Downloading /" + seriesname + "/" + self._coninstancename +
            "/index.html")
        file = FTP().GetFileAsString(
            "/" + seriesname + "/" + self._coninstancename, "index.html")
        if file is None:
            Log("DownloadConInstancePage: /" + seriesname + "/" +
                self._coninstancename + "/index.html does not exist")
            return  # Just return with the ConInstance page empty

        # Get the JSON
        j = FindBracketedText(file, "fanac-json")[0]
        if j is not None and j != "":
            self.FromJson(j)

        Log("/" + seriesname + "/" + self._coninstancename +
            "/index.html downloaded")
예제 #6
0
    def __init__(self, conseriesname):

        assert len(conseriesname) > 0
        self.Seriesname = conseriesname
        self.Datasource = ConSeries(conseriesname)

        Log("Loading " + "/" + self.Seriesname + "/index.html from fanac.org")
        file = FTP().GetFileAsString("/" + self.Seriesname, "index.html")

        # Get the JSON from the file
        j = FindBracketedText(file, "fanac-json")[0]
        if j is None or j == "":
            Log("DownloadConSeries: Can't load convention information from /" +
                self.Seriesname + "index.html")
            return

        try:
            self.FromJson(j)
        except (json.decoder.JSONDecodeError):
            Log("DownloadConSeries: JSONDecodeError when loading convention information from /"
                + self.Seriesname + "index.html")
            return

        Log(self.Seriesname + " Loaded")
예제 #7
0
###############################################################################

LogOpen("Log -- ConpubsAnalyzer.txt", "Log (Errors) -- ConpubsAnalyzer.txt")

f = FTP()
if not f.OpenConnection("FTP Credentials.json"):
    Log("Main: OpenConnection('FTP Credentials.json' failed")
    exit(0)

Log("Loading root/index.html")
file = FTP().GetFileAsString("", "index.html")
if file is None:
    assert False

# Get the JSON
j = FindBracketedText(file, "fanac-json")[0]
if j is None or j == "":
    Log("Can't find convention information json in conpubs' index.html")
    exit(0)

listOfConSeries = []
try:
    d = json.loads(j)
    listOfConSeries = ConList().FromJson(d["_datasource"])
except json.decoder.JSONDecodeError:
    Log("JSONDecodeError when loading convention information from conpubs' index.html"
        )
    exit(0)

# Walk the list of ConSeries, loading each in turn
cpc = ConpubsCounts()