how would you...?

inhahe inhahe at gmail.com
Sun May 18 07:37:37 EDT 2008


"Sanoski" <Joshuajruss at gmail.com> wrote in message 
news:1449c36e-10ce-42f4-bded-99d53a0a2569 at a1g2000hsb.googlegroups.com...
> I'm pretty new to programming. I've just been studying a few weeks off
> and on. I know a little, and I'm learning as I go. Programming is so
> much fun! I really wish I would have gotten into it years ago, but
> here's my question. I have a longterm project in mind, and I wont to
> know if it's feasible and how difficult it will be.
>
> There's an XML feed for my school that some other class designed. It's
> just a simple idea that lists all classes, room number, and the person
> with the highest GPA. The feed is set up like this. Each one of the
> following lines would also be a link to more information about the
> class, etc.
>
> Economics, Room 216, James Faker, 3.4
> Social Studies, Room 231, Brain Fictitious, 3.5
>
> etc, etc
>
> The student also has a picture reference that depicts his GPA based on
> the number. The picture is basically just a graph. I just want to
> write a program that uses the information on this feed.
>
> I want it to reach out to this XML feed, record each instance of the
> above format along with the picture reference of the highest GPA
> student, download it locally, and then be able to use that information
> in various was. I figured I'll start by counting each instance. For
> example, the above would be 2 instances.
>
> Eventually, I want it to be able to cross reference data you've
> already downloaded, and be able to compare GPA's, etc. It would have a
> GUI and everything too, but I am trying to keep it simple right now,
> and just build onto it as I learn.
>
> So lets just say this. How do you grab information from the web, in
> this case a feed, and then use that in calculations? How would you
> implement such a project? Would you save the information into a text
> file? Or would you use something else? Should I study up on SQLite?
> Maybe I should study classes. I'm just not sure. What would be the
> most effective technique?


People usually say BeautifulSoup for getting stuff from the web.  I think I 
tried it once and had some problem and gave up.  But since this is XML I 
think all you'd need is an xml.dom.minidom or xml.etree.ElementTree. i'm not 
sure which is easier.  see doc\python.chm in the Python directory to study 
up on those.  To grab the webpage to begin with you'd use urllib2.  That 
takes around one line of code.  I wouldn't save it to a text file, because 
they're not that good for random access.  Or storing images.  I'd save it in 
a database.  There are other database modules than SQLite, but SQLite is a 
good one, for simple projects like that where you're just going to be 
running one instance of the program at a time.  SQLite is fast and it's the 
only one that doesn't require a separate database engine to be installed and 
running.
Classes are just a way of organizing code (and a little more, but they don't 
have a lot to do with saving stuff to file).
I'm not clear on whether the GPA is available as text and an image, or just 
an image.  If it's just available as an image you're going to want to use 
PIL (Python Image Library).  Btw, use float() to convert a textual GPA to a 
number.
You'll have to learn some basics of the SQL language (that applies to any 
database).  Or maybe not with SQLObject or SQLAlchemy, but I don't know how 
easy those are to learn.  Or if you don't want to learn SQL you could use a 
text file with fixed-length fields and perhaps references to individual 
filenames that store the pictures, and I could tell you how to do that.  But 
a database is a lot more flexible, and you wouldn't need to learn much SQL 
for the same purposes.
Btw, I used SQLite version 2 before and it didn't allow me to return query 
results as dictionaries (i.e., indexable by field name), just lists of 
values, except by using some strange code I found somewhere.  But a list is 
also easy to use.  But if version 3 doesn't do it either and you want the 
code I have it.





More information about the Python-list mailing list