4
4
5
5
.. moduleauthor:: Tianning Li <[email protected] >
6
6
"""
7
- import pandas as pd
8
- from finvizfinance .util import web_scrap , number_covert
9
- from finvizfinance .group .overview import Overview
7
+ from finvizfinance .group .base import Base
10
8
11
9
12
- COLUMNS = {
13
- 0 : "No." ,
14
- 1 : "Name" ,
15
- 2 : "Market Cap." ,
16
- 3 : "P/E" ,
17
- 4 : "Forward P/E" ,
18
- 5 : "PEG" ,
19
- 6 : "P/S" ,
20
- 7 : "P/B" ,
21
- 8 : "P/Cash" ,
22
- 9 : "P/Free Cash Flow" ,
23
- 10 : "Dividend Yield" ,
24
- 11 : "EPS growth past 5 years" ,
25
- 12 : "EPS growth next 5 years" ,
26
- 13 : "Sales growth past 5 years" ,
27
- 14 : "Shares Float" ,
28
- 15 : "Performance (Week)" ,
29
- 16 : "Performance (Month)" ,
30
- 17 : "Performance (Quarter)" ,
31
- 18 : "Performance (Half Year)" ,
32
- 19 : "Performance (Year)" ,
33
- 20 : "Performance (YearToDate)" ,
34
- 21 : "Analyst Recom." ,
35
- 22 : "Average Volume" ,
36
- 23 : "Relative Volume" ,
37
- 24 : "Change" ,
38
- 25 : "Volume" ,
39
- 26 : "Number of Stocks" ,
40
- }
41
-
42
-
43
- class Custom (Overview ):
10
+ class Custom (Base ):
44
11
"""Custom inherit from overview module.
45
12
Getting information from the finviz group custom page.
46
13
"""
47
14
48
15
v_page = 152
49
16
50
- def get_columns (self ):
51
- """Get information about the columns
52
-
53
- Returns:
54
- columns(dict): return the index and column name.
55
- """
56
- return COLUMNS
57
-
58
17
def screener_view (
59
18
self , group = "Sector" , order = "Name" , columns = [0 , 1 , 2 , 3 , 10 , 22 , 24 , 25 , 26 ]
60
19
):
@@ -67,34 +26,4 @@ def screener_view(
67
26
Returns:
68
27
df(pandas.DataFrame): group information table.
69
28
"""
70
- if group not in self .group_dict :
71
- raise ValueError ()
72
- if order not in self .order_dict :
73
- raise ValueError ()
74
- self .url = (
75
- self .BASE_URL .format (group = self .group_dict [group ], v_page = self .v_page )
76
- + "&"
77
- + self .order_dict [order ]
78
- )
79
- columns = [str (i ) for i in columns ]
80
- self .url += "&c=" + "," .join (columns )
81
-
82
- soup = web_scrap (self .url )
83
- table = soup .find ("table" , class_ = "table-light" )
84
- rows = table .find_all ("tr" )
85
- table_header = [i .text .strip () for i in rows [0 ].find_all ("td" )][1 :]
86
- frame = []
87
- rows = rows [1 :]
88
- num_col_index = list (range (2 , len (table_header )))
89
- for row in rows :
90
- cols = row .find_all ("td" )[1 :]
91
- info_dict = {}
92
- for i , col in enumerate (cols ):
93
- # check if the col is number
94
- if i not in num_col_index :
95
- info_dict [table_header [i ]] = col .text
96
- else :
97
- info_dict [table_header [i ]] = number_covert (col .text )
98
-
99
- frame .append (info_dict )
100
- return pd .DataFrame (frame )
29
+ return Base .screener_view (group , order , columns )
0 commit comments