๐Ÿ“ฆ vinta / pangu.space

Paranoid text spacing as a service

โ˜… 27 stars โ‘‚ 4 forks ๐Ÿ‘ 27 watching โš–๏ธ MIT License
๐Ÿ“ฅ Clone https://github.com/vinta/pangu.space.git
HTTPS git clone https://github.com/vinta/pangu.space.git
SSH git clone git@github.com:vinta/pangu.space.git
CLI gh repo clone vinta/pangu.space
Vinta Vinta update README 42a1ac6 7 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ docs
๐Ÿ“ fixtures
๐Ÿ“ functions
๐Ÿ“ infrastructure
๐Ÿ“ vendor
๐Ÿ“„ .gitignore
๐Ÿ“„ Gopkg.lock
๐Ÿ“„ Gopkg.toml
๐Ÿ“„ LICENSE
๐Ÿ“„ Makefile
๐Ÿ“„ mkdocs.yml
๐Ÿ“„ project.json
๐Ÿ“„ README.md
๐Ÿ“„ README.md

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