Python script

Talk between players of the game about the game ( no personal attacks )
Post Reply
AD Epoch
Private First Class
Private First Class
Posts: 25
Joined: Tue Oct 28, 2008 6:53 am

Python script

Post by AD Epoch » Wed Jun 02, 2010 12:09 pm

I have written a short python script that intermittantly reads some webpages of your choice to see if your chosen callsigns are on it. It's meant to be used to monitor the BZ Flag stats web pages for various chosen servers to see if anyone I know is on (reads every 5 mins or so, but you could change that).

If anyone thinks it might be useful to them I'd be happy to post it.

AD Epoch
Shalom BahShem
Yehoshua, Meshiakh

darkid
Private First Class
Private First Class
Posts: 131
Joined: Wed Aug 12, 2009 5:03 pm

Re: Python script

Post by darkid » Wed Jun 02, 2010 10:34 pm

I'd feel like it's useful... is there a certain App to use to run python scripts?
Darkid--Not a happy camper.

User avatar
joevano
General
General
Posts: 1863
Joined: Sat Jun 18, 2005 1:08 pm
Location: South Bend, Indiana, USA

Re: Python script

Post by joevano » Wed Jun 02, 2010 11:09 pm

Yes... python
There is nothing worse than aggressive stupidity. -- Johann Wolfgang von Goethe
"How many legs does a dog have if you call his tail a leg? Four. Calling a tail a leg doesn't make it a leg." -- Abraham Lincoln

AD Epoch
Private First Class
Private First Class
Posts: 25
Joined: Tue Oct 28, 2008 6:53 am

Re: Python script

Post by AD Epoch » Thu Jun 03, 2010 8:32 am

Yes. Python is like another "virtual machine" sort of like Java. Except Python apps are just plain text files with a .py extension. You just need to install Python 2.6, which is free and open source and can be found at http://www.python.org/ . They call Python executable suedo code because it resembles plain English in many ways.

I'll try to tidy it up a bit then I'll post it as an attachment of a reply in this thread.
Shalom BahShem
Yehoshua, Meshiakh

AD Epoch
Private First Class
Private First Class
Posts: 25
Joined: Tue Oct 28, 2008 6:53 am

Re: Python script

Post by AD Epoch » Thu Jun 03, 2010 11:06 am

I've tried to post the script but it says the extension pyw is not allowed (and presumably py). However since python files are just text files you can downlaod this text file and perform a simple rename of the file extension to get it working.

I use .pyw which tells Python on windows to not display a DOS box in the background, I don't know if this extension works on other Operating Systems but it's worth a try. If it doesn't work then use .py as that WILL work on any system.

It imports a module called winsound to play a sound file, but if you are using non Windows OS you may need to comment or remove this line near the top of the file:

import winsound

it can be commented out by placing a hash at the front of the line

#import winsound

It will need two file created in the same directory

Callsign list.TXT
URL list.TXT

The "Callsign list.TXT" file needs to contain callsigns exactly as you see them on screen, one on each line.

The "URL list.TXT" file needs to contain URL's like the one below:

http://stats.bzflag.org/serverinfo.php? ... com%3A5154

Hope it is useful to you.

It's always good to look at the code before you run something that someone gives you just to make sure it's not malicious. A text editor is good, Python comes with one called IDLE.
Attachments
scan BZStats.txt
change the file extension to py for non Windows OS's or pyw for Windows OS's
(10.47 KiB) Downloaded 100 times
Shalom BahShem
Yehoshua, Meshiakh

User avatar
strayer
Sergeant Major
Sergeant Major
Posts: 190
Joined: Sat May 24, 2003 3:54 pm
Location: Germany
Contact:

Re: Python script

Post by strayer » Thu Jun 03, 2010 12:57 pm

omg...

Please check http://stats.bzflag.org/rssgenerator.php and consider using the RSS feed instead of parsing the HTML code. Even when the stats site isn't known for changing its HTML code that often, the advantage of using the RSS feed is the reliable tag structure.
(Furthermore, there already exist Python packages which parse RSS feed structure. This will make it easier for you too.)
A pessimist is an optimist with experience... ;o)

AD Epoch
Private First Class
Private First Class
Posts: 25
Joined: Tue Oct 28, 2008 6:53 am

Re: Python script

Post by AD Epoch » Fri Jun 04, 2010 10:00 am

I've heard a saying before like: You can't pleased all people all the time :). Not sure the omg was warranted :(, but another saying is hindsight is 20 20 vision. It's a great idea strayer. I didn't know that BZstats did RSS feeds, and that would be better, but as I have never hooked into one before it will be a project for a night with bad TV I think. I'll also have to experiment with what the stats can give me.

What I have now provides what I want, "who is on that I know on the servers I like.", so no rush for me.

But still good idea strayer.
Shalom BahShem
Yehoshua, Meshiakh

User avatar
strayer
Sergeant Major
Sergeant Major
Posts: 190
Joined: Sat May 24, 2003 3:54 pm
Location: Germany
Contact:

Re: Python script

Post by strayer » Fri Jun 04, 2010 7:10 pm

Well, beside the certainty of having a design-independent content structure, a RSS feed (usually) allows to transfer the same data like an HTML page with less traffic and less server resources (for creation).
In this special case it seems that at least the amount of transferred bytes is higher when using the feed. Funny ... isn't it? :)

However, when you find the time (or the night with a boring TV program) you can indeed have a look at it - since it would/could broaden your horizon. ;)
A pessimist is an optimist with experience... ;o)

