Script: upside_down.py

Replaces text you write with upside down text.
Author: xt — Version: 0.3.1 — License: GPL3
For WeeChat ≥ 0.3.0.
Tags: input, py3
Added: 2010-01-14 — Updated: 2022-03-19

Download GitHub Repository

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -*- coding: utf-8 -*-
#
# Copyright (c) 2009 by xt <xt@bash.no>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
# USAGE: Bind a key to command /flip . Then write some text at input line
# press your key to transform it to upside down.

#
# (this script requires WeeChat 0.3.0 or newer)
#
# History:
# 2022-03-14, TauPan <taupan@gmail.com>
#   version 0.3.1: port to python3
# 2010-01-14, xt
#   version 0.3: steal more chars from m4v
# 2010-01-06, xt <xt@bash.no>
#   version 0.2: fix idiotic programming
# 2009-11-12, xt <xt@bash.no>
#   version 0.1: initial release

import weechat as w
import re

SCRIPT_NAME    = "upside_down"
SCRIPT_AUTHOR  = "xt <xt@bash.no>"
SCRIPT_VERSION = "0.3.1"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC    = "Replaces text you write with upside down text"

settings = {}

replacements = {
# Upper case
    u'A' : u'\N{FOR ALL}',
    u'B' : u'\N{GREEK SMALL LETTER XI}',
    u'C' : u'\N{ROMAN NUMERAL REVERSED ONE HUNDRED}',
    u'D' : u'\N{LEFT HALF BLACK CIRCLE}',
    u'E' : u'\N{LATIN CAPITAL LETTER REVERSED E}',
    u'F' : u'\N{TURNED CAPITAL F}',
    u'G' : u'\N{TURNED SANS-SERIF CAPITAL G}',
    u'J' : u'\N{LATIN SMALL LETTER LONG S}',
    u'K' : u'\N{RIGHT NORMAL FACTOR SEMIDIRECT PRODUCT}',
    u'L' : u'\ua780',
    u'M' : u'W',
    u'N' : u'\N{LATIN LETTER SMALL CAPITAL REVERSED N}',
    u'P' : u'\N{CYRILLIC CAPITAL LETTER KOMI DE}',
    u'Q' : u'\N{GREEK CAPITAL LETTER OMICRON WITH TONOS}',
    u'R' : u'\N{LATIN LETTER SMALL CAPITAL TURNED R}',
    u'T' : u'\N{UP TACK}',
    u'U' : u'\N{INTERSECTION}',
    u'V' : u'\u0245',
    u'Y' : u'\N{TURNED SANS-SERIF CAPITAL Y}',
     'a' : u"\u0250",
     'b' : u'q',
     'c' : u"\u0254",
     'd' : u'p',
     'e' : u"\u01DD",
     'f' : u"\u025F",
     'g' : u"\u0183",
     'h' : u'\u0265',
     'i' : u'\u0131',
     'j' : u'\u027E',
     'k' : u'\u029E',
     'm' : u'\u026F',
     'n' : u'u',
     'r' : u'\u0279',
     't' : u'\u0287',
     'p' : u'd',
     'u' : u'n',
     'q' : u'b',
     'v' : u'\u028C',
     'w' : u'\u028D',
     'y' : u'\u028E',
     '.' : u'\u02D9',
     '[' : u']',
     '(' : u')',
     '{' : u'}',
     '?' : u'\u00BF',
     '!' : u'\u00A1',
     "\'" :u',',
     '>' : u'<',
     '<' : u'>',
     '_' : u'\u203E',
     ';' : u'\u061B',
     '\u203F' : u'\u2040',
     '\u2045' : u'\u2046',
     '\u2234' : u'\u2235',
}



if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                    SCRIPT_DESC, "", ""):
    for option, default_value in settings.items():
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, default_value)
    w.hook_command("flip",
                         SCRIPT_DESC,
                         "[text]",
                         "text: text to be flipped\n"
                         "",
                         "", "flip_cmd_cb", "")


def flip_cmd_cb(data, buffer, args):
    ''' Command /flip '''
    translate_input = args
    if not translate_input:
        translate_input = w.buffer_get_string(w.current_buffer(), "input")
    outstring = ''
    for char  in translate_input:
        if char in replacements:
            char = replacements[char]
        outstring += char
    w.buffer_set(w.current_buffer(), 'input', outstring)
    return w.WEECHAT_RC_OK