Beispiel #1
0
    def test_get_dates(self):
        DBHandler.store_bread(Bread(year=0, month=2, day=1))
        DBHandler.store_bread(Bread(year=0, month=4, day=2))
        DBHandler.store_bread(Bread(year=0, month=6, day=3))

        list_dates = DBHandler.get_dates()

        self.assertIn((0, 2, 1), list_dates)
        self.assertIn((0, 4, 2), list_dates)
        self.assertIn((0, 6, 3), list_dates)

        DBHandler.delete_bread(0, 2, 1)
        DBHandler.delete_bread(0, 4, 2)
        DBHandler.delete_bread(0, 6, 3)
    def get_bread(year, month, day):
        # ------------------------------------
        # get the newest post from the first page of dblist

        html_dblist = Downloader.get_html(
            'http://bs.ubf.kr/dailybread/dblist.php?start=0')

        parser_dblist = Parser_dblist()
        parser_dblist.feed(html_dblist)

        year_newest, month_newest, day_newest = map(
            int, parser_dblist.data_dblist[1].split('.'))

        # ------------------------------------
        # find the index of today's bread in dblist

        index = Timetools.get_diffdays(year, month, day, year_newest,
                                       month_newest, day_newest)

        if index < 0:
            raise InvalidDateError

        # ------------------------------------
        # get the id of the page

        html_idinfo = Downloader.get_html(
            'http://bs.ubf.kr/dailybread/dblist.php?start=%d' % index)

        parser_idinfo = Parser_idinfo()
        parser_idinfo.feed(html_idinfo)

        if parser_idinfo.data_idinfo:
            id_ = parser_idinfo.data_idinfo[0]
        else:
            raise InvalidDateError

        # ------------------------------------
        # get the bread from the page

        html_bread = Downloader.get_html(
            'http://bs.ubf.kr/dailybread/dbdisp.php?id=%d' % id_)

        parser_bread = Parser_bread()
        parser_bread.feed(html_bread)

        bread = Bread(
            year=int(parser_bread.data_text_1[0]),
            month=int(parser_bread.data_text_2[0].split('/')[0]),
            day=int(parser_bread.data_text_2[0].split('/')[1]),
            book=parser_bread.data_title[0].split(':')[0].split()[0],
            chapter=int(parser_bread.data_title[0].split(':')[0].split()[1]),
            index_start=int(parser_bread.data_body_1[0]),
            index_end=int(parser_bread.data_body_1[-2]),
            title=parser_bread.data_title[1].strip(),
            verses=[s.strip() for s in parser_bread.data_body_1[1::2]],
            comments=[s.strip() for s in parser_bread.data_body_2[:-2]],
            application=parser_bread.data_body_2[-2].strip(),
            oneword=parser_bread.data_body_2[-1].strip())

        return bread
class TestBread(TestCase):
    def setUp(self):
        self.bread = Bread()

    def test_dict(self):
        table = self.bread.to_dict()
        bread_converted = Bread(**table)
        self.assertEqual(self.bread.to_str(), bread_converted.to_str())

    def test_json(self):
        data = self.bread.to_json()
        bread_converted = Bread(**json.loads(data))
        self.assertEqual(self.bread.to_str(), bread_converted.to_str())

    def tearDown(self):
        pass
Beispiel #4
0
    def __init__(self, root=None):
        self.root = root
        self.style = Data.style['editor']
        self.image_icon = tk.PhotoImage(data=Data.icon)
        self.image_logo = tk.PhotoImage(data=Data.logo)

        super(Editor, self).__init__(self.root)

        self.root.wm_title(u'DailyBread')
        self.root.protocol('WM_DELETE_WINDOW', self.callback_quit)

        self.init_menus()
        self.init_frames()
        self.init_widgets()
        self.init_styles()
        self.init_binds()

        self.bread = Bread()
        self.thoughts_prev = self.bread.thoughts
    def lookup_bread(year, month, day):
        value_date = '%04d.%02d.%02d' % (year, month, day)

        try:
            with conn:
                items = list(
                    conn.execute('SELECT * FROM storage WHERE date=?',
                                 (value_date, )))
        except sqlite3.Error:
            raise DBLookupError

        if not items:
            raise DBLookupError

        try:
            data = json.loads(items[0][1])
        except ValueError:
            raise DBLookupError

        return Bread(**data)
Beispiel #6
0
 def setUp(self):
     self.bread = Bread(year=0, month=3, day=1)
 def setUp(self):
     self.bread = Bread()
 def test_json(self):
     data = self.bread.to_json()
     bread_converted = Bread(**json.loads(data))
     self.assertEqual(self.bread.to_str(), bread_converted.to_str())
 def test_dict(self):
     table = self.bread.to_dict()
     bread_converted = Bread(**table)
     self.assertEqual(self.bread.to_str(), bread_converted.to_str())