Shinyshell Community Forums > Coding > Sending Headers |
||||||
Sign Up | Member List | New Posts | Help |
[1]
June 11 02009, 11:31 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
I want to integrate the is.gd URL shortening service into my chat box, as people are continually posting links and they stretch the chat. Luckily, is.gd have an API, it's just that I don't know how to send headers how it says to using your templating system.
So, I have two questions: 1) First, how would I do this? Link to API Instructions 2) And how do you search strings? Say, to find if the user has entered a URL. Thanks in advance :D ______________________________ Lazurane |
June 13 02009, 12:33 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
June 13 02009, 12:56 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
If you only need to send a header, just print it:
print "Location: %s\n" % is_gd_url or for more than one... print "Status: 307 Temporary Redirect" I've looked at the page, but I didn't notice it said anything about sending headers, so I can't be more specific. Anyway, you can search strings with regex (there's a built-in re module): # see if a string is a valid URL Then again, I may have forgotten how it's used. I haven't used the re module in a while. You'll figure it out though, I'm certain. |
June 14 02009, 00:18 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
Well, how would you send the GET request and then receive the thing back?
______________________________ Lazurane |
June 14 02009, 10:15 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
It's easy with urllib2. There's a fantastic page about how to use it here: voidspace.org.uk. Just import it and start using it.
It's got loads of examples, and you should read it all even if you won't use much of it right now. You'll need it again at some point. What you're looking for is around 1/2 of the page down. |
June 17 02009, 22:26 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
Thanks for this, I tried it and it worked! Then, as I went to ammend my code, I realised that I needed to do it in AJAX rather than Python! At least the regex.match thing will help me with determining whether URLs and emails are valid in all the forms around my site.
______________________________ Lazurane |
[1]
Forum Information |
||||||||||
|