Example #1
0
    def test_fix(self):

        dt_1 = arrow(datetime(2012, 1, 1))
        dt_2 = arrow(datetime(2012, 1, 2))

        self.assertEqual(dt_1.humanize(dt_2), 'in 1 day')
        self.assertEqual(dt_1.humanize(dt_2, fix=False), '1 day')
        self.assertEqual(dt_2.humanize(dt_1), '1 day ago')
        self.assertEqual(dt_2.humanize(dt_1, fix=False), '1 day')
Example #2
0
    def test_fix(self):

        dt_1 = arrow(datetime(2012, 1, 1))
        dt_2 = arrow(datetime(2012, 1, 2))

        self.assertEqual(dt_1.humanize(dt_2), 'in 1 day')
        self.assertEqual(dt_1.humanize(dt_2, fix=False), '1 day')
        self.assertEqual(dt_2.humanize(dt_1), '1 day ago')
        self.assertEqual(dt_2.humanize(dt_1, fix=False), '1 day')
Example #3
0
def main():
    '''
        Get list of books read in 2017. Create data visulizations. 
        Print out how many hours were spent reading this year.
    '''
    books = read_books_from_file('reading-challenge-2017_v2.csv')
    timeline(books)
    double_donut(books)
    arrow(books)
    print(hours_spent_reading(books, 350))
Example #4
0
def index():
	# to_tz = time zone numeric/name encoding
	if request.method == 'POST':
		offset = int(request.form['input_dt'][-5:])
		delta = timedelta(hours = offset / 100)
		dt_req = parser.parse(request.form['input_dt'])
		cur_time = arrow(dt_req, delta)
				
		to_tz = request.form['to_tz']
		conv_time = cur_time.to(str(to_tz))
		res = [conv_time.datetime.date(), conv_time.datetime.time(), conv_time.tz.name]

		return render_template('index.html', to_tz = to_tz, dt = str(dt_req), res=res)	 		

	return render_template('index.html', dt = str(arrow('local').datetime))
Example #5
0
    def test_one_arg_utc_datetime_now(self):

        result = arrow(datetime.utcnow())

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
        self.assertEqual(result.tz.tzinfo, tz.tzutc())
Example #6
0
    def test_one_arg_local_datetime_now(self):

        # Wrong, but confirms default handling as UTC.
        result = arrow(datetime.now())

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assertTrue(result.tz.utc)
Example #7
0
    def test_two_args_local_datetime_now_local_str(self):

        result = arrow(datetime.now(), 'local')

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assert_ts_equal(result.timestamp, time.time())
        self.assertEqual(result.tz.utcoffset, self.local.utcoffset)
Example #8
0
    def test_no_diff(self):

        dt = datetime(2011, 1, 1, 1, 1, 1)

        result = arrow(dt).humanize(dt)

        self.assertIsNone(result)
Example #9
0
    def test_one_arg_local_datetime_now(self):

        # Wrong, but confirms default handling as UTC.
        result = arrow(datetime.now())

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assertTrue(result.tz.utc)
Example #10
0
    def test_none(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt).humanize(fix=False)

        self.assertEqual(result, '1 hour')
Example #11
0
    def test_no_args(self):

        result = arrow()

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
        self.assertTrue(result.tz.utc)
Example #12
0
    def test_one_arg_utc_datetime(self):

        result = arrow(datetime.utcnow())

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
        self.assertEqual(result.tz.tzinfo, tz.tzutc())
Example #13
0
    def test_arrow(self):

        arr = Arrow(datetime.utcnow() + timedelta(hours=-1))

        result = arrow().humanize(arr, fix=False)

        self.assertEqual(result, '1 hour')
Example #14
0
    def test_no_diff(self):

        dt = datetime(2011, 1, 1, 1, 1, 1)

        result = arrow(dt).humanize(dt)

        self.assertIsNone(result)
Example #15
0
    def test_none(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt).humanize(fix=False)

        self.assertEqual(result, '1 hour')
Example #16
0
    def test_arrow(self):

        arr = Arrow(datetime.utcnow() + timedelta(hours=-1))

        result = arrow().humanize(arr, fix=False)

        self.assertEqual(result, '1 hour')
Example #17
0
    def test_two_args_local_datetime_local_str(self):

        result = arrow(datetime.now(), 'local')

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assert_ts_equal(result.timestamp, time.time())
        self.assertEqual(result.tz.utcoffset, self.local.utcoffset)
Example #18
0
    def test_no_args(self):

        result = arrow()

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
        self.assertTrue(result.tz.utc)
Example #19
0
    def test_two_args_datetime_future_timedelta(self):

        dt = datetime.utcnow() + timedelta(hours=1)

        result = arrow(dt, timedelta(hours=-1))

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() + 7200)
Example #20
0
    def test_two_args_datetime_future_timedelta(self):

        dt = datetime.utcnow() + timedelta(hours=1)

        result = arrow(dt, timedelta(hours=-1))

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() + 7200)
Example #21
0
    def test_two_args_datetime_past_iso_str(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt, '+01:00')

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() - 7200)
Example #22
0
    def test_two_args_utc_datetime_past_utc_str(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt, 'UTC')

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() - 3600)
Example #23
0
    def test_one_arg_utc_datetime_prev(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt)

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() - 3600)
Example #24
0
def start_the_fun(sf_image, sf_choice):
    finish = "Start"
    while finish == "Start":
        if finish == "Quit":
            break
        choices = ["Auto-Complete", "EXIT"]
        reply = ui.buttonbox("Click 'Auto-Complete' to list all available moves: "
                             "\n\nClick 'EXIT' to close application:", image=sf_choice, choices=choices)
        if reply == "Auto-Complete":
            oneSweetSeperation.sweet_separation(sf_image)
            sweets_located, coords = twoSweetLocation.sweet_location(sf_image)
            move_dict = threeMoveGeneration.move(sweets_located, sf_image)
            arrow.arrow(sf_image, move_dict, coords)
            os.remove("ArrowImage.png")
            exit()
        elif reply == "EXIT":
            exit()
Example #25
0
    def test_two_args_datetime_past_iso_str(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt, '+01:00')

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() - 7200)
Example #26
0
    def test_one_arg_utc_datetime_prev(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt)

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() - 3600)
Example #27
0
    def test_two_args_utc_datetime_past_utc_str(self):

        dt = datetime.utcnow() + timedelta(hours=-1)

        result = arrow(dt, 'UTC')

        self.assert_dt_equal(result.datetime, dt)
        self.assert_ts_equal(result.timestamp, time.time() - 3600)
Example #28
0
    def test_one_arg_iso_timezone(self):

        result = arrow('-01:30')

        dt_expected = datetime.utcnow().replace(tzinfo=tz.tzutc()).astimezone(
            tz.tzoffset(None, -5400))

        self.assert_dt_equal(result.datetime, dt_expected)
        self.assert_ts_equal(result.timestamp, time.time())
Example #29
0
    def test_one_arg_named_timezone(self):

        result = arrow('US/Pacific')

        dt_expected = datetime.utcnow().replace(tzinfo=tz.tzutc()).astimezone(
            tz.gettz('US/Pacific'))

        self.assert_dt_equal(result.datetime, dt_expected)
        self.assert_ts_equal(result.timestamp, time.time())
Example #30
0
    def test_one_arg_iso_timezone(self):

        result = arrow('-01:30')

        dt_expected = datetime.utcnow().replace(tzinfo=tz.tzutc()).astimezone(
            tz.tzoffset(None, -5400))

        self.assert_dt_equal(result.datetime, dt_expected)
        self.assert_ts_equal(result.timestamp, time.time())
Example #31
0
    def test_one_arg_named_timezone(self):

        result = arrow('US/Pacific')

        dt_expected = datetime.utcnow().replace(tzinfo=tz.tzutc()).astimezone(
            tz.gettz('US/Pacific'))

        self.assert_dt_equal(result.datetime, dt_expected)
        self.assert_ts_equal(result.timestamp, time.time())