AD Epoch
Private First Class
Private First Class
Posts: 25
Joined: Tue Oct 28, 2008 6:53 am

Re: Python script

Post by AD Epoch » Sun Jun 06, 2010 6:05 am

Ok here's the RSS feed version. It was a great idea, and enabled me to remove one of the files needed. No more URL file, it's now 1 URL hardcoded into the constructor of the application's class. You still need to create a file called "Callsign list.TXT" that contains the callsign you are looking for, one per line, and it's case sensitive. Once again all this is just the default settings, as it's python it's just a text file, and if you are willing to wade through my code you can edit the names and settings, and make sure I'm not doing anything malicious.

Incidentaly I've decided that the xml.sax module is much more complicated than it should be. I've got half a mind to make my own module that delivers a list of tags and values and points to their parent tag. I know there are better modules out their but I wanted to use something that people didn't have to install separately, or any other files to keep in the same directory. It just get's too complicated for those who don't know about how Python works.
Attachments
scan BZStats v2.txt
You need to rename the extension to .pyw or just .py.
(12.61 KiB) Downloaded 113 times
Shalom BahShem
Yehoshua, Meshiakh

cj
Private First Class
Private First Class
Posts: 17
Joined: Tue Nov 11, 2008 6:45 am

Re: Python script

Post by cj » Fri Jun 25, 2010 8:43 am

Sounds good AD.. Sadly I am running Macs.. I use Python for my Dropbox apps. I did what you suggest on the winsound but it comes up with this:

Traceback (most recent call last):
File "/Users/Darkroom/Dropbox/bzflag/scan BZStats v2.txt", line 33, in <module>
import winsound
ImportError: No module named winsound

I put a # in front of the line import winsound

Is there anybody that was successful in running this script with Macs?

thanks

AD Epoch
Private First Class
Private First Class
Posts: 25
Joined: Tue Oct 28, 2008 6:53 am

Re: Python script

Post by AD Epoch » Wed Jun 30, 2010 9:24 am

Hey CJ!

Glad someone has had a go at it. Sorry to hear you are having trouble though. Unfortunately sound on Python is very OS dependent. I'm not sure how to do it with a Mac unfortunately, but I wou8ld suggest running a search as I'm sure there is an easy way. I ran a quick search and apparently there is a module called PyAudio that is on the Mac version. I tried it on my Win version but it wasn't there. I'm sure just removing the import statement (or commenting it out with a hash) should make the rest of the program work. The calls to the playign sound routines are wrapped in try-except statements which means it should simply display a message saying it can't play the sounds. If anybody else has any idea and would like to, share feel free to post the code for cj.

Also cj did you rename the file extension to .py? This makes it officially a "Python" file as opposed to some wierd textfile with Python like language. The only reason I posted it as a txt file is that the forum wouldn't let me (presumably because it is an executable file).

The more i use Python the more I like it, but realistically it's not as portable as Java, but much easier to use.

If anyone else has a comment on the application feel free to post it. I'd like to hear if it has been useful, (or not :().
Shalom BahShem
Yehoshua, Meshiakh

cj
Private First Class
Private First Class
Posts: 17
Joined: Tue Nov 11, 2008 6:45 am

Re: Python script

Post by cj » Wed Jun 30, 2010 11:05 pm

Thanks AD.

I didn't rename the file, but i used open with and used the python app to open but I will rename it. If I have a positive on that I will repost.

Thanks for replying

cj
Private First Class
Private First Class
Posts: 17
Joined: Tue Nov 11, 2008 6:45 am

Re: Python script

Post by cj » Wed Jun 30, 2010 11:46 pm

I renamed the file to have the .py and it seems to work when I put an # in front of import winsound. I am now working on importing pyaudio in the script.

I have a question in the URL list.txt how do you go about find the url of the server? the main one is missilewars that Blast host.

thanks

cj

AD Epoch
Private First Class
Private First Class
Posts: 25
Joined: Tue Oct 28, 2008 6:53 am

Re: Python script

Post by AD Epoch » Thu Jul 01, 2010 11:14 am

Hi cj,

I think you might be using the wrong version. I posted 2, the first was done poorly, and the second is the one to use. However I have made a small change, now it will log the windows to a file. Use the one with THIS post. You WILL need to make a text file called "Callsign list.TXT" and place it in the same directory as the application. DO NOT FORGET to rename the file to a .py extension.

I am including a version of the callsign file.

YOU DONT NEED THE URL FILE.

I hope you get it working Okay cj. I use it whenever I want to check if someone I know is on, and that way I can find them easily.

All the best cj :)

AD
Attachments
Callsign list.TXT
This contains the callsigns
(70 Bytes) Downloaded 86 times
scan BZStats v2.txt
This is the application
(14.09 KiB) Downloaded 86 times
Shalom BahShem
Yehoshua, Meshiakh

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest