CLIでメモするPythonのスクリプト
ビビるほどtiny。
あくまで暫定版。
python cMemo.py add bodyなどとすればbodyというテキストがmemo.mdに追記される。
それだけ。
python cMemo.pyをaliasに登録しておく。
たとえばmemoとaliasにすれば、memo add bodyなどでbodyが記録できる。
python cMemo.py listでmemo.mdの中身が表示される。
それだけ。
こういうテキスト型のメモツールを使うとどういう感触がするのかを確かめたいので作ってみた。
code:sample.py
#this script is CLI type memo tool import sys
import os
targetMdFile = "memo.md"
def addMemo(text):
print ("add " + text)
if os.path.isfile(targetMdFile):
with open(targetMdFile,mode="r") as f:
l = f.read()
print(l)
l = l + "\n" + text
with open(targetMdFile,mode="w") as f:
f.write(l)
def callMemo():
if os.path.isfile(targetMdFile):
with open(targetMdFile,mode="r") as f:
l = f.read()
print(l)
def main():
if len(sys.argv) == 1:
print("hello")
if len(sys.argv) == 2:
receivedCommand = sys.argv1 if receivedCommand == "list":
callMemo()
if len(sys.argv) == 3:
receivedCommand = sys.argv1 receivedObject = sys.argv2 if receivedCommand == "add":
addMemo(receivedObject)
if __name__ == "__main__":
main()