Example #32
0
    def test_humanize(self):

        dt_1 = datetime(2012, 2, 2, 2, 2, 2)
        dt_2 = datetime(2010, 12, 25, 1, 1, 1)

        result = arrow(dt_1).humanize(dt_2, places=7)
        self.assertEqual(
            result,
            '1 year, 1 month, 1 week, 1 day, 1 hour, 1 minute and 1 second ago'
        )

        result = arrow(dt_1).humanize(dt_2, places=6)
        self.assertEqual(
            result, '1 year, 1 month, 1 week, 1 day, 1 hour and 1 minute ago')

        result = arrow(dt_1).humanize(dt_2, places=1)
        self.assertEqual(result, '1 year ago')

        result = arrow(dt_1).humanize(dt_2, places=2)
        self.assertEqual(result, '1 year and 1 month ago')

        result = arrow(dt_1).humanize(dt_2, places=3)
        self.assertEqual(result, '1 year, 1 month and 1 week ago')

        dt_1 = datetime(2010, 12, 25, 1, 1, 1)
        dt_2 = datetime(2012, 2, 2, 2, 2, 2)

        result = arrow(dt_1).humanize(dt_2, places=7)
        self.assertEqual(
            result,
            'in 1 year, 1 month, 1 week, 1 day, 1 hour, 1 minute and 1 second')

        result = arrow(dt_1).humanize(dt_2, places=6)
        self.assertEqual(
            result, 'in 1 year, 1 month, 1 week, 1 day, 1 hour and 1 minute')

        result = arrow(dt_1).humanize(dt_2, places=1)
        self.assertEqual(result, 'in 1 year')

        result = arrow(dt_1).humanize(dt_2, places=2)
        self.assertEqual(result, 'in 1 year and 1 month')

        result = arrow(dt_1).humanize(dt_2, places=3)
        self.assertEqual(result, 'in 1 year, 1 month and 1 week')
Example #33
0
    def test_humanize(self):

        dt_1 = datetime(2012, 2, 2, 2, 2, 2)
        dt_2 = datetime(2010, 12, 25, 1, 1, 1)

        result = arrow(dt_1).humanize(dt_2, places=7)
        self.assertEqual(result, '1 year, 1 month, 1 week, 1 day, 1 hour, 1 minute and 1 second ago')

        result = arrow(dt_1).humanize(dt_2, places=6)
        self.assertEqual(result, '1 year, 1 month, 1 week, 1 day, 1 hour and 1 minute ago')

        result = arrow(dt_1).humanize(dt_2, places=1)
        self.assertEqual(result, '1 year ago')

        result = arrow(dt_1).humanize(dt_2, places=2)
        self.assertEqual(result, '1 year and 1 month ago')

        result = arrow(dt_1).humanize(dt_2, places=3)
        self.assertEqual(result, '1 year, 1 month and 1 week ago')

        dt_1 = datetime(2010, 12, 25, 1, 1, 1)
        dt_2 = datetime(2012, 2, 2, 2, 2, 2)

        result = arrow(dt_1).humanize(dt_2, places=7)
        self.assertEqual(result, 'in 1 year, 1 month, 1 week, 1 day, 1 hour, 1 minute and 1 second')

        result = arrow(dt_1).humanize(dt_2, places=6)
        self.assertEqual(result, 'in 1 year, 1 month, 1 week, 1 day, 1 hour and 1 minute')

        result = arrow(dt_1).humanize(dt_2, places=1)
        self.assertEqual(result, 'in 1 year')

        result = arrow(dt_1).humanize(dt_2, places=2)
        self.assertEqual(result, 'in 1 year and 1 month')

        result = arrow(dt_1).humanize(dt_2, places=3)
        self.assertEqual(result, 'in 1 year, 1 month and 1 week')
Example #34
0
 def attack(self, enemies):
     f = None
     for balloon in enemies:
         br, bc = balloon.row, balloon.col
         bx, by, bx1, by1 = getCellBounds(br, bc)
         bcx, bcy = (bx + bx1) / 2, (by + by1) / 2
         tx = self.position[0]
         ty = self.position[1]
         if distance(bcx, bcy, tx, ty) < self.range:
             if f == None:
                 f = balloon
             elif balloon.pos < f.pos:
                 f = balloon
     #sometimes f is still none
     if f != None:
         row, col = f.row, f.col
         bx, by, bx1, by1 = getCellBounds(row, col)
         cx, cy = (bx + bx1) / 2, (by + by1) / 2
         dx, dy = cx - self.position[0], cy - self.position[1]
         #normalize dx, dy
         s = normalize(dx, dy)
         ddx, ddy = dx / s, dy / s
         return [arrow.arrow(self.position, ddx, ddy)]
     return []
Example #35
0
 def __init__(self, grid):
     print("Grid Object Generated.....")
     self.grid = grid
     self.Width = (width - 100) // len(self.grid)
     self.Height = (height - 100) // len(self.grid[0])
     self.arrow = arrow(self.Width, self.Height)
Example #36
0
    def test_two_args_utc_datetime_now_utc_str(self):

        result = arrow(datetime.utcnow(), 'UTC')

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
Example #37
0
    def get_molecules(self, file_name):
        doc = dom.parse(file_name)
        molecules = []
        # read colors
        colors = []
        for elem7 in doc.getElementsByTagName("color"):
            red = (float(elem7.getAttribute("r")) * 255)
            green = (float(elem7.getAttribute("g")) * 255)
            blue = (float(elem7.getAttribute("b")) * 255)
            colors.append("#%02x%02x%02x" % (red, green, blue))

        # read fonts
        fonts = {}
        for elem8 in doc.getElementsByTagName("font"):
            family = str(elem8.getAttribute("name"))
            fonts[int(elem8.getAttribute("id"))] = family

        # read molecules
        for elem1 in doc.getElementsByTagName("fragment"):
            if elem1.parentNode.nodeName == "page":
                mol = molecule(paper=self.paper)
                atom_id_to_atom = {}
                atom_id_to_text = {}
                for elem2 in elem1.childNodes:

                    # atom
                    if elem2.nodeName == "n":
                        font = ""
                        Size = 12
                        text = "C"
                        color1 = "#000000"
                        for elem3 in elem2.childNodes:
                            if elem3.nodeName == "t":
                                if elem3.hasAttribute("color"):
                                    color1 = colors[
                                        int(elem3.getAttribute("color")) - 2]
                                text = ""
                                for elem4 in elem3.childNodes:
                                    if elem4.nodeName == "s":
                                        if elem3.hasAttribute("color"):
                                            color1 = colors[int(
                                                elem3.getAttribute("color")) -
                                                            2]
                                        for Id, Font in fonts.items():
                                            if Id == int(
                                                    elem4.getAttribute(
                                                        "font")):
                                                font = Font
                                        Size = int(elem4.getAttribute("size"))
                                        text += dom_ext.getAllTextFromElement(
                                            elem4).strip()

                        position = elem2.getAttribute("p").split()
                        assert len(position) == 2

                        # we must postpone symbol assignment until we know the valency of the atoms
                        atom_id_to_text[elem2.getAttribute('id')] = text
                        atom = mol.create_vertex()
                        atom.line_color = color1
                        atom.font_family = font
                        atom.font_size = Size
                        atom.x = float(position[0])
                        atom.y = float(position[1])
                        mol.add_vertex(atom)
                        atom_id_to_atom[elem2.getAttribute('id')] = atom

                    # bond
                    #{"v BKChemu bond.type":"v ChemDraw hodnota atributu Display elementu b"}
                    bondType2 = {
                        "WedgeBegin": "w",
                        "WedgedHashBegin": "h",
                        "Wavy": "a",
                        "Bold": "b",
                        "Dash": "d"
                    }

                    if elem2.nodeName == "b":
                        if elem2.hasAttribute("color"):
                            color2 = colors[(int(elem2.getAttribute("color")) -
                                             2)]
                        else:
                            color2 = "#000000"
                        order = 1
                        if elem2.hasAttribute("Order"):
                            order = int(elem2.getAttribute("Order"))
                        bond = mol.create_edge()
                        if elem2.hasAttribute("Display"):
                            display = elem2.getAttribute("Display").strip()
                            for bondC, bondB in bondType2.items():
                                if bondC == display:
                                    bond.type = bondB
                        bond.line_color = color2
                        bond.order = order
                        atom1 = atom_id_to_atom[elem2.getAttribute("B")]
                        atom2 = atom_id_to_atom[elem2.getAttribute("E")]
                        mol.add_edge(atom1, atom2, bond)

                # here we reassign the symbols
                for id, atom in atom_id_to_atom.items():
                    text = atom_id_to_text[id]
                    v = mol.create_vertex_according_to_text(atom, text)
                    atom.copy_settings(v)
                    mol.replace_vertices(atom, v)
                    atom.delete()
                # finally we add the molecule to the list of molecules for output
                molecules.append(mol)

        # read texts
        textik = {2: "i", 1: "b", 32: "sub", 64: "sup"}

        for elem5 in doc.getElementsByTagName("t"):
            if elem5.parentNode.nodeName == "page":
                position = map(float, elem5.getAttribute("p").split())
                assert len(position) == 2
                celyText = ""
                for elem51 in elem5.childNodes:
                    if elem51.nodeName == "s":
                        for elem52 in elem51.childNodes:
                            if isinstance(elem52, dom.Text):
                                rodice = []
                                text100 = elem52.data
                                if elem51.hasAttribute("face"):
                                    Face01 = int(elem51.getAttribute("face"))
                                    for face, parent in textik.items():
                                        for i in range(9):
                                            if not Face01 & 2**i == 0:
                                                if face == Face01 & 2**i:
                                                    rodice.append(parent)
                                for rodic in rodice:
                                    text100 = "<%s>%s</%s>" % (rodic, text100,
                                                               rodic)
                        celyText += text100

                        if elem5.hasAttribute("color"):
                            color3 = colors[(int(elem5.getAttribute("color")) -
                                             2)]
                        else:
                            color3 = "#000000"

                        font_id = elem51.getAttribute("font")
                        if font_id != "":
                            font = fonts[int(font_id)]
                        #text = dom_ext.getAllTextFromElement(elem51)
                #print celyText
                text = celyText
                t = text_class(self.paper, position, text=text)
                t.line_color = color3
                #print elem51
                if elem51.hasAttribute("size"):
                    t.font_size = int(elem51.getAttribute("size"))
                if font:
                    t.font_family = font
                molecules.append(t)

        # read graphics - plus
        for elem6 in doc.getElementsByTagName("graphic"):
            if elem6.getAttribute(
                    "GraphicType") == "Symbol" and elem6.getAttribute(
                        "SymbolType") == "Plus":
                position = map(float,
                               elem6.getAttribute("BoundingBox").split())
                position2 = [position[0], position[1]]
                assert len(position2) == 2
                if elem6.hasAttribute("color"):
                    color4 = colors[(int(elem6.getAttribute("color")) - 2)]
                else:
                    color4 = "#000000"
                pl = plus(self.paper, position2)
                pl.line_color = color4
                molecules.append(pl)

        sipka = []
        #for elem71 in doc.getElementsByTagName("graphic"):
        #if elem71.getAttribute("GraphicType")=="Line":

        for elem7 in doc.getElementsByTagName("arrow"):
            sipka.insert(0, elem7.getAttribute('Head3D'))
            sipka.insert(1, elem7.getAttribute('Tail3D'))
            if elem7.hasAttribute("color"):
                sipka.insert(0, colors[(int(elem7.getAttribute("color")) - 2)])
            point1 = map(float, sipka[1].split())
            point2 = map(float, sipka[2].split())
            arr = arrow(self.paper,
                        points=[point2[0:2], point1[0:2]],
                        fill=sipka[0])
            arr.line_color = sipka[0]
            molecules.append(arr)

        sipka = []
        return molecules
Example #38
0
    def test_tz_kwarg_local(self):

        result = arrow(tz='local')

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assert_ts_equal(result.timestamp, time.time())
Example #39
0
    def test_one_arg_local_timezone(self):

        result = arrow('local')

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assert_ts_equal(result.timestamp, time.time())
Example #40
0
    def test_one_arg_float_timestamp(self):

        result = arrow(time.time())

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
Example #41
0
    xmlparse.filename = '06-08 22-05.xml'
    pixel_location = location.xy_location(xmlparse.location_data()[road_num])
    direction = xmlparse.road_direction()[road_num]
    arrow_colors = xmlparse.road_status()[road_num]
    if arrow_colors == 3:  # 3 means block
        RGB = (255, 0, 0)  # red
    elif arrow_colors == 2:  # 2 means slow
        RGB = (255, 165, 0)  # orange
    else:
        RGB = (0, 255, 0)
    size = 15
    if arrow_colors == 3:
        size = 25
    elif arrow_colors == 2:
        size = 20
    arrow_location = arrow.arrow(
        pixel_location, size, direction)  # input the location of pixel (x,y)
    map_draw.point(arrow_location,
                   RGB)  # choice RGB,the initial picture is not the RGB.
del map_draw  # the example  of ImageDraw document have this 'del' step, but not know why.
open_image.save('map/map.png', 'png')  # save

#depend on my data , I run it to make a lots of images.
'''
hours = 13
minites = '05'
imagename = 1   
while True:
    open_image = Image.open('map1.png')              # open 
    map_draw = ImageDraw.Draw(open_image)            # make object
    for road_num in range(120):
        xmlparse.filename = '06-08 %d-%s.xml' % (hours, minites)
Example #42
0
    def test_one_arg_local_datetime(self):

        result = arrow(datetime.now())

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assertTrue(result.tz.utc)
Example #43
0
    def test_two_args_utc_datetime_utc_str(self):

        result = arrow(datetime.utcnow(), 'UTC')

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
Example #44
0
    def test_one_arg_float_timestamp(self):

        result = arrow(time.time())

        self.assert_dt_equal(result.datetime, datetime.utcnow())
        self.assert_ts_equal(result.timestamp, time.time())
Example #45
0
    def test_one_arg_local_datetime(self):

        result = arrow(datetime.now())

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assertTrue(result.tz.utc)
Example #46
0
  def get_molecules( self, file_name):
    doc = dom.parse( file_name)
    molecules = []
    # read colors
    colors=[]
    for elem7 in doc.getElementsByTagName("color"):
      red=(float(elem7.getAttribute("r"))*255)
      green=(float(elem7.getAttribute("g"))*255)
      blue=(float(elem7.getAttribute("b"))*255)
      colors.append("#%02x%02x%02x" % (red,green,blue))

    # read fonts
    fonts={}
    for elem8 in doc.getElementsByTagName("font"):
      family=str(elem8.getAttribute("name"))
      fonts[int(elem8.getAttribute("id"))]=family

    # read molecules
    for elem1 in doc.getElementsByTagName("fragment"):
      if elem1.parentNode.nodeName=="page":
        mol = molecule( paper=self.paper)
        atom_id_to_atom = {}
        atom_id_to_text = {}
        for elem2 in elem1.childNodes:

          # atom
          if elem2.nodeName=="n":
            font = ""
            Size = 12
            text = "C"
            color1="#000000"
            for elem3 in elem2.childNodes:
              if elem3.nodeName=="t":
                if elem3.hasAttribute("color"):
                  color1=colors[int(elem3.getAttribute("color"))-2]
                text = ""
                for elem4 in elem3.childNodes:
                  if elem4.nodeName=="s":
                    if elem3.hasAttribute("color"):
                      color1=colors[int(elem3.getAttribute("color"))-2]
                    for Id, Font in fonts.items():
                      if Id==int(elem4.getAttribute("font")):
                        font=Font
                    Size= int(elem4.getAttribute("size"))
                    text += dom_ext.getAllTextFromElement( elem4).strip()

            position = elem2.getAttribute("p").split()
            assert len( position) == 2


            # we must postpone symbol assignment until we know the valency of the atoms
            atom_id_to_text[ elem2.getAttribute('id')] = text
            atom = mol.create_vertex()
            atom.line_color = color1
            atom.font_family = font
            atom.font_size = Size
            atom.x = float( position[0])
            atom.y = float( position[1])
            mol.add_vertex( atom)
            atom_id_to_atom[ elem2.getAttribute('id')] = atom

          # bond
          #{"v BKChemu bond.type":"v ChemDraw hodnota atributu Display elementu b"}
          bondType2={"WedgeBegin":"w",
          "WedgedHashBegin":"h",
          "Wavy":"a",
          "Bold":"b",
          "Dash":"d"
          }

          if elem2.nodeName=="b":
            if elem2.hasAttribute("color"):
              color2 = colors[(int(elem2.getAttribute("color"))-2)]
            else:
              color2="#000000"
            order = 1
            if elem2.hasAttribute("Order"):
              order = int( elem2.getAttribute("Order"))
            bond = mol.create_edge()
            if elem2.hasAttribute("Display"):
              display = elem2.getAttribute("Display").strip()
              for bondC, bondB in bondType2.items():
                if bondC ==display:
                  bond.type = bondB
            bond.line_color = color2
            bond.order = order
            atom1 = atom_id_to_atom[ elem2.getAttribute("B")]
            atom2 = atom_id_to_atom[ elem2.getAttribute("E")]
            mol.add_edge( atom1, atom2, bond)

        # here we reassign the symbols
        for id, atom in atom_id_to_atom.items():
          text = atom_id_to_text[ id]
          v = mol.create_vertex_according_to_text( atom, text)
          atom.copy_settings( v)
          mol.replace_vertices( atom, v)
          atom.delete()
        # finally we add the molecule to the list of molecules for output
        molecules.append( mol)

    # read texts
    textik={2:"i",
            1:"b",
            32:"sub",
            64:"sup"}

    for elem5 in doc.getElementsByTagName("t"):
      if elem5.parentNode.nodeName=="page":
        position = map( float, elem5.getAttribute("p").split())
        assert len( position) == 2
        celyText=""
        for elem51 in elem5.childNodes:
          if elem51.nodeName=="s":
            for elem52 in elem51.childNodes:
              if isinstance( elem52, dom.Text):
                rodice=[]
                text100=elem52.data
                if elem51.hasAttribute("face"):
                  Face01=int(elem51.getAttribute("face"))
                  for face, parent in textik.items():
                    for i in range(9):
                      if not Face01&2**i==0:
                        if face==Face01&2**i:
                          rodice.append(parent)
                for rodic in rodice:
                  text100 = "<%s>%s</%s>" % (rodic,text100,rodic)
            celyText += text100

            if elem5.hasAttribute("color"):
              color3=colors[(int(elem5.getAttribute("color"))-2)]
            else:
              color3="#000000"

            font_id = elem51.getAttribute("font")
            if font_id != "":
              font=fonts[int(font_id)]
            #text = dom_ext.getAllTextFromElement(elem51)
        #print celyText
        text = celyText
        t = text_class( self.paper, position, text=text)
        t.line_color = color3
        #print elem51
        if elem51.hasAttribute("size"):
          t.font_size = int( elem51.getAttribute("size"))
        if font:
          t.font_family = font
        molecules.append(t)

    # read graphics - plus
    for elem6 in doc.getElementsByTagName("graphic"):
      if elem6.getAttribute("GraphicType")=="Symbol" and elem6.getAttribute("SymbolType")=="Plus":
        position = map( float, elem6.getAttribute("BoundingBox").split())
        position2=[position[0],position[1]]
        assert len(position2) == 2
        if elem6.hasAttribute("color"):
          color4=colors[(int(elem6.getAttribute("color"))-2)]
        else:
          color4="#000000"
        pl = plus(self.paper, position2)
        pl.line_color = color4
        molecules.append(pl)

    sipka=[]
    #for elem71 in doc.getElementsByTagName("graphic"):
      #if elem71.getAttribute("GraphicType")=="Line":

    for elem7 in doc.getElementsByTagName("arrow"):
      sipka.insert(0,elem7.getAttribute('Head3D') )
      sipka.insert(1,elem7.getAttribute('Tail3D') )
      if elem7.hasAttribute("color"):
        sipka.insert(0,colors[(int(elem7.getAttribute("color"))-2)])
      point1 = map( float, sipka[1].split())
      point2 = map( float, sipka[2].split())
      arr = arrow( self.paper, points=[point2[0:2],point1[0:2]], fill=sipka[0])
      arr.line_color=sipka[0]
      molecules.append( arr)

    sipka=[]
    return molecules
Example #47
0
    def test_tz_kwarg_local(self):

        result = arrow(tz='local')

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assert_ts_equal(result.timestamp, time.time())
Example #48
0
    def test_one_arg_local_timezone(self):

        result = arrow('local')

        self.assert_dt_equal(result.datetime, datetime.now())
        self.assert_ts_equal(result.timestamp, time.time())