def FromJson(self, val: str) -> ConSeriesFrame: # MainConSeriesFrame d = json.loads(val) if d["ver"] >= 3: self.Seriesname = RemoveAccents(d["_textConSeries"]) self.TextFancyURL = RemoveAccents(d["_textFancyURL"]) self.TextComments = d["_textComments"] self._grid.Datasource = ConSeries().FromJson(d["_datasource"]) return self
def FromJson(self, val: str) -> Con: d = json.loads(val) self._name = RemoveAccents(d["_name"]) # self._locale=d["_locale"] # self._gohs=d["_gohs"] # self._dates=FanzineDateRange().Match(d["_dates"]) if "_URL" in d.keys(): self._URL = d["_URL"] # else: # self._URL="" return self
def FromJson(self, val: str) -> ConSeries: d = json.loads(val) self._name = RemoveAccents( d["_name"]) # Clean out old accented entries self._stuff = d["_stuff"] self._series = [] i = 0 while str(i) in d.keys( ): # This is because json merges 1 and "1" as the same. (It appears to be a bug.) self._series.append(Con(self._seriesname).FromJson(d[str(i)])) i += 1 return self
def UploadConSeries(self) -> bool: # MainConSeriesFrame # First read in the template try: with open(PyiResourcePath("Template-ConSeries.html")) as f: file = f.read() except: wx.MessageBox("Can't read 'Template-ConSeries.html'") return False # Delete any trailing blank rows. (Blank rows anywhere are as error, but we only silently drop trailing blank rows.) # Find the last non-blank row. last = None for i, row in enumerate(self._grid.Datasource.Rows): if len((row.GoHs + row.Locale + row.Name + row.URL).strip()) > 0 or not row.Dates.IsEmpty: last = i # Delete the row or rows following it if last is not None and last < self._grid.Datasource.NumRows - 1: del self._grid.Datasource.Rows[last + 1:] # Determine if we're missing 100% of the data for the Dates, Location, or GoH columns so we can drop them from the listing ProgressMessage(self).Show("Uploading /" + self.Seriesname + "/index.html") # We want to do substitutions, replacing whatever is there now with the new data # The con's name is tagged with <fanac-instance>, the random text with "fanac-headertext" link = FormatLink( "https://fancyclopedia.org/" + WikiPagenameToWikiUrlname(self.Seriesname), self.Seriesname) file = SubstituteHTML(file, "title", self.Seriesname) file = SubstituteHTML(file, "fanac-instance", link) file = SubstituteHTML(file, "fanac-headertext", self.TextComments) showempty = self.m_radioBoxShowEmpty.GetSelection( ) == 0 # Radio button: Show Empty cons? hasdates = len([ d.Dates for d in self._grid.Datasource.Rows if d.Dates is not None and not d.Dates.IsEmpty() ]) > 0 haslocations = len([ d.Locale for d in self._grid.Datasource.Rows if d.Locale is not None and len(d.Locale) > 0 ]) > 0 hasgohs = len([ d.GoHs for d in self._grid.Datasource.Rows if d.GoHs is not None and len(d.GoHs) > 0 ]) > 0 # Now construct the table which we'll then substitute. newtable = '<table class="table" id="conseriestable">\n' newtable += " <thead>\n" newtable += ' <tr id="conseriestable">\n' newtable += ' <th scope="col">Convention</th>\n' if hasdates: newtable += ' <th scope="col">Dates</th>\n' if haslocations: newtable += ' <th scope="col">Location</th>\n' if hasgohs: newtable += ' <th scope="col">GoHs</th>\n' newtable += ' </tr>\n' newtable += ' </thead>\n' newtable += ' <tbody>\n' for row in self._grid.Datasource.Rows: if (row.URL is None or row.URL == "") and not showempty: # Skip empty cons? continue newtable += " <tr>\n" if row.URL is None or row.URL == "": newtable += ' <td>' + row.Name + '</td>\n' else: newtable += ' <td>' + FormatLink( RemoveAccents(row.URL) + "/index.html", row.Name) + '</td>\n' if hasdates: newtable += ' <td>' + str( row.Dates) if not None else "" + '</td>\n' if haslocations: newtable += ' <td>' + row.Locale + '</td>\n' if hasgohs: newtable += ' <td>' + row.GoHs + '</td>\n' newtable += " </tr>\n" newtable += " </tbody>\n" newtable += " </table>\n" file = SubstituteHTML(file, "fanac-table", newtable) file = SubstituteHTML(file, "fanac-json", self.ToJson()) file = SubstituteHTML( file, "fanac-date", datetime.now().strftime("%A %B %d, %Y %I:%M:%S %p") + " EST") # Now try to FTP the data up to fanac.org if self.Seriesname is None or len(self.Seriesname) == 0: Log("UploadConSeries: No series name provided") return False if not FTP().PutFileAsString( "/" + self.Seriesname, "index.html", file, create=True): wx.MessageBox("Upload failed") return False UpdateLog().LogText("Uploaded ConSeries: " + self.Seriesname) ProgressMessage(self).Show("Upload succeeded: /" + self.Seriesname + "/index.html", close=True, delay=0.5) self.MarkAsSaved( ) # It was just saved, so unless it's updated again, the dialog can exit without uploading self._uploaded = True # Something's been uploaded self.RefreshWindow() return True
def SiteFilename(self, val: str) -> None: self._sitefilename = RemoveAccents(val)
keys=list(fanacSeriesDictByCountry.keys()) keys.sort() # We want to list the countries in alphabetical order for key in keys: val=fanacSeriesDictByCountry[key] k=key if len(key.strip()) > 0 else "<no country>" print(f"\n{CapIt(k)} {len(val[0])} titles, {val[1].Issuecount} issues, and {val[1].Pagecount} pages", file=f) for series in val[0]: print(f" {series.DisplayName} ({series.Issuecount} issues, {series.Pagecount} pages)", file=f) Log(f" {series.DisplayName} ({series.Issuecount} issues, {series.Pagecount} pages)") # Now create a properly ordered flat list suitable for WriteTable fanacFanzineSeriesListByCountry: list[tuple[str, int, str]]=[] for countryName, countryEntries in fanacSeriesDictByCountry.items(): for v in countryEntries[0]: fanacFanzineSeriesListByCountry.append((countryName, countryEntries[1], v)) # (country, countryCount, series) fanacFanzineSeriesListByCountry.sort(key=lambda elem: RemoveAccents(RemoveArticles(elem[2].DisplayName.lower())).lower()) fanacFanzineSeriesListByCountry.sort(key=lambda elem: elem[0].lower()) # Provides the annotation for rows in the following output table def plural(i: int) -> str: return "s" if i > 1 else "" def Annotate(elem: FanzineCounts) -> str: s="" if elem.Titlecount > 0: s=str(elem.Titlecount)+" title"+plural(elem.Titlecount)+", " i=elem.Issuecount p=elem.Pagecount if i > 0: s+=str(i)+" issue"+plural(i)+", " s+=str(p)+" page"+plural(p)