Created
June 13, 2018 04:41
-
-
Save CavaTrendy/d10a64b9a08653ef4eba39d430537614 to your computer and use it in GitHub Desktop.
Writing a Journal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This is the Journal module | |
created with the help of Python Jumpstart by Building 10 Apps | |
''' | |
import os | |
def load(name): | |
''' | |
This method creates and load new journal | |
:param name: base name of the journal to load | |
:return: a new journal nme structure populated with file data | |
''' | |
data = [] | |
filename = get_fullpath_name(name) | |
if os.path.exists(filename): | |
with open(filename) as fin: | |
for entry in fin.readlines(): | |
data.append(entry.rstrip()) | |
return data | |
def save(name, journal_data): | |
filename = get_fullpath_name(name) | |
print('Saving to: {}'.format(filename)) | |
with open(filename, 'w') as fout: | |
for entry in journal_data: | |
fout.write(entry + '\n') | |
def get_fullpath_name(name): | |
filename = os.path.abspath(os.path.join(".", "Journal", name + ".jrl")) | |
return filename | |
def add_entry(text, journal_data): | |
journal_data.append(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
created with the help of Python Jumpstart by Building 10 Apps | |
''' | |
print('1.About to import journal') | |
import program2 | |
print('2.Program imported') | |
print('3. Printing header') | |
program2.print_header() | |
print('Done it')print('1.About to import journal') | |
import program2 | |
print('2.Program imported') | |
print('3. Printing header') | |
program2.print_header() | |
print('Done it') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
created with the help of Python Jumpstart by Building 10 Apps | |
''' | |
import journal | |
def main(): | |
print_header() | |
run_event_loop() | |
def print_header(): | |
print('----------------------') | |
print(" Journal App") | |
print('----------------------') | |
def run_event_loop(): | |
print('What you want to do with the journal? ') | |
cmd = 'empty' | |
journal_name = 'default' | |
journal_data = journal.load(journal_name)# list() | |
while cmd!='x' and cmd: | |
cmd = input('[L]ist entries, [A]dd an entry, E[x]it: ') | |
if cmd.lower().strip() == 'l': | |
list_entries(journal_data) | |
elif cmd.lower( ).strip() == 'a': | |
add_entries(journal_data) | |
elif cmd.lower().strip() != 'x' and cmd: | |
print ("Sorry we do not understand '{}'.". format(cmd)) | |
print('Done, Thank you and Goodbye') | |
journal.save(journal_name , journal_data) | |
def list_entries(data): | |
print('Journal entries are: ') | |
entries = reversed(data) | |
for idx, entry in enumerate(entries): | |
print('* [{}] {}'. format(idx + 1, entry)) | |
def add_entries(data): | |
text = input('Type your entry, <enter> to exit: ') | |
journal.add_entry(text, data) | |
#data.append(text) | |
print('__fle__ ' + __file__) | |
print('__name__ ' + __name__) | |
if __name__ == "__main__": | |
main() | |
import journal | |
def main(): | |
print_header() | |
run_event_loop() | |
def print_header(): | |
print('----------------------') | |
print(" Journal App") | |
print('----------------------') | |
def run_event_loop(): | |
print('What you want to do with the journal? ') | |
cmd = 'empty' | |
journal_name = 'default' | |
journal_data = journal.load(journal_name)# list() | |
while cmd!='x' and cmd: | |
cmd = input('[L]ist entries, [A]dd an entry, E[x]it: ') | |
if cmd.lower().strip() == 'l': | |
list_entries(journal_data) | |
elif cmd.lower( ).strip() == 'a': | |
add_entries(journal_data) | |
elif cmd.lower().strip() != 'x' and cmd: | |
print ("Sorry we do not understand '{}'.". format(cmd)) | |
print('Done, Thank you and Goodbye') | |
journal.save(journal_name , journal_data) | |
def list_entries(data): | |
print('Journal entries are: ') | |
entries = reversed(data) | |
for idx, entry in enumerate(entries): | |
print('* [{}] {}'. format(idx + 1, entry)) | |
def add_entries(data): | |
text = input('Type your entry, <enter> to exit: ') | |
journal.add_entry(text, data) | |
#data.append(text) | |
print('__fle__ ' + __file__) | |
print('__name__ ' + __name__) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment