예제 #1
0
def test_from_json_file(nested_example):
    """
    can it be re-created from an actual json file?
    """

    json_str = nested_example.to_json()
    with open("temp.json", 'w') as tempfile:
        tempfile.write(nested_example.to_json())

    with open("temp.json") as tempfile:
        reconstructed = js.from_json(tempfile)

    reconstructed = js.from_json(json_str)

    assert reconstructed == nested_example
예제 #2
0
def test_from_json_dict2(nested_dict):
    """
    can it be re-created from an actual json string?
    """

    json_str = nested_dict.to_json()

    reconstructed = js.from_json(json_str)

    assert reconstructed == nested_dict
예제 #3
0
def load_json():
    try:
        with open('mailroom_json.json', 'r') as f:
            contents = f.read()
    except IOError:
        print("Unable to load donor database")

    if contents:
        json_donor = js.from_json(contents)
    print(json_donor)
                donor.factordonation(factor, min_donation, max_donation))
        db2.create_report()
        return db2

    def projection(self, projection_inputs):
        factor, min_donation, max_donation = projection_inputs
        db2 = self.challenge(factor, min_donation, max_donation)
        total = reduce(lambda x, y: x + y,
                       map(lambda x: x.totaldonation, db2.donors))
        print(f'\nProjection: total contribution would be ${total:.2f}!')


# initialize the database
with open('database.json', 'r') as f:
    data = f.read()
db = js.from_json(data)

# db = DataBase([Donor('Jeff', 'Bezos', [3.65, 54.50]),
#                Donor('Mark', 'Zuckerberg', [36.54, 1.25, 54.87]),
#                Donor('Paul', 'Allen', [17.38]),
#                Donor('William', 'Gates', [25.55, 33.33, 78.14])
#                ])


def menu_selection(prompt, selection_dict):
    """Return options for user to select from."""
    while True:
        try:
            userinput = input(prompt)
            if userinput == 'q':
                data = db.to_json()
예제 #5
0
to the original prompt
4. From the original prompt, the user should be able to quit the scipt cleanly
"""


import sys
import os
import datetime
from donor import Donor
from donor_dict import Donor_Dict
from json_save_meta import from_json

d_js = ""
with open('dict_init.json', 'r') as f:
    d_js = f.read()
d = from_json(d_js)
divider = "\n" + "*" * 50 + "\n"


def main_menu(user_prompt=None):
    """
    Prompt user to send a Thank You, Create a report, create letters, or quit.
    """
    valid_prompts = {"1": create_thank_u,
                     "2": create_donor_report,
                     "3": write_letters_to_all,
                     "4": simulate,
                     "5": mr_exit}
    options = list(valid_prompts.keys())
    print(divider + "We're a Pyramid Scheme & So Are You! E-Mailroom" +
          divider)
 def load(self):
     with open('mailroom.json', 'r') as file:
         mailroom_loaded = json.from_json(file.read())
     return mailroom_loaded