Skip to content

Instantly share code, notes, and snippets.

@damilare
Created June 17, 2012 12:04
Show Gist options
  • Save damilare/2944350 to your computer and use it in GitHub Desktop.
Save damilare/2944350 to your computer and use it in GitHub Desktop.
Case correction service
import re, web, urlparse
def correct_case(text):
return ' '.join(['%s.' % x.strip().capitalize() for x in re.split('\.', text) if x])
urls = (
'/api/correct_case','CaseService'
)
app = web.application(urls, globals())
class CaseService:
def GET(self):
return 'Please send a POST request'
def POST(self):
text = None
data = urlparse.parse_qsl(web.data())
for k,v in data:
if k == 'str':
text = v
if text:
return correct_case(text)
else:
return 'Please send you text in a str parameter'
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment