Esempio n. 1
0
    def test_journal_init(self):
        """
		Verify init journal is correct.
		"""

        journal = Journal()

        self.assertEqual(journal.get_journal_amount(), 0.0000)
Esempio n. 2
0
    def test_journal_add_item_acount(self):
        """
		Verify add item acount in journal is correct.
		"""

        journal = Journal()
        journal.add_acount('Jorge')

        journal.add_item_acount('Jorge', 'Capitan del espacio', 10.0000)

        self.assertEqual(journal.get_journal_amount(), 10.0000)
Esempio n. 3
0
    def test_journal_add_acount(self):
        """
		Verify add acount in journal is correct.
		"""

        journal = Journal()
        journal.add_acount('Jorge')

        self.assertEqual(journal.get_number_acounts(), 1)
        self.assertEqual(journal.is_acount_in_journal('Jorge'), True)
        self.assertEqual(journal.is_acount_in_journal('Pablo'), False)
Esempio n. 4
0
    def test_journal_acount_numbers(self):
        """
		Verify number of acounts in journals.
		"""

        journal = Journal()

        for index in xrange(1, 20):
            acount = Acount('luz_%s' % index)
            journal.add_acount(acount)

            self.assertEqual(journal.get_number_acounts(), index)
Esempio n. 5
0
    def setUp(self) -> None:
        # setting up testing set of instances

        self.item1 = Book("Tropic of Cancer", "Henry Miller", "Autobiographical novel", 1934, 318)
        self.item2 = Book("1984", "George Orwell", "Novel", 1949, 328)
        self.item3 = Book("Junkie", "William S. Burroughs", "Autobiographical novel", 1953, 166)
        self.item4 = Book("On the Road", "Jack Kerouac", "Autobiographical novel", 1957, 320)
        self.item5 = Comics("Deadpool", "Marvel", "Superhero", 2019, 25)
        self.item6 = Journal("ATT", "AT", "Celebrity", "10.20.2021", 14)
        self.item7 = Newspaper("NYT", "NY", "Weekly", "04.10.2020", 20)
        self.item8 = Magazine("Rolling Stone", "Wenner Media LLC", "Musical", "04.10.2020", 18)
        result = [self.item1, self.item2, self.item3, self.item4, self.item5, self.item6, self.item7]
        self.manager = BookstoreManager(result)
Esempio n. 6
0
 def __init__( self ):
     App.__init__( self )
     config = ConfigParser.ConfigParser()
     config.read('config.ini')
     self.journal_file = config.get( 'Journal', 'journal_file' )
     self.simple_program_name = config.get('Training program',
                                           'simple_program_name' )
     self.simple_program_last_training = config.getint(
         'Training program', 'simple_program_last_training' )
     if os.path.isfile( self.journal_file ):            
         self.journal = Journal.load_journal( self.journal_file )
     else:
         self.journal = Journal( [], {} )
     self.dict_of_simple_programs = self.read_simple_programs()
     self.simple_program = self.dict_of_simple_programs.get(
         self.simple_program_name )        
Esempio n. 7
0
 def set_another_journal(self, *rest):
     app = App.get_running_app()
     journal_file = self.journal_file_input.text
     filename, file_extension = os.path.splitext(journal_file)
     if file_extension != '.json':
         self.show_not_json_popup()
         return
     if journal_file != app.journal_file:
         app.journal_file = journal_file
         if os.path.isfile(app.journal_file):
             app.journal = Journal.load_journal(app.journal_file)
         else:
             app.journal = Journal()
     app.write_config()
     for node in self.tree_view.iterate_all_nodes():
         self.tree_view.remove_node(node)
     self.populate_tree_view()
Esempio n. 8
0
def run(manual_args=None):
    args = parse_args(manual_args)
    configure_logger(args.debug)
    args.text = [p.decode('utf-8') if util.PY2 and not isinstance(p, unicode) else p for p in args.text]
    if args.version:
        version_str = "{0} version {1}".format(jrnl.__title__, jrnl.__version__)
        print(util.py2encode(version_str))
        sys.exit(0)

    if not os.path.exists(CONFIG_PATH):
        log.debug('Configuration file not found, installing jrnl...')
        config = install.install_jrnl(CONFIG_PATH)
    else:
        log.debug('Reading configuration from file %s', CONFIG_PATH)
        config = util.load_and_fix_json(CONFIG_PATH)
        install.upgrade_config(config, config_path=CONFIG_PATH)

    if args.ls:
        print(util.py2encode(list_journals(config)))
        sys.exit(0)

    log.debug('Using configuration "%s"', config)
    original_config = config.copy()
    # check if the configuration is supported by available modules
    if config['encrypt'] and not PYCRYPTO:
        util.prompt("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.")
        sys.exit(1)

    # If the first textual argument points to a journal file,
    # use this!
    journal_name = args.text[0] if (args.text and args.text[0] in config['journals']) else 'default'
    if journal_name is not 'default':
        args.text = args.text[1:]
    # If the first remaining argument looks like e.g. '-3', interpret that as a limiter
    if not args.limit and args.text and args.text[0].startswith("-"):
        try:
            args.limit = int(args.text[0].lstrip("-"))
            args.text = args.text[1:]
        except:
            pass

    log.debug('Using journal "%s"', journal_name)
    journal_conf = config['journals'].get(journal_name)
    if type(journal_conf) is dict:  # We can override the default config on a by-journal basis
        log.debug('Updating configuration with specific jourlnal overrides %s', journal_conf)
        config.update(journal_conf)
    else:  # But also just give them a string to point to the journal file
        config['journal'] = journal_conf

    if config['journal'] is None:
        util.prompt("You have not specified a journal. Either provide a default journal in your config file, or specify one of your journals on the command line.")
        sys.exit(1)

    config['journal'] = os.path.expanduser(os.path.expandvars(config['journal']))
    touch_journal(config['journal'])
    log.debug('Using journal path %(journal)s', config)
    mode_compose, mode_export = guess_mode(args, config)

    # open journal file or folder
    if os.path.isdir(config['journal']):
        if config['journal'].strip("/").endswith(".dayone") or \
           "entries" in os.listdir(config['journal']):
            journal = DayOneJournal.DayOne(**config)
        else:
            util.prompt("[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
            sys.exit(1)
    else:
        journal = Journal.Journal(journal_name, **config)

    # How to quit writing?
    if "win32" in sys.platform:
        _exit_multiline_code = "on a blank line, press Ctrl+Z and then Enter"
    else:
        _exit_multiline_code = "press Ctrl+D"

    if mode_compose and not args.text:
        if not sys.stdin.isatty():
            # Piping data into jrnl
            raw = util.py23_read()
        elif config['editor']:
            raw = util.get_text_from_editor(config)
        else:
            try:
                raw = util.py23_read("[Compose Entry; " + _exit_multiline_code + " to finish writing]\n")
            except KeyboardInterrupt:
                util.prompt("[Entry NOT saved to journal.]")
                sys.exit(0)
        if raw:
            args.text = [raw]
        else:
            mode_compose = False

    journal.open()

    # Writing mode
    if mode_compose:
        raw = " ".join(args.text).strip()
        if util.PY2 and type(raw) is not unicode:
            raw = raw.decode(sys.getfilesystemencoding())
        log.debug('Appending raw line "%s" to journal "%s"', raw, journal_name)
        journal.new_entry(raw)
        util.prompt("[Entry added to {0} journal]".format(journal_name))
        journal.write()
    else:
        old_entries = journal.entries
        if args.on_date:
            args.start_date = args.end_date = args.on_date
        journal.filter(tags=args.text,
                       start_date=args.start_date, end_date=args.end_date,
                       strict=args.strict,
                       short=args.short,
                       starred=args.starred)
        journal.limit(args.limit)

    # Reading mode
    if not mode_compose and not mode_export:
        print(util.py2encode(journal.pprint()))

    # Various export modes
    elif args.short:
        print(util.py2encode(journal.pprint(short=True)))

    elif args.tags:
        print(util.py2encode(exporters.to_tag_list(journal)))

    elif args.export is not False:
        print(util.py2encode(exporters.export(journal, args.export, args.output)))

    elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTO:
        util.prompt("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.")

    elif args.encrypt is not False:
        encrypt(journal, filename=args.encrypt)
        # Not encrypting to a separate file: update config!
        if not args.encrypt or args.encrypt == config['journal']:
            update_config(original_config, {"encrypt": True}, journal_name, force_local=True)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.decrypt is not False:
        decrypt(journal, filename=args.decrypt)
        # Not decrypting to a separate file: update config!
        if not args.decrypt or args.decrypt == config['journal']:
            update_config(original_config, {"encrypt": False}, journal_name, force_local=True)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.edit:
        if not config['editor']:
            util.prompt("[You need to specify an editor in {0} to use the --edit function.]".format(CONFIG_PATH))
            sys.exit(1)
        other_entries = [e for e in old_entries if e not in journal.entries]
        # Edit
        old_num_entries = len(journal)
        edited = util.get_text_from_editor(config, journal.editable_str())
        journal.parse_editable_str(edited)
        num_deleted = old_num_entries - len(journal)
        num_edited = len([e for e in journal.entries if e.modified])
        prompts = []
        if num_deleted:
            prompts.append("{0} {1} deleted".format(num_deleted, "entry" if num_deleted == 1 else "entries"))
        if num_edited:
            prompts.append("{0} {1} modified".format(num_edited, "entry" if num_edited == 1 else "entries"))
        if prompts:
            util.prompt("[{0}]".format(", ".join(prompts).capitalize()))
        journal.entries += other_entries
        journal.sort()
        journal.write()
Esempio n. 9
0
import Abiturient
import Journal
journal = Journal.Journal()

stud1 = Abiturient.Abiturient()
journal.add_student(stud1)

stud2 = Abiturient.Abiturient()
journal.add_student(stud2)

stud3 = Abiturient.Abiturient()
journal.add_student(stud3)
'''
stud4 = Abiturient.Abiturient()
stud5 = Abiturient.Abiturient()
stud6 = Abiturient.Abiturient()
'''
''' 
journal.add_student(stud4)
journal.add_student(stud5)
journal.add_student(stud6)
'''

#journal.del_obj()

#journal.above_specified_value(5)

#journal.bad_marks()

#journal.grade_point_average()
Esempio n. 10
0
    manager = BookstoreManager(BookstoreItem.storage)
    book1 = Book("Tropic of Cancer", "Henry Miller", "Autobiographical novel",
                 1934, 318)
    book2 = Book("1984", "George Orwell", "Novel", 1949, 328)
    book3 = Book("Junkie", "William S. Burroughs", "Autobiographical novel",
                 1953, 166)
    # book4 = Book("Edinburgh", "Alexander Chee", "Autobiographical novel", 2001, 209)
    book5 = Book("Giovanni's Room", "James Baldwin", "Poem", 1956, 159)
    book6 = Book("On the Road", "Jack Kerouac", "Autobiographical novel", 1957,
                 320)

    comics1 = Comics("Deadpool", "Marvel", "Superhero", 2019, 25)

    newspaper1 = Newspaper("NYT", "NY", "Weekly", "04.10.2020", 20)

    journal1 = Journal("ATT", "AT", "Celebrity", "10.20.2021", 14)

    magazine1 = Magazine("Rolling Stone", "Wenner Media LLC", "Musical",
                         "04.10.2020", 18)
    magazine2 = Magazine("Esquire", "Hearts Communications Inc", "Fashion",
                         "21.11.2014", 22)
    magazine3 = Magazine("Vanity Fair", "Conde Nast", "Musical", "15.12.2020",
                         30)
    magazine4 = Magazine("Elle", "Kevin OMalley", "Musical", "10.04.2018", 14)

    print("Unsorted list of autobiographical novel genre items:\n")
    for item in manager.find_item_by_genre("Autobiographical novel"):
        print(item)

    print(
        "Sorted by ascending name list of autobiographical novel genre items:\n"
Esempio n. 11
0
def cli():
    if not os.path.exists(CONFIG_PATH):
        config = install.install_jrnl(CONFIG_PATH)
    else:
        with open(CONFIG_PATH) as f:
            config = json.load(f)
        install.update_config(config, config_path=CONFIG_PATH)

    original_config = config.copy()
    # check if the configuration is supported by available modules
    if config['encrypt'] and not PYCRYPTO:
        print(
            "According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org."
        )
        sys.exit(-1)

    args = parse_args()

    # If the first textual argument points to a journal file,
    # use this!
    journal_name = args.text[0] if (
        args.text and args.text[0] in config['journals']) else 'default'
    if journal_name is not 'default':
        args.text = args.text[1:]
    journal_conf = config['journals'].get(journal_name)
    if type(
            journal_conf
    ) is dict:  # We can override the default config on a by-journal basis
        config.update(journal_conf)
    else:  # But also just give them a string to point to the journal file
        config['journal'] = journal_conf
    touch_journal(config['journal'])
    mode_compose, mode_export = guess_mode(args, config)

    # open journal file or folder


    if os.path.isdir(config['journal']) and ( config['journal'].endswith(".dayone") or \
        config['journal'].endswith(".dayone/")):
        journal = Journal.DayOne(**config)
    else:
        journal = Journal.Journal(**config)

    if mode_compose and not args.text:
        if config['editor']:
            raw = get_text_from_editor(config)
        else:
            raw = util.py23_input("[Compose Entry] ")
        if raw:
            args.text = [raw]
        else:
            mode_compose = False

    # Writing mode
    if mode_compose:
        raw = " ".join(args.text).strip()
        entry = journal.new_entry(raw, args.date)
        entry.starred = args.star
        print("[Entry added to {0} journal]".format(journal_name))
        journal.write()

    # Reading mode
    elif not mode_export:
        journal.filter(tags=args.text,
                       start_date=args.start_date,
                       end_date=args.end_date,
                       strict=args.strict,
                       short=args.short)
        journal.limit(args.limit)
        print(journal)

    # Various export modes
    elif args.tags:
        print_tags(journal)

    elif args.json:  # export to json
        print(exporters.to_json(journal))

    elif args.markdown:  # export to json
        print(exporters.to_md(journal))

    elif (args.encrypt is not False
          or args.decrypt is not False) and not PYCRYPTO:
        print(
            "PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org."
        )

    elif args.encrypt is not False:
        encrypt(journal, filename=args.encrypt)
        # Not encrypting to a separate file: update config!
        if not args.encrypt:
            update_config(original_config, {
                "encrypt": True,
                "password": ""
            }, journal_name)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.decrypt is not False:
        decrypt(journal, filename=args.decrypt)
        # Not decrypting to a separate file: update config!
        if not args.decrypt:
            update_config(original_config, {
                "encrypt": False,
                "password": ""
            }, journal_name)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.delete_last:
        last_entry = journal.entries.pop()
        print("[Deleted Entry:]")
        print(last_entry)
        journal.write()
Esempio n. 12
0
    else:
        if sys.argv[1] == 'pull':
            while True:
                try:
                    print(">> git pull")
                    mess = puller.pull()
                    print(mess)
                    break
                except:
                    print("unsuccessful, retry")
                    sleep(5)
            sys.exit()
        debug = True

    wtab = wt.WeekTable()  # The template for planner
    jnal = jn.Journal()  # The Journal
    plan = pl.Plan()  # The planner
    time = tm.Time()  # Lazy time tracker
    tenw = tw.TenWeek()  # The long run
    print('wtab, jnal, plan, time, tenw: On')

    tick = cl.Clock(debug)  # The loop
    print('tick: On' + int(debug) * ' (debug mode)')

    while not tick.exit:
        # Mail receive a special treatment since it needs
        # to be destruct and re-construct when there is connection fault
        # thus it is initiate inside the scope of tick.run
        tick.run(ml, time, tenw, wtab, jnal, plan)
        if tick.update:
            # TODO: Run git synchorise here