Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/usr/bin/python3.5
- import datetime
- import os
- import shutil
- now = datetime.datetime.now()
- nameOfScript = "Something v1.0"
- #Windows="cls", osX="clear"
- clearTerm = ("cls" if os.name == "nt" else "clear")
- dirPath = os.path.dirname(os.path.realpath(__file__))
- dirName = "/data"
- newDirPath = dirPath + dirName
- nameFile = "/name.txt"
- ageFile = "/yearBorn.txt"
- storyFile = "/about.txt"
- getDataName = "Name"
- getDataAge = "Age"
- getDataStory = "About"
- setYearBorn = "yearBorn"
- headerName = "DATA"
- helpBarText = \
- ("\n(1)\tShow Data"
- "\n(2)\tEdit items in Data"
- "\n(3)\tEdit About in item"
- "\n(4)\tDel all Data"
- "\n(end)\texit")
- class data:
- _navn = ""
- _alder = 0
- _story = ""
- def __init__(self, navn, yearBorn, story):
- self._navn = navn
- self._story = story
- if yearBorn == None:
- self._alder = ""
- elif yearBorn < 0:
- self._alder = ""
- elif yearBorn > now.year:
- self._alder = ""
- else:
- self._alder = now.year - yearBorn
- def getNavn(self):
- return self._navn
- def getAlder(self):
- return self._alder
- def getStory(self):
- return self._story
- def getData(self):
- return("\n"+ getDataName +":\t {}"
- "\n"+ getDataAge +":\t {}"
- "\n"+ getDataStory +":\n {}")\
- .format(self._navn,
- self._alder,
- self._story)
- # type == a-j
- def createTxt(type, name, yearBorn):
- _name = open(dir(type) + nameFile, "w")
- _name.write(name)
- _name.close()
- _age = open(dir(type) + ageFile, "w")
- _age.write(yearBorn)
- _age.close()
- # type == a-j
- def readTxt(type , nORy):
- if nORy == "n":
- _name = open(dir(type) + nameFile, "r")
- output = _name.read()
- _name.close()
- return output
- elif nORy == "y":
- _age = open(dir(type) + ageFile, "r")
- output = _age.read()
- _age.close()
- if output == "":
- return None
- else:
- return int(output)
- # type == a-j
- def writeStory(type, story):
- _story = open(dir(type) + storyFile, "w")
- _story.write(story)
- _story.close()
- # type == a-j
- def readStory(type):
- _story = open(dir(type) + storyFile, "r")
- output = _story.read()
- _story.close()
- return output
- def delStory(type):
- writeStory(type, "")
- pass
- def checkDir():
- if not os.path.exists(newDirPath):
- os.makedirs(newDirPath)
- os.makedirs(dir("a"))
- os.makedirs(dir("b"))
- os.makedirs(dir("c"))
- os.makedirs(dir("d"))
- os.makedirs(dir("e"))
- os.makedirs(dir("f"))
- os.makedirs(dir("g"))
- os.makedirs(dir("h"))
- os.makedirs(dir("i"))
- os.makedirs(dir("j"))
- createTxt("a", "", "")
- createTxt("b", "", "")
- createTxt("c", "", "")
- createTxt("d", "", "")
- createTxt("e", "", "")
- createTxt("f", "", "")
- createTxt("g", "", "")
- createTxt("h", "", "")
- createTxt("i", "", "")
- createTxt("j", "", "")
- writeStory("a", "")
- writeStory("b", "")
- writeStory("c", "")
- writeStory("d", "")
- writeStory("e", "")
- writeStory("f", "")
- writeStory("g", "")
- writeStory("h", "")
- writeStory("i", "")
- writeStory("j", "")
- return
- else:
- return
- # type == a-j
- def dir(type):
- return(newDirPath + "/" + type)
- def readName(type):
- if type == "a":
- return a.getNavn()
- if type == "b":
- return b.getNavn()
- if type == "c":
- return c.getNavn()
- if type == "d":
- return d.getNavn()
- if type == "e":
- return e.getNavn()
- if type == "f":
- return f.getNavn()
- if type == "g":
- return g.getNavn()
- if type == "h":
- return h.getNavn()
- if type == "i":
- return i.getNavn()
- if type == "j":
- return j.getNavn()
- # type == a-j
- def readData(type):
- _data = data(readTxt(type, "n"), readTxt(type, "y"), readStory(type))
- return _data
- def updateData():
- global a
- global b
- global c
- global d
- global e
- global f
- global g
- global h
- global i
- global j
- a = readData("a")
- b = readData("b")
- c = readData("c")
- d = readData("d")
- e = readData("e")
- f = readData("f")
- g = readData("g")
- h = readData("h")
- i = readData("i")
- j = readData("j")
- checkDir()
- a = readData("a")
- b = readData("b")
- c = readData("c")
- d = readData("d")
- e = readData("e")
- f = readData("f")
- g = readData("g")
- h = readData("h")
- i = readData("i")
- j = readData("j")
- def database():
- return("----------------------------"
- "\n"+ headerName +":\n"
- "\n\ta:\t{}"
- "\n\tb:\t{}"
- "\n\tc:\t{}"
- "\n\td:\t{}"
- "\n\te:\t{}"
- "\n\tf:\t{}"
- "\n\tg:\t{}"
- "\n\th:\t{}"
- "\n\ti:\t{}"
- "\n\tj:\t{}"
- "\n\n"
- "----------------------------")\
- .format(a.getNavn(),
- b.getNavn(),
- c.getNavn(),
- d.getNavn(),
- e.getNavn(),
- f.getNavn(),
- g.getNavn(),
- h.getNavn(),
- i.getNavn(),
- j.getNavn())
- def main():
- close = False
- while not close:
- absolutely_unused_variable = os.system(clearTerm)
- print(nameOfScript)
- print("----------------------------")
- print(helpBarText)
- print("\n----------------------------")
- choice = input("\nChoose: ")
- if choice == "1":
- closeShowItems = False
- while not closeShowItems:
- absolutely_unused_variable = os.system(clearTerm)
- print(nameOfScript)
- print(database())
- choiceDatabase = input("Show Item: ")
- if readName(choiceDatabase) == "":
- None
- else:
- if choiceDatabase == "a":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(a.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "b":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(b.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "c":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(c.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "d":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(d.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "e":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(e.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "f":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(f.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "g":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(g.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "h":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(h.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "i":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(i.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "j":
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + choiceDatabase + "\n----------------------------")
- print(j.getData())
- print("----------------------------")
- input()
- if choiceDatabase == "":
- closeShowItems = True
- if choice == "2":
- closeEditItems = False
- while not closeEditItems:
- absolutely_unused_variable = os.system(clearTerm)
- print(nameOfScript)
- print(database())
- spes = input("Edit Item: ")
- if spes in ("a",
- "b",
- "c",
- "d",
- "e",
- "f",
- "g",
- "h",
- "i"
- "j"):
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + spes +"\n----------------------------")
- name = input("Set " + getDataName +": ")
- navn = readName(spes)
- if name == "":
- print("Are you sure your want to delete item (" + spes + ")?")
- delChoice = input("y/n")
- if delChoice == "y":
- age = ""
- delStory(spes)
- createTxt(spes, name, age)
- updateData()
- else:
- closeEditItems = True
- elif name != navn:
- age = input("Set " + setYearBorn + ": ")
- delStory(spes)
- createTxt(spes,name,age)
- updateData()
- elif spes == "":
- closeEditItems = True
- if choice == "3":
- closeEditAbout = False
- while not closeEditAbout:
- absolutely_unused_variable = os.system(clearTerm)
- print(nameOfScript)
- print(database())
- spes = input("Edit " + getDataStory +" in Item: ")
- if spes in ("a",
- "b",
- "c",
- "d",
- "e",
- "f",
- "g",
- "h",
- "i"
- "j"):
- absolutely_unused_variable = os.system(clearTerm)
- print("Item=" + spes + "\n----------------------------")
- imName = readName(spes)
- if imName == "":
- None
- else:
- print(getDataStory + ":\n")
- mainStory = ""
- while True:
- story = input()
- if story == '': break
- mainStory = mainStory + "\n" + story
- writeStory(spes, mainStory)
- updateData()
- elif spes == "":
- closeEditAbout = True
- if choice == "4":
- absolutely_unused_variable = os.system(clearTerm)
- print("\nAre you sure you want to delete all data?")
- deld = input("y/n: ")
- if deld == "y":
- shutil.rmtree(newDirPath)
- checkDir()
- updateData()
- if choice == "end":
- absolutely_unused_variable = os.system(clearTerm)
- close = True
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement