Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

chemosh6969 posted:

I've never done web scrapping before and was wondering if anyone knew of, or had, an example of an imdb scrape? I want to learn how to do it for a few other sites but really wanted to find an example to build off of.
Take a look at BeautifulSoup. It has an extensive documentation and would make the task loads easier.

This guy has a pretty good guide for how to use it.

Adbot
ADBOT LOVES YOU

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

Scaevolus posted:

lxml is faster and better than BeautifulSoup.
You are my hero.

I've been using BeautifulSoup for a number of projects and this looks very promising. Thanks!

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

tef posted:

awesomeness
I familiarized myself with XPaths using Hpricot and Firebug on RoR a while back and missed them while using BeautifulSoup; lxml looks like it'll cut a large chunk of work out of what I'm currently developing.

All the tips are much appreciated, thanks. :)

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah
Does anyone know if PIL supports the creation of animated GIFs?

I'm creating a small command line utility for a buddy that will input a small image, make it a two-frame animated GIF with one frame that has a single pixel with a slight coloration difference for import into Windows Live Messenger as an emoticon (the point of doing so prevents WLM from distorting the emoticon by automatically resizing it).

If PIL isn't the best imaging library for this sorta thing, any recommendations for something better would be great.

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

Scaevolus posted:

A bit of searching led me to http://sites.google.com/site/almarklein/files-1/images2gif.py , which should show you what you want.
Boy I feel dumb, I came across that very same thing and disregarded it for some reason I can't seem to recall. :downs:

Thanks!

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah
I'm having a frustrating problem with MySQLdb and I can't figure out this behavior.

I have this code performing a simple operation to pull a value out of a database:

code:
db = MySQLdb.connect(host="mysql", user="***", passwd="***", db="***")
cursor = db.cursor()
cursor.execute("SELECT PSDsn FROM student_ad WHERE sAmaccountname = '2016203'")
psdsn = cursor.fetchall()
print psdsn[0][0]
Now, that query when executed pretty much anywhere else returns 0102, as it should. However, when using MySQLdb...

code:
>>> print psdsn[0]
(102L,)
>>> print psdsn[0][0]
102
What gives, or is the real problem my usage of MySQLdb?

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

Dren posted:

Is it that your data is in a tuple that upsets you?

That's because you're using fetchall. If you use fetchone you'll get the result you expect.

If you had a query that generated more than one result you might do this:
code:
cursor.execute("SELECT PSDsn FROM student_ad WHERE sAmaccountname LIKE '20%%'")
psdsns = cursor.fetchall()

for psdsn in psdsns:
  print psdsn
Having fetchall always return results in a tuple keeps that for loop from behaving unexpectedly when there is only one result.

Also, MySQLdb gives you back all integers as python longs, hence the L after the 102.
The problem is that it should be returning 0102, not 102. I don't get why it's trimming the preceding 0. :confused:

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

tripwire posted:

Like I said, mysql doesn't spit out data in whatever format you want; it spits out strings. The library you are using is automatically converting fields which looks like numerical values to longs; and if you read the documentation for mysqldb, it covers how to pass in a type-conversion dictionary which will do what you want.
Thanks, you were right. I now have it convert to a string and it returns the right value.

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

Yakattak posted:

Does anybody have any resources for working with a SOAP based API? Specifically with Python but I know absolutely nothing about SOAP. I am trying to communicate with the FedEx API and it's proving to be very difficult as I know nothing about SOAP.
You should wash up with some suds.

It's easy as dirt to use, presuming you're using their web service.

EDIT: I read thread good. :downs: Oh well, if anybody's using SOAP web services in the future, I'm pretty sure suds is the easiest way to go.

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

duck monster posted:

What are peoples recomendations on editors. I cant keep pycharm stable on Lion anymore with its constant lockups, and for the loving life of me I cant get eclipse to recognise its python path source directories for django. I'm losing days of work to this poo poo and its driving me loving insane.

e: Oh great aptana is just an eclipse rebrand with that crazy retarded virtual file-structure poo poo. Just give me a directory listing you over-engineering java wingnuts grrrrrrrrr

e2: Ok, 15 minutes of "rebuilding workspace" later, I think Aptana just failed the audition. :/ Any other recomendations for a non eclipse or IDEA based python editor that "gets" django?

e3: BBedit cant have different docs in a split window. Delete. :suicide: What else is there?

e4: Oh hey jEdit is ugly as gently caress, but is stable , highlights python and html/js properly, has a multi-doc split windows and appears to just work. You'll do , you ugly little text editor! Shame about the eye-searing font though :/

e5: Oh hey sublime-text is pretty drat sweet!
Coda is pretty great. Maybe TextMate?

They're both worth the price. TextMate is more flexible plugin-wise but Coda's integrated SFTP is way better than the available TextMate plugins.

Adbot
ADBOT LOVES YOU

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

Auditore posted:

Hi guys, I'm stuck on this one for a quiz.

"Write a boolean-valued function is_odd(n) that returns True if and only if its int parameter n is odd. [Hint: consider the mod operator, '%'.]"

I have,


However when you 'check' the answer in the quiz program it runs examples through the function to see if it works. Unbeknownst to me, it tries the following two commands.


Where the correct answers are <type 'bool'>. If I want the first numbers-based part correct I can only get <type 'str'> and vice versa.

Plz halp.

code:
>>> def is_odd(n):
...     if n%2 == 0:
...         return False
...     else:
...         return True
...
>>> print type(is_odd(411))
<type 'bool'>
>>> print type(is_odd(412))
<type 'bool'>
:confused:

  • Locked thread