Shinyshell Community Forums > Coding >
Sending Headers


[1]


June 11 02009, 11:31 GMT
Nick^
merciful justice

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
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

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
*bump* (because Peter took the latest topic place)
______________________________
Lazurane

June 13 02009, 12:56 GMT
lec**
Supra stultitiam

lec's avatar
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 
print "Location: %s\n" % is_gd_url
]]>


or for more than one...

print "Status: 307 Temporary Redirect" 
print "Location: %s\n" % is_gd_url
print "Status: 307 Temporary Redirect"
print "Location: %s\n" % is_gd_url
]]>


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 
regex = re.compile("^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$", re.I)

if regex.match(string):
# ...
# see if a string is a valid URL
regex = re.compile("^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$", re.I)

if regex.match(string):
# ...
]]>


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

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
Well, how would you send the GET request and then receive the thing back?
______________________________
Lazurane

June 14 02009, 10:15 GMT
lec**
Supra stultitiam

lec's avatar
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

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
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
  Currently Active Members [detailed] (0 members and ? guests)
-
Forum Statistics
Topics: 0, Posts: 0, Members: 108.
Welcome to our newest member, adamthephantump
Most members online was 5, on August 28 2009, at 21:49:28.
Legend
    Forums with unread topics in them are indicated by a strong yellow colouring around the forum icon.
    Forums with no unread topics have the standard pale yellow colouring around the forum icon.
    Forums with a blue arrow icon will redirect you to a non-forum page.
    Locked forums have a little padlock by their icon. You won't be able to post in these forums.
Shinyshell Home | Contact | Staff List | Archive | Top 

Conventional Login

Don't have an account? You may want to create one.

OpenID Login
OpenID login and registration is usable, but not finished.
What is OpenID?
Search

(advanced search)
Site Stats
  Total members: 108
  Latest member: adamthephantump
  Members currently online: 0
  Most online: 5 - Aug 28, 2009 (21:49)
  Front page hits: 88119
Developer info
  Site version: 3.5 Alpha
  16 queries - 9 templates
Under the Spotlight
Collide Site
Collide make fabulously dreamy electronic-industrial music, they're one of my favourite bands! Give them a chance to take control of your life - myspace | youtube - "Euphoria".

Collide Site - Hits: 4926

5/5 (2) | Rate this site?