How can we post ASCII art on Facebook wall?

前端 未结 2 847
無奈伤痛
無奈伤痛 2021-01-14 16:52

In my app, I have a requirement to post the ASCII art from my iPhone app onto the Facebook wall post. But the problem I face is that Facebook font (Lucida Console) Changes t

2条回答
  •  余生分开走
    2021-01-14 17:14

    I came up with a Python script, only tested it with simple examples so far.

    #!/usr/bin/python
    '''
    fbformat -- format ASCII for Facebook
    '''
    import sys, os
    PRINTABLE = [' '] + map(chr, range(ord('!'), ord('~') + 1))
    FB_ABLE = [u'\u3000'] + map(unichr, range(0xff01, 0xff5f))
    TO_FB = dict(zip(PRINTABLE, FB_ABLE))
    FROM_FB = dict(zip(FB_ABLE, PRINTABLE))
    COMMAND = os.path.splitext(os.path.basename(sys.argv[0]))[0]
    TEXT = sys.stdin.read().decode('utf8')
    TO = ''.join([TO_FB.get(C, C) for C in TEXT])
    FROM = ''.join([FROM_FB.get(C, C) for C in TEXT])
    sys.stdout.write([TO, FROM][COMMAND == 'fbunformat'].encode('utf8'))
    

    symlink it as ~/home/bin/fbformat and ~/home/bin/fbunformat, and make sure ~/home/bin is in your PATH.

    enter the following as test.txt:

    YES!
    \o/
     |
    / \
    

    then:

    jcomeau@aspire:~/rentacoder/gdavis$ fbformat < /tmp/test.txt
    YES!
    \o/
     |
    / \
    jcomeau@aspire:~/rentacoder/gdavis$ fbformat < /tmp/test.txt | fbunformat
    YES!
    \o/
     |
    / \
    

    resources: http://www.cs.tut.fi/~jkorpela/chars/spaces.html and https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms

提交回复
热议问题