sarim commited on
Commit
a50e78e
·
1 Parent(s): b6d1e78

add indexs detail

Browse files
Files changed (2) hide show
  1. app.py +9 -1
  2. index_data.py +293 -0
app.py CHANGED
@@ -1,9 +1,10 @@
1
- from fastapi import FastAPI
2
  from bs4 import BeautifulSoup
3
  import time
4
  import requests
5
  from fastapi.responses import HTMLResponse
6
  from starlette.responses import FileResponse
 
7
 
8
  app = FastAPI(
9
  title="PSX web scraper",
@@ -88,5 +89,12 @@ def get_portfolio():
88
 
89
 
90
 
 
 
 
91
 
 
 
 
 
92
 
 
1
+ from fastapi import FastAPI,HTTPException
2
  from bs4 import BeautifulSoup
3
  import time
4
  import requests
5
  from fastapi.responses import HTMLResponse
6
  from starlette.responses import FileResponse
7
+ from index_data import IndexEnum,INDEX_MAP
8
 
9
  app = FastAPI(
10
  title="PSX web scraper",
 
89
 
90
 
91
 
92
+ @app.get("/index/{index_name}")
93
+ def get_index_companies(index_name: IndexEnum):
94
+ companies = INDEX_MAP.get(index_name)
95
 
96
+ if companies is None:
97
+ raise HTTPException(status_code=404, detail="Index not found")
98
+
99
+ return [company.to_dict() for company in companies]
100
 
index_data.py ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from enum import Enum
2
+
3
+ class Company:
4
+ def __init__(self, name, sector,symbol):
5
+ self.name = name
6
+ self.sector = sector
7
+ self.symbol = symbol
8
+
9
+ def __repr__(self):
10
+ return (
11
+ f"Company(name='{self.name}', "
12
+ f"sector='{self.sector}', "
13
+ f"symbol='{self.symbol}')"
14
+ )
15
+ def to_dict(self):
16
+ return {
17
+ "name": self.name,
18
+ "sector": self.sector,
19
+ "symbol": self.symbol,
20
+ }
21
+
22
+ class IndexEnum(str, Enum):
23
+ kse_100 = "kse_100"
24
+ kse_30 = "kse_30"
25
+ psx_div_20 = "psx_div_20"
26
+ mii_30 = "mii_30"
27
+ kmi_30 = "kmi_30"
28
+
29
+
30
+
31
+ ## KSE 100
32
+ kse_100 = [
33
+ Company("HBL Growth Fund", "Close-End Mutual Funds", "HGFA"),
34
+ Company("First Habib Modaraba", "Modaraba", "FHAM"),
35
+ Company("Pak-Gulf Leasing Company", "Leasing Companies", "PGLC"),
36
+ Company("Engro Holdings Ltd.", "Investment / Holding Companies", "ENGROH"),
37
+ Company("DH Partners Ltd.", "Investment / Holding Companies", ""),
38
+ Company("Pakistan Stock Exchange Ltd.", "Investment / Holding Companies", "PSX"),
39
+
40
+ Company("United Bank Ltd.", "Commercial Banks", "UBL"),
41
+ Company("Bank AL Habib Ltd.", "Commercial Banks", "BAHL"),
42
+ Company("Bank Alfalah Ltd.", "Commercial Banks", "BAFL"),
43
+ Company("The Bank of Punjab", "Commercial Banks", "BOP"),
44
+ Company("Faysal Bank Ltd.", "Commercial Banks", "FABL"),
45
+ Company("Meezan Bank Ltd.", "Commercial Banks", "MEBL"),
46
+ Company("Habib Bank Ltd.", "Commercial Banks", "HBL"),
47
+ Company("Habib Metropolitan Bank Ltd.", "Commercial Banks", "HMB"),
48
+ Company("MCB Bank Ltd.", "Commercial Banks", "MCB"),
49
+ Company("National Bank of Pakistan", "Commercial Banks", "NBP"),
50
+ Company("Standard Chartered Bank (Pak) Ltd.", "Commercial Banks", "SCBPL"),
51
+ Company("Askari Bank Ltd.", "Commercial Banks", "AKBL"),
52
+ Company("Allied Bank Ltd.", "Commercial Banks", "ABL"),
53
+
54
+ Company("Adamjee Insurance Co. Ltd.", "Insurance", "AICL"),
55
+ Company("TPL REIT Fund I", "REIT", "TPLRF1"),
56
+ Company("Dolmen City REIT", "REIT", "DCR"),
57
+
58
+ Company("Gadoon Textile Mills Ltd.", "Textile Spinning", "GADT"),
59
+ Company("Yousaf Weaving Mills Ltd.", "Textile Weaving", "YOWL"),
60
+ Company("Nishat Mills Ltd.", "Textile Composite", "NML"),
61
+ Company("Mehmood Textile Mills Ltd.", "Textile Composite", "MTL"),
62
+ Company("Kohinoor Textile Mills Ltd.", "Textile Composite", "KTML"),
63
+ Company("Interloop Ltd.", "Textile Composite", "ILP"),
64
+ Company("Bannu Woollen Mills Ltd.", "Woollen", "BWHL"),
65
+ Company("Ibrahim Fibres Ltd.", "Synthetics & Rayon", "IBFL"),
66
+ Company("JDW Sugar Mills Ltd.", "Sugar & Allied", "JDWS"),
67
+
68
+ Company("Lucky Cement Ltd.", "Cement", "LUCK"),
69
+ Company("D. G. Khan Cement Co. Ltd.", "Cement", "DGKC"),
70
+ Company("Bestway Cement Ltd.", "Cement", "BWCL"),
71
+ Company("Fauji Cement Company Ltd.", "Cement", "FCCL"),
72
+ Company("Kohat Cement Company Ltd.", "Cement", "KOHC"),
73
+ Company("Cherat Cement Company Ltd.", "Cement", "CHCC"),
74
+ Company("Maple Leaf Cement Factory Ltd.", "Cement", "MLCF"),
75
+ Company("Pioneer Cement Ltd.", "Cement", "PIOC"),
76
+
77
+ Company("Pakistan Tobacco Company Ltd.", "Tobacco", "PTC"),
78
+ Company("Attock Refinery Ltd.", "Refinery", "ATRL"),
79
+ Company("Cnergyico PK Ltd.", "Refinery", "CNERGY"),
80
+
81
+ Company("The Hub Power Company Ltd.", "Power Generation & Distribution", "HUBC"),
82
+ Company("Kot Addu Power Company Ltd.", "Power Generation & Distribution", "KAPCO"),
83
+ Company("K-Electric Ltd.", "Power Generation & Distribution", "KEL"),
84
+ Company("Pakgen Power Ltd.", "Power Generation & Distribution", "PKGP"),
85
+
86
+ Company("Pakistan State Oil Company Ltd.", "Oil & Gas Marketing", "PSO"),
87
+ Company("Attock Petroleum Ltd.", "Oil & Gas Marketing", "APL"),
88
+ Company("Sui Northern Gas Pipelines Ltd.", "Oil & Gas Marketing", "SNGP"),
89
+ Company("Sui Southern Gas Company Ltd.", "Oil & Gas Marketing", "SSGC"),
90
+
91
+ Company("Oil & Gas Development Co. Ltd.", "Oil & Gas Exploration", "OGDC"),
92
+ Company("Mari Petroleum Company Ltd.", "Oil & Gas Exploration", "MARI"),
93
+ Company("Pakistan Oilfields Ltd.", "Oil & Gas Exploration", "POL"),
94
+ Company("Pakistan Petroleum Ltd.", "Oil & Gas Exploration", "PPL"),
95
+
96
+ Company("International Steels Ltd.", "Engineering", "ISL"),
97
+ Company("International Industries Ltd.", "Engineering", "INIL"),
98
+
99
+ Company("Millat Tractors Ltd.", "Automobile Assembler", "MTL"),
100
+ Company("Indus Motor Company Ltd.", "Automobile Assembler", "INDU"),
101
+ Company("Sazgar Engineering Works Ltd.", "Automobile Assembler", "SAZEW"),
102
+ Company("Atlas Honda Ltd.", "Automobile Assembler", "ATLH"),
103
+ Company("Honda Atlas Cars (Pakistan) Ltd.", "Automobile Assembler", "HCAR"),
104
+ Company("Ghandhara Automobiles Ltd.", "Automobile Assembler", "GHAND"),
105
+ Company("Ghandhara Industries Ltd.", "Automobile Assembler", "GHNI"),
106
+
107
+ Company("Thal Ltd.", "Automobile Parts & Accessories", "THALL"),
108
+ Company("Pak Elektron Ltd.", "Cables & Electrical Goods", "PAEL"),
109
+ Company("Pakistan International Bulk Term. Ltd.", "Transport", "PIBTL"),
110
+
111
+ Company("Systems Ltd.", "Technology & Communication", "SYS"),
112
+ Company("Air Link Communication Ltd.", "Technology & Communication", "AIRLINK"),
113
+ Company("Pakistan Telecommunication Company Ltd.", "Technology & Communication", "PTC"),
114
+ Company("TRG Pakistan Ltd.", "Technology & Communication", "TRG"),
115
+ Company("Hum Network Ltd.", "Technology & Communication", "HUMNL"),
116
+
117
+ Company("Fauji Fertilizer Company Ltd.", "Fertilizer", "FFC"),
118
+ Company("Engro Fertilizers Ltd.", "Fertilizer", "EFERT"),
119
+ Company("Fatima Fertilizer Company Ltd.", "Fertilizer", "FATIMA"),
120
+
121
+ Company("GlaxoSmithKline Pakistan Ltd.", "Pharmaceutical", "GLAXO"),
122
+ Company("AGP Ltd.", "Pharmaceutical", "AGP"),
123
+ Company("The Searle Company Ltd.", "Pharmaceutical", "SEARL"),
124
+ Company("Abbott Laboratories (Pak.) Ltd.", "Pharmaceutical", "ABOT"),
125
+ Company("Citi Pharma Ltd.", "Pharmaceutical", "CIPHL"),
126
+ Company("Haleon Pakistan", "Pharmaceutical", "HALEON"),
127
+ Company("Highnoon Laboratories", "Pharmaceutical", "HINOON"),
128
+
129
+ Company("Lucky Core Industries Ltd.", "Chemical", "LCI"),
130
+ Company("Lotte Chemical Pakistan Ltd.", "Chemical", "LOTCHEM"),
131
+
132
+ Company("Packages Ltd.", "Paper, Board & Packaging", "PKGS"),
133
+ Company("S.S. Oil Mills Ltd.", "Vanaspati & Allied", "SSOM"),
134
+ Company("Service Industries Ltd.", "Leather & Tanneries", "SRVI"),
135
+
136
+ Company("Colgate-Palmolive (Pakistan) Ltd.", "Food & Personal Care", "COLG"),
137
+ Company("Fauji Foods Ltd.", "Food & Personal Care", "FFL"),
138
+ Company("Murree Brewery Company Ltd.", "Food & Personal Care", "MUREB"),
139
+ Company("Nestle Pakistan Ltd.", "Food & Personal Care", "NESTLE"),
140
+ Company("National Foods Ltd.", "Food & Personal Care", "NATF"),
141
+ Company("Rafhan Maize Products Co. Ltd.", "Food & Personal Care", "RMPL"),
142
+ Company("Unilever Pakistan Food Ltd.", "Food & Personal Care", "UPFL"),
143
+ Company("Unity Foods Ltd.", "Food & Personal Care", "UNITY"),
144
+
145
+ Company("Tariq Glass Industries Ltd.", "Glass & Ceramics", "TGGL"),
146
+ Company("Ghani Glass Ltd.", "Glass & Ceramics", "GHGL"),
147
+
148
+ Company("Pakistan Services Ltd.", "Miscellaneous", "PSEL"),
149
+ Company("Pakistan Aluminium Beverage Cans Ltd.", "Miscellaneous", "PABC"),
150
+ Company("Shifa International Hospitals Ltd.", "Miscellaneous", "SHFA"),
151
+ Company("Javedan Corporation Ltd.", "Property", "JAVED")
152
+ ]
153
+
154
+
155
+ ## KSE 30
156
+
157
+ kse_30 = [
158
+ Company("Fauji Fertilizer Company Limited", "Fertilizer", "FFC"),
159
+ Company("United Bank Limited", "Commercial Banks", "UBL"),
160
+ Company("The Hub Power Company Limited", "Power Generation & Distribution", "HUBC"),
161
+ Company("Engro Holdings Limited", "Investment / Holding Companies", "ENGROH"),
162
+ Company("Oil & Gas Development Company Limited", "Oil & Gas Exploration", "OGDC"),
163
+ Company("Pakistan Petroleum Limited", "Oil & Gas Exploration", "PPL"),
164
+ Company("Meezan Bank Limited", "Commercial Banks", "MEBL"),
165
+ Company("D.G. Khan Cement Company Limited", "Cement", "DGKC"),
166
+ Company("Mari Energies Limited", "Oil & Gas Exploration", "MARI"),
167
+ Company("Habib Bank Limited", "Commercial Banks", "HBL"),
168
+ Company("Fauji Cement Company Limited", "Cement", "FCCL"),
169
+ Company("Engro Fertilizers Limited", "Fertilizer", "EFERT"),
170
+ Company("Pakistan State Oil Company Limited", "Oil & Gas Marketing", "PSO"),
171
+ Company("Maple Leaf Cement Factory Limited", "Cement", "MLCF"),
172
+ Company("Pakistan Oilfields Limited", "Oil & Gas Exploration", "POL"),
173
+ Company("Ghandhara Industries Limited", "Automobile Assembler", "GHNI"),
174
+ Company("Pak Elektron Limited", "Cables & Electrical Goods", "PAEL"),
175
+ Company("Lucky Cement Limited", "Cement", "LUCK"),
176
+ Company("Attock Refinery Limited", "Refinery", "ATRL"),
177
+ Company("MCB Bank Limited", "Commercial Banks", "MCB"),
178
+ Company("Sazgar Engineering Works Limited", "Automobile Assembler", "SAZEW"),
179
+ Company("National Bank of Pakistan", "Commercial Banks", "NBP"),
180
+ Company("The Searle Company Limited", "Pharmaceutical", "SEARL"),
181
+ Company("Sui Northern Gas Pipelines Limited", "Oil & Gas Marketing", "SNGP"),
182
+ Company("Ghandhara Automobiles Limited", "Automobile Assembler", "GAL"),
183
+ Company("Pakistan Refinery Limited", "Refinery", "PRL"),
184
+ Company("The Bank of Punjab", "Commercial Banks", "BOP"),
185
+ Company("Sui Southern Gas Company Limited", "Oil & Gas Marketing", "SSGC"),
186
+ Company("Systems Limited", "Technology & Communication", "SYS"),
187
+ Company("Bank AL Habib Limited", "Commercial Banks", "BAHL"),
188
+ ]
189
+
190
+
191
+ ## div 20
192
+
193
+ psx_div_20 = [
194
+ Company("Pakistan Oilfields Limited", "Oil & Gas Exploration", "POL"),
195
+ Company("Millat Tractors Limited", "Automobile Assembler", "MTL"),
196
+ Company("Arif Habib Corporation Limited", "Investment / Holding Companies", "AHCL"),
197
+ Company("Fauji Fertilizer Company Limited", "Fertilizer", "FFC"),
198
+ Company("MCB Bank Limited", "Commercial Banks", "MCB"),
199
+ Company("Engro Fertilizers Limited", "Fertilizer", "EFERT"),
200
+ Company("Bank Alfalah Limited", "Commercial Banks", "BAFL"),
201
+ Company("BankIslami Pakistan Limited", "Commercial Banks", "BIPL"),
202
+ Company("Bank AL Habib Limited", "Commercial Banks", "BAHL"),
203
+ Company("Image Pakistan Limited", "Textile Composite", "IMAGE"),
204
+ Company("The Bank of Punjab", "Commercial Banks", "BOP"),
205
+ Company("Faysal Bank Limited", "Commercial Banks", "FABL"),
206
+ Company("National Foods Limited", "Food & Personal Care", "NATF"),
207
+ Company("United Bank Limited", "Commercial Banks", "UBL"),
208
+ Company("Javedan Corporation Limited", "Property", "JVDC"),
209
+ Company("The Hub Power Company Limited", "Power Generation & Distribution", "HUBC"),
210
+ Company("Meezan Bank Limited", "Commercial Banks", "MEBL"),
211
+ Company("Habib Bank Limited", "Commercial Banks", "HBL"),
212
+ Company("Oil & Gas Development Company Limited", "Oil & Gas Exploration", "OGDC"),
213
+ Company("Fatima Fertilizer Company Limited", "Fertilizer", "FATIMA"),
214
+ ]
215
+
216
+ ## MII 30
217
+
218
+ mii_30 = [
219
+ Company("Fauji Fertilizer Company Limited", "Fertilizer", "FFC"),
220
+ Company("Engro Holdings Limited", "Investment / Holding Companies", "ENGROH"),
221
+ Company("The Hub Power Company Limited", "Power Generation & Distribution", "HUBC"),
222
+ Company("Lucky Cement Limited", "Cement", "LUCK"),
223
+ Company("Meezan Bank Limited", "Commercial Banks", "MEBL"),
224
+ Company("Mari Energies Limited", "Oil & Gas Exploration", "MARI"),
225
+ Company("Oil & Gas Development Company Limited", "Oil & Gas Exploration", "OGDC"),
226
+ Company("Pakistan Petroleum Limited", "Oil & Gas Exploration", "PPL"),
227
+ Company("Engro Fertilizers Limited", "Fertilizer", "EFERT"),
228
+ Company("Systems Limited", "Technology & Communication", "SYS"),
229
+ Company("Pakistan State Oil Company Limited", "Oil & Gas Marketing", "PSO"),
230
+ Company("Maple Leaf Cement Factory Limited", "Cement", "MLCF"),
231
+ Company("D.G. Khan Cement Company Limited", "Cement", "DGKC"),
232
+ Company("Millat Tractors Limited", "Automobile Assembler", "MTL"),
233
+ Company("Fauji Cement Company Limited", "Cement", "FCCL"),
234
+ Company("Faysal Bank Limited", "Commercial Banks", "FABL"),
235
+ Company("Sazgar Engineering Works Limited", "Automobile Assembler", "SAZEW"),
236
+ Company("Pioneer Cement Limited", "Cement", "PIOC"),
237
+ Company("Cherat Cement Company Limited", "Cement", "CHCC"),
238
+ Company("Sui Northern Gas Pipelines Limited", "Oil & Gas Marketing", "SNGP"),
239
+ Company("Attock Refinery Limited", "Refinery", "ATRL"),
240
+ Company("Lucky Core Industries Limited", "Chemical", "LCI"),
241
+ Company("Pak Elektron Limited", "Cables & Electrical Goods", "PAEL"),
242
+ Company("The Searle Company Limited", "Pharmaceutical", "SEARL"),
243
+ Company("GlaxoSmithKline Pakistan Limited", "Pharmaceutical", "GLAXO"),
244
+ Company("Highnoon Laboratories Limited", "Pharmaceutical", "HINOON"),
245
+ Company("Kohat Cement Company Limited", "Cement", "KOHC"),
246
+ Company("Abbott Laboratories (Pakistan) Limited", "Pharmaceutical", "ABOT"),
247
+ Company("National Foods Limited", "Food & Personal Care", "NATF"),
248
+ ]
249
+
250
+
251
+ ## KMI 30
252
+
253
+ kmi_30 = [
254
+ Company("Air Link Communication Limited", "Technology & Communication", "AIRLINK"),
255
+ Company("Attock Refinery Limited", "Refinery", "ATRL"),
256
+ Company("Cnergyico PK Limited", "Refinery", "CNERGY"),
257
+ Company("Citi Pharma Limited", "Pharmaceutical", "CPHL"),
258
+ Company("D.G. Khan Cement Company Limited", "Cement", "DGKC"),
259
+ Company("Engro Fertilizers Limited", "Fertilizer", "EFERT"),
260
+ Company("Engro Holdings Limited", "Investment / Holding Companies", "ENGROH"),
261
+ Company("Fauji Cement Company Limited", "Cement", "FCCL"),
262
+ Company("Fauji Fertilizer Company Ltd", "Fertilizer", "FFC"),
263
+ Company("Fauji Foods Limited", "Food & Personal Care", "FFL"),
264
+ Company("Ghandhara Automobiles Limited", "Automobile Assembler", "GAL"),
265
+ Company("Ghandhara Industries Limited", "Automobile Assembler", "GHNI"),
266
+ Company("GlaxoSmithKline Pakistan", "Pharmaceutical", "GLAXO"),
267
+ Company("The Hub Power Company Limited", "Power Generation & Distribution", "HUBC"),
268
+ Company("Lucky Cement Limited", "Cement", "LUCK"),
269
+ Company("Mari Energies Limited", "Oil & Gas Exploration", "MARI"),
270
+ Company("Meezan Bank Limited", "Commercial Banks", "MEBL"),
271
+ Company("Maple Leaf Cement Factory Limited", "Cement", "MLCF"),
272
+ Company("Millat Tractors Limited", "Automobile Assembler", "MTL"),
273
+ Company("National Refinery Limited", "Refinery", "NRL"),
274
+ Company("Oil & Gas Development Company Limited", "Oil & Gas Exploration", "OGDC"),
275
+ Company("Pak Elektron Limited", "Cables & Electrical Goods", "PAEL"),
276
+ Company("Pakistan Petroleum Limited", "Oil & Gas Exploration", "PPL"),
277
+ Company("Pakistan Refinery Limited", "Refinery", "PRL"),
278
+ Company("Pakistan State Oil Company Limited", "Oil & Gas Marketing", "PSO"),
279
+ Company("Sazgar Engineering Works Limited", "Automobile Assembler", "SAZEW"),
280
+ Company("The Searle Company Limited", "Pharmaceutical", "SEARL"),
281
+ Company("Sui Northern Gas Pipelines Limited", "Oil & Gas Marketing", "SNGP"),
282
+ Company("Sui Southern Gas Company Limited", "Oil & Gas Marketing", "SSGC"),
283
+ Company("Systems Limited", "Technology & Communication", "SYS"),
284
+ ]
285
+
286
+
287
+ INDEX_MAP = {
288
+ IndexEnum.kse_100: kse_100,
289
+ IndexEnum.kse_30: kse_30,
290
+ IndexEnum.psx_div_20: psx_div_20,
291
+ IndexEnum.mii_30: mii_30,
292
+ IndexEnum.kmi_30: kmi_30,
293
+ }