Python

For communicating with your fellow chronologists with off-topic stuff.

Moderators: Col_Fury, michel, Arthur, Somebody, StrayLamb

User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Python

Post by Russ Chappell »

Is anyone familiar with basic, rudimentary Python? The Search function is written in Python, and I need some help with coding it to ignore something in the listings.
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
wolverine7230
Big Bad
Big Bad
Posts: 193
Joined: Sat Jun 06, 2015 6:20 am

Re: Python

Post by wolverine7230 »

Yeah, I know basic Python. I could take a look, but I don't know everything about Python, so if it's too complex, I'm not sure to to what extent I could help. But yeah, I'm up for it.
User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Re: Python

Post by Russ Chappell »

Thanks for the offer. Here's the deal, and of course, anyone is free to chip in:

Each character in the project has some code surrounding their name that allows us to collapse or expand the listings, so it doesn't take up as much screen space. Here's the way a normal character is listed:

Code: Select all

<p id="2-D"><span class="char"><b>2-D</b></span><br>
<span class="chron">
A:I@ 1/5-FB<br>
</span></p>
The collapse/expand program uses the "char" and "chron" classes to control what gets expanded or collapsed. All of that works fine with the Search Program.

However, we're creating a new page that's giving us problems. We're setting up one page as a repository of alternate universe characters, with characters grouped together under their alternate universe. You can view the page here:

http://www.chronologyproject.com/alternate.php

The difference in this page from all the others is that we want to be able to also collapse individual universes. Here's the way we list a universe that has three characters:

Code: Select all

<div id="EARTH-27"><span class="char"><input type="button" value="Universe" disabled> <b>EARTH-27</b></span>

<span class="chron"><p id="MAGNETO_27"><span class="char"><b>MAGNETO | EARTH-27</b></span><br>
<span class="chron">
EX2 83<br>
</span></p>

<p id="NIGHTCRAWLER_27"><span class="char"><b>NIGHTCRAWLER | EARTH-27</b></span><br>
<span class="chron">
EX2 83<br>
</span></p>

<p id="ROGUE_27"><span class="char"><b>ROGUE | EARTH-27</b></span><br>
<span class="chron">
EX2 83<br>
</span></p>

</span></div>

<p><hr></p>
Note the following:
The line that begins with "<div id"
The line that reads "</span></div>
The line that reads "<p><hr></p>

In addition, note that the FIRST character in each universe (and ONLY the first character) begins its entry with an extra <span class="chron">

We've got that code working the way that we want it for collapsing and expanding, but it's giving the Search program indigestion.

When I run the python program that builds the search index, we get a lot of warnings about "not an ok figure". It doesn't like any of the three lines that I pointed out above. It doesn't seem to have any problem with the extra <span class="chron"> at the beginning of every universe's first character.

I'm hoping that we can solve the problem by getting the python program to ignore any lines that read:

Code: Select all

</span></div>
and

Code: Select all

<p><hr></p>
and any line that starts with:

Code: Select all

<div id=
You'll probably need a copy of the python program we use to build the search index. It's fairly small, and I can email it to you. Is the email attached to your account here appropriate for that?
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
wolverine7230
Big Bad
Big Bad
Posts: 193
Joined: Sat Jun 06, 2015 6:20 am

Re: Python

Post by wolverine7230 »

Yep, a copy of the code would be useful. Any e-mail I have attached to this forum is there for this kind of thing, so feel free to send it to me. Thanks!
wolverine7230
Big Bad
Big Bad
Posts: 193
Joined: Sat Jun 06, 2015 6:20 am

Re: Python

Post by wolverine7230 »

Ok, I haven't looked at the code in-depth yet, but as I see it, there are three solutions to the problem:
1) We find a way to make the program completely skip those lines.
2) We find a way to make the program ignore those lines (like comments).
3) We find another way to get the desired effect on the web page.

Probably won't work, but have you tried using the exception function to simply ignore the errors? (https://docs.python.org/2/tutorial/errors.html)

-wolverine
User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Re: Python

Post by Russ Chappell »

