Skip to content

Instantly share code, notes, and snippets.

@madosuki
Last active October 4, 2017 00:36
Show Gist options
  • Save madosuki/be533c24dd3d0e2e4177c4e684cbf105 to your computer and use it in GitHub Desktop.
Save madosuki/be533c24dd3d0e2e4177c4e684cbf105 to your computer and use it in GitHub Desktop.
Python3用。テキストファイルに書かれた文字を縦書きっぽく成形し、クリップボードに入れるだけのプログラムです。
#encoding: utf-8
import sys
import pyperclip as clip
class Vertical:
def __init__(self):
self.size = 0
self.tex = ""
self.count = 0
self.l = []
self.dic = {"。":"︒", "、":"︑", "?":"︖", "!":"︕", ",":"︐", ":":"︓", ";":"︔","(":"︵",")":"︶","{":"︷","}":"︸","「":"﹁","」":"﹂","『":"﹃","』":"﹄","〈":"︿", "〉":"﹀", "【":"︻", "】":"︼", "《":"︽", "》":"︾", "〔":"︹", "〕":"︺", "[":"﹇", "]":"﹈", "―":"︱", "…":"︙", "‥":"︰", "ー":"丨"}
def HorizonalToVertical(self, text):
locallist = text
size = len(text)
for i in range(size):
if self.count == 0:
tmp = locallist[i]
for j in self.dic:
if tmp == j:
tmp = self.dic[j]
break
self.l.append(tmp)
else:
tmp = locallist[i]
for j in self.dic:
if tmp == j:
tmp = self.dic[j]
break
self.l[i] = tmp + self.l[i]
self.count = self.count + 1
def AddSpace(self, text, size):
result = ""
for i in range(size):
strsize = len(text)
if strsize < (size):
space = ""
diff = size - strsize
for j in range(diff):
space = space + " "
result = text + space
return result
return False
def AddNewLineCode(self):
size = len(self.l)
for i in range(size):
self.l[i] = self.l[i] + "\n"
def GoToVertical(path):
f = open(path, "r")
v = Vertical()
size = 0
for check in f:
text = check.replace("\n", "")
if size < len(text):
size = len(text)
f.seek(0)
for line in f:
text = line.replace("\n", "")
test = v.AddSpace(text, size)
if test != False:
text = test
v.HorizonalToVertical(text)
f.close()
for i in v.l:
print(i)
v.AddNewLineCode()
result = "".join(v.l)
clip.copy(result)
def main():
argvs = sys.argv
count = len(argvs)
if count == 1:
print("Please Text File Path.")
exit()
else:
print("")
GoToVertical(argvs[1])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment