-
Notifications
You must be signed in to change notification settings - Fork 4
/
nepse_simple.py
234 lines (187 loc) · 6.41 KB
/
nepse_simple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# /bin/env python
# -*- coding: utf-8 -*-
"""Untitled24.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1k8T91ug1-HAPxvYj9d88EUTIguMZ3QwO
"""
asadas = """<html><head>NEPSE SIMPLE</head><header>
<!-- Top header menu containing
logo and Navigation bar -->
<div id="top-header">
<!-- Logo -->
<div id="logo">
<a href="https://sumityadav.com.np">
<img src= https://rockerritesh.github.io/nepsesimple/android-chrome-192x192.png>
</a>
</div>
<!-- Navigation Menu -->
<nav>
<ul>
<li class="active"><a href="https://rockerritesh.github.io/nepsesimple/index">Home</a></li>
<li><a href="https://rockerritesh.github.io/nepsesimple/todaysummary">Today Summary</a></li>
<li><a href="https://rockerritesh.github.io/nepsesimple/marketsummary">Summary</a></li>
<li><a href="https://rockerritesh.github.io/nepsesimple/marketdata">Top Value Data</a></li>
<li><a href="https://rockerritesh.github.io/nepsesimple/ipo">IPO</a></li>
<li><a href="https://rockerritesh.github.io/nepsesimple/todayindex">Indices</a></li>
<li><a href="https://rockerritesh.github.io/nepsesimple/each_company">Each Company</a></li>
<p dir="auto"><a href="https://github.com/rockerritesh/nepsesimple/actions/workflows/update.yml"><img src="https://github.com/rockerritesh/nepsesimple/actions/workflows/update.yml/badge.svg" alt="Update file(s)" style="max-width: 100%;"></a></p>
</ul>
</nav>
</div>
<p><img class="lazyautosizes lazyloaded" src="https://github.com/rockerritesh/nepsesimple/raw/main/graph.png" data-src="https://github.com/rockerritesh/nepsesimple/raw/main/graph.png" data-srcset="https://github.com/rockerritesh/nepsesimple/raw/main/graph.png, https://github.com/rockerritesh/nepsesimple/raw/main/graph.png 1.5x, https://github.com/rockerritesh/nepsesimple/raw/main/graph.png 2x" data-sizes="auto" alt="https://github.com/rockerritesh/nepsesimple/raw/main/graph.png" title="Graph" sizes="800px" srcset="https://github.com/rockerritesh/nepsesimple/raw/main/graph.png, https://github.com/rockerritesh/nepsesimple/raw/main/graph.png 1.5x, https://github.com/rockerritesh/nepsesimple/raw/main/graph.png 2x"></p>
<!-- Image menu in Header to contain an Image and
a sample text over that image -->
<div id="header-image-menu">
</div>
</header>
<script button.addEventListener('click', () => {
document.body.classList.toggle('dark')
localStorage.setItem(
'theme',
document.body.classList.contains('dark') ? 'dark' : 'light'
)
})
if (localStorage.getItem('theme') === 'dark') {
document.body.classList.add('dark')
}></script>
<style>
body{
padding:10% 3% 10% 3%;
text-align:center;
}
img{
height:140px;
width:140px;
}
h1{
color: #32a852;
}
.mode {
float:right;
}
.change {
cursor: pointer;
border: 1px solid #555;
border-radius: 40%;
width: 20px;
text-align: center;
padding: 5px;
margin-left: 8px;
}
.dark{
background-color: #000;
color: #fff;
}
</style>
<body>
"""
import requests
import pandas as pd
import numpy as np
import openpyxl
import matplotlib.pyplot as plt
import bs4
import html5lib
"""
url = "https://nepalstockinfo.com/stocklive"
html = requests.get(url).content
df = pd.read_html(html)
df[0]
df[0] = df[0].sort_values(by=["Previous Closing"])
df[0].pop("#")
df[0].pop("S.N.")
df[0]
loc = "nepse_simple.xlsx"
df[0].to_csv("mydata.csv")
df[0].to_html("todaysummary.html")
df[0].to_excel(loc)
oxl = openpyxl.load_workbook(loc)
oxl.sheetnames
sheet = oxl.active
ws = sheet
dims = {}
for row in ws.rows:
for cell in row:
if cell.value:
dims[cell.column_letter] = max(
(dims.get(cell.column_letter, 0), len(str(cell.value)))
)
for col, value in dims.items():
ws.column_dimensions[col].width = value
oxl.save(loc)
"""
url2 = "https://www.nepalipaisa.com/Indices.aspx"
html2 = requests.get(url2).content
df_list2 = pd.read_html(html2)
df22 = df_list2[-1]
data2 = np.array(df22)
data2 = np.flip(data2)
plot = data2[0 : data2.shape[0], 2]
plt.figure(figsize=(40, 25))
plt.plot(plot, "go--")
plt.savefig("graph.png")
# FOR STOCK
urlstock = "https://www.sharesansar.com/market"
htmlstock = requests.get(urlstock).content
df_list_stock = pd.read_html(htmlstock)
df_stock = df_list_stock[3]
df_stock.to_csv("stock.csv")
# FOR IPO
urlshare = "https://www.sharesansar.com/?show=home"
htmlshare = requests.get(urlshare).content
df_list_share = pd.read_html(htmlshare)
df_share = df_list_share[2]
df_share.to_csv("ipo.csv")
df_share.to_html("ipo.html")
# new way direct from nepalstock.com
nepse = requests.get("http://nepalstock.com")
soup = bs4.BeautifulSoup(nepse.text, "html5lib")
category = soup.find_all(class_="panel-body")
html = asadas + str(category[3]) + "</body> </html>"
with open("marketsummary.html", "w") as output:
output.write(html)
html = asadas + str(category[2]) + "</body> </html>"
with open("marketdata.html", "w") as output:
output.write(html)
html = asadas + str(category[4]) + "</body> </html>"
with open("todayindex.html", "w") as output:
output.write(html)
"""
nepse = requests.get("https://nepalstockinfo.com")
soup = bs4.BeautifulSoup(nepse.text, "html5lib")
category = soup.find_all(class_="col-md-6")
html = "<html><head></head><body>" + str(category[2]) + "</body> </html>"
with open("marketsummary.html", "w") as output:
output.write(html)
"""
"""
df = pd.read_json("https://nepalstock-api.herokuapp.com/nepse-index")
df1 = df.sort_values(by=["nooftransaction"])
html = df1.to_html()
html = asadas + html + "</body> </html>"
with open("index.html", "w") as output:
output.write(html)
# all company status each
dfall = pd.read_json("https://nepalstock-api.herokuapp.com/nepse-index")
htm = dfall.to_html()
htm = asadas + htm + "</body> </html>"
with open("each_company.html", "w") as output:
output.write(htm)
"""
# json file nepssimpleeapi
df = pd.read_html("http://www.nepalstock.com/todaysprice/export")
df = df[-1].T
df.to_json("nepsesimple.json")
"""
# FOR PLOT
for i in range(df.shape[1]):
closing_price=df[i][4]
#a0=np.load(f'{i}.npy')
a0=1
#closing_price=(1,2,3,4,5)
aaa=np.append(a0,(closing_price))
np.save(f'{i}',aaa)
#a=np.load('1.npy')
#plt.plot(a)
"""