wolverine7230 wrote:1) We find a way to make the program completely skip those lines.
2) We find a way to make the program ignore those lines (like comments).
3) We find another way to get the desired effect on the web page.
Not really a fan of option 3, since everything else works the way we want. #2 SHOULD be an option in any programming language; I just don't know how to carry it out in Python.
Probably won't work, but have you tried using the exception function to simply ignore the errors? (https://docs.python.org/2/tutorial/errors.html)
As I mentioned in my email, the program APPEARS to work properly, even though I get errors, so it may be possible to simply manually ignore the errors, but I'm hesitant to use an exception to not report the error, since there could be true errors on the pages that need to be corrected (unless we could write the exception to specifically focus on those phrases I mentioned in the earlier post).
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
User avatar
Somebody
Director
Director
Posts: 3392
Joined: Thu Feb 10, 2005 2:48 pm
Location: Scotland
Contact:

Re: Python

Post by Somebody »

Obvious question time - have you tried copying the .chron style to a new style (say, .universe, with JS copying to follow) so that there wouldn't be a <div style="chron"> inside a <div style="chron">? I don't know how much attention the program pays to the HTML, but it's at least possible that confuses it.
User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Re: Python

Post by Russ Chappell »

Somebody wrote:so that there wouldn't be a <div style="chron"> inside a <div style="chron">?
We don't have that, now.

It's a SPAN style chron inside a DIV style chron. Two different things. I had thought about making the new universe coding a span style too, but that would require nesting spans within each other. Is that possible?

And even then, we'd still need to find a way to get it to ignore the visual separator between universes (the hr).
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
wolverine7230
Big Bad
Big Bad
Posts: 193
Joined: Sat Jun 06, 2015 6:20 am

Re: Python

Post by wolverine7230 »

On the 'is that possible?': I find with programming it's just about going for it. Backup the file and try it.
User avatar
Somebody
Director
Director
Posts: 3392
Joined: Thu Feb 10, 2005 2:48 pm
Location: Scotland
Contact:

Re: Python

Post by Somebody »

On phone right now, so this is from memory.
Russ Chappell wrote:
Somebody wrote:so that there wouldn't be a <div style="chron"> inside a <div style="chron">?
We don't have that, now.

It's a SPAN style chron inside a DIV style chron. Two different things. I had thought about making the new universe coding a span style too, but that would require nesting spans within each other. Is that possible?
You can put inline within inline (i.e., span within span) and block within block (i.e., div within div). What you can't - or at least shouldn't - do, IIRC, is put block within inline (i.e., div inside a span).
Russ Chappell wrote:And even then, we'd still need to find a way to get it to ignore the visual separator between universes (the hr).
Meh.

Code: Select all

.universe{border-bottom:1px black}
User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Re: Python

Post by Russ Chappell »

Somebody wrote:Meh.
.universe{border-bottom:1px black}
That's not the point. We can come up with all kinds of ways to draw a line, and we can probably come up with clever alternatives to collapse and expand the listings. The problem is that all of these ways will introduce coding that the search script doesn't expect to see, and it vomits.

We have to teach the search script to ignore something. The collapse and expand scripts already work perfectly, so let's teach it to ignore something that's already there, rather than reinventing the wheel, and teaching the search to ignore that.
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Re: Python

Post by Russ Chappell »

I've located the section of the Search script that's returning the error, and if I'm reading the coding right, it appears that when the script encounters these bits of text, it's not doing anything (which is what we want). It's just alerting me that it found something unusual. I still want to eliminate the warnings (and I think I may have figured out a way to handle two of the situations), but at least I can feel reasonably comfortable that I'm not messing up the Search functionality. Maybe something by the weekend...
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Re: Python

Post by Russ Chappell »

I have eliminated the warnings caused by
<p><hr></p>
and
</span></div>
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
User avatar
Russ Chappell
Site Admin
Site Admin
Posts: 5678
Joined: Thu Feb 12, 2004 5:40 pm
Location: Tuscaloosa, AL
Contact:

Re: Python

Post by Russ Chappell »

And now
<div id=
has been solved.

Stand down.
I can't promise you that things will improve, if we make changes;
I can promise you that they won't improve, if we don't.

Image
Adventures in the Marvelous Zone! A Girl's View of the Marvel Universe
wolverine7230
Big Bad
Big Bad
Posts: 193
Joined: Sat Jun 06, 2015 6:20 am

Re: Python

Post by wolverine7230 »

Hello!

Sorry if you thought I'd abandoned you, but I was on holiday skiing, and didn't have access to a computer :( .

Glad you found a solution!

-wolverine
Post Reply