@@ -689,7 +689,7 @@ def _option_frames_from_url(self, url):
689
689
690
690
if not hasattr (self , 'underlying_price' ):
691
691
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 )
693
693
except IndexError :
694
694
self .underlying_price , self .quote_time = np .nan , np .nan
695
695
@@ -704,34 +704,38 @@ def _option_frames_from_url(self, url):
704
704
705
705
return {'calls' : calls , 'puts' : puts }
706
706
707
- def _get_underlying_price (self , url ):
707
+ def _underlying_price_and_time_from_url (self , url ):
708
708
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 ):
709
715
underlying_price = root .xpath ('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]' )[0 ]\
710
716
.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
717
718
718
719
try :
719
720
underlying_price = float (underlying_price )
720
721
except ValueError :
721
722
underlying_price = np .nan
722
723
724
+ return underlying_price
725
+
726
+ @staticmethod
727
+ def _quote_time_from_root (root ):
723
728
#Gets the time of the quote, note this is actually the time of the underlying price.
724
729
try :
725
730
quote_time_text = root .xpath ('.//*[@class="time_rtq Fz-m"]' )[0 ].getchildren ()[1 ].getchildren ()[0 ].text
726
731
##TODO: Enable timezone matching when strptime can match EST with %Z
727
732
quote_time_text = quote_time_text .split (' ' )[0 ]
728
733
quote_time = dt .datetime .strptime (quote_time_text , "%I:%M%p" )
729
-
730
734
quote_time = quote_time .replace (year = CUR_YEAR , month = CUR_MONTH , day = CUR_DAY )
731
735
except ValueError :
732
736
quote_time = np .nan
733
737
734
- return underlying_price , quote_time
738
+ return quote_time
735
739
736
740
def _get_option_data (self , expiry , name ):
737
741
frame_name = '_frames' + self ._expiry_to_string (expiry )
0 commit comments