@@ -689,7 +689,7 @@ def _option_frames_from_url(self, url):
689689
690690 if not hasattr (self , 'underlying_price' ):
691691 try :
692- self .underlying_price , self .quote_time = self ._get_underlying_price (url )
692+ self .underlying_price , self .quote_time = self ._underlying_price_and_time_from_url (url )
693693 except IndexError :
694694 self .underlying_price , self .quote_time = np .nan , np .nan
695695
@@ -704,34 +704,38 @@ def _option_frames_from_url(self, url):
704704
705705 return {'calls' : calls , 'puts' : puts }
706706
707- def _get_underlying_price (self , url ):
707+ def _underlying_price_and_time_from_url (self , url ):
708708 root = self ._parse_url (url )
709+ underlying_price = self ._underlying_price_from_root (root )
710+ quote_time = self ._quote_time_from_root (root )
711+ return underlying_price , quote_time
712+
713+ @staticmethod
714+ def _underlying_price_from_root (root ):
709715 underlying_price = root .xpath ('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]' )[0 ]\
710716 .getchildren ()[0 ].text
711-
712- try :
713- underlying_price = float (underlying_price )
714- except ValueError :
715- # check for comma
716- underlying_price = underlying_price .replace (',' , '' )
717+ underlying_price = underlying_price .replace (',' , '' ) #GH11
717718
718719 try :
719720 underlying_price = float (underlying_price )
720721 except ValueError :
721722 underlying_price = np .nan
722723
724+ return underlying_price
725+
726+ @staticmethod
727+ def _quote_time_from_root (root ):
723728 #Gets the time of the quote, note this is actually the time of the underlying price.
724729 try :
725730 quote_time_text = root .xpath ('.//*[@class="time_rtq Fz-m"]' )[0 ].getchildren ()[1 ].getchildren ()[0 ].text
726731 ##TODO: Enable timezone matching when strptime can match EST with %Z
727732 quote_time_text = quote_time_text .split (' ' )[0 ]
728733 quote_time = dt .datetime .strptime (quote_time_text , "%I:%M%p" )
729-
730734 quote_time = quote_time .replace (year = CUR_YEAR , month = CUR_MONTH , day = CUR_DAY )
731735 except ValueError :
732736 quote_time = np .nan
733737
734- return underlying_price , quote_time
738+ return quote_time
735739
736740 def _get_option_data (self , expiry , name ):
737741 frame_name = '_frames' + self ._expiry_to_string (expiry )
0 commit comments