-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusinessinsider.py
103 lines (70 loc) · 3.2 KB
/
businessinsider.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
import requests
from bs4 import BeautifulSoup
def businessi(term):
store={}
URL="https://markets.businessinsider.com/bonds/"+term
headers={"User-Agent": "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"}
page = requests.get(URL,headers=headers)
soup = BeautifulSoup(page.content, "html.parser")
table=soup.find_all(class_="table__tr")
scripts=soup.find_all("script")
st=[]
rating=soup.find(class_="moodys-rating__rating")
for i in range(0,len(scripts)):
st.append(str(scripts[i]))
tabledata=[]
for i in table:
if('class="table__td">' in str(i)):
tabledata.append(str(i))
for i in range(0,len(tabledata)-5):
base=str(tabledata[i]).replace("\t","").replace("\n",'')
name=base.split('class="table__td">')[1].split('</td>')[0]
data=base.split('class="table__td">')[1].split('</td>')[1].split('<td class="table__td text-right">')[1]
store[name]=data
Issue=str(store["Issuer"]).split('">')[1].split("</a>")[0]
store["Issuer"]=Issue
try:
rating=rating.text
store["rating"]=100-int(rating)
if (int(rating)<33):
store["color"]="green"
elif(int(rating)>33 and int(rating)<66):
store["color"]="orange"
else:
store["color"]="red"
except:
store["rating"]="-"
store["graphdata"]=st[23].replace("<script>","").replace("</script>","").replace("=","").replace(" ","").replace("null","None").replace("false","False").replace("true","True").replace("\n","").replace("\t","").replace('/','')
return store
def topchart():
store={}
URL="https://markets.businessinsider.com/ajax/finanzen/api/commodities?urls=gold-price,oil-price"
headers={"User-Agent": "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"}
page = requests.get(URL,headers=headers)
data = page.json()
return data
def topbonds():
store=[]
URL="https://markets.businessinsider.com/bonds"
headers={"User-Agent": "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"}
page = requests.get(URL,headers=headers)
soup = BeautifulSoup(page.content, "html.parser")
table=soup.find_all(class_="table__tr")
topb=[]
for i in table:
if ("/bonds" in str(i)):
topb.append(str(i).replace("\n","").replace("\t","").split("/bonds/"))
for i in range(0,len(topb)):
linkisin=topb[i][2].split('<td class="table__td text-right">')[0].split('">')
name=topb[i][1].split('<td class="table__td text-right">')[0].split('">')[1].split("</a>")[0]
permod=topb[i][2].split('<td class="table__td text-right">')
link=linkisin[0]
isin=linkisin[1].split("</a>")[0]
d=[]
for k in range(1,len(permod)):
d.append(permod[k].split("</td>")[0])
di={"name":name,"isin":isin,"yield":d[0],"moodys":d[1],"date":d[2],"link":link,"namelink":name.replace(" ","%20").replace(".","")}
store.append(di)
return store
#print(businessi("apple_incad-notes_201626-Bond-2026-au3cb0237881"))
#topbonds()