Skip to content

vinta/pangu.space

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

pangu.space

Paranoid text spacing for good readability, to automatically insert whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, numerical digits and symbols).

Usage

Current APIs:

  • https://api.pangu.space/v1/spacing-text?t=YOUR-TEXT

in Command-line interface:

$ curl https://api.pangu.space/v1/spacing-text -G --data-urlencode "t=當你凝視著bug,bug也凝視著你" -H "x-api-key: TiEeVInyGza4ta0kougRH4MBBfdGe2Q91TjrbQLm" -w "\n"
當你凝視著 bug,bug 也凝視著你

in Python:

import requests

r = requests.get('https://api.pangu.space/v1/spacing-text?t=當你凝視著bug,bug也凝視著你', headers={'x-api-key': 'TiEeVInyGza4ta0kougRH4MBBfdGe2Q91TjrbQLm'})
print(r.content.decode('utf-8'))
# 當你凝視著 bug,bug 也凝視著你

You must request the API with a HTTP header x-api-key: TiEeVInyGza4ta0kougRH4MBBfdGe2Q91TjrbQLm. Yeah, you are free to use the API key for accessing the service. Although it has a quota of 100000 requests per month.

Development

pangu.space is built on AWS Lambda and Amazon API Gateway. I use Apex to manage and deploy Lambda functions.

# deploy all functions
$ apex deploy

# view logs
$ apex logs -f

# invoke a function directly
$ apex invoke spacing_text --logs
{
    "statusCode": 400,
    "headers": null,
    "body":"{\"message\": \"No text was provided in HTTP query string\"}"
}

# invoke a function with an API Gateway event
$ cat fixtures/spacing_text_event.json
{
    "queryStringParameters": {"t": "與PM戰鬥的人,應當小心自己不要成為PM"}
}
$ apex invoke spacing_text --logs < fixtures/spacing_text_event.json
{
    "statusCode": 200,
    "headers": {"content-type": "text/plain; charset=utf-8"},
    "body": "與 PM 戰鬥的人,應當小心自己不要成為 PM"
}

Related Posts

About

Paranoid text spacing as a service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published