2020 yılında, acil ihtiyacım olduğu için ve sonrasını da çok (hiç) düşünmeden hızlıca powershell ile -kendime- yazdığım “Şirket Bilançolarını toplu indirme”scripti ile ilgili güncellik sorunları ve serzenişler içeren mailler almıştım (neden paylaşıyorsun diye küfür de içeren yorum yazan arkadaşı da analım). Aslında clean code kurallarına çok uymadığı ve daha ziyade spaghetti olan bu kodları neden paylaştım ve başıma dert aldım bilmiyorum. Neyse, bu akşam çok müsait ve canım sıkılan bir zamanımda twitter’dan gelen bir DM ile hızlıca göz atıp 2022 yılını da içerek şekilde güncelledim. Artık 2023 yılı ve neden herkese paylaştığımın hesabını sorup küfürler yazan bencil (!) arkadaşlar düşünsün.
Eski versiyonda detaylı açıklamaları var, link şurada;
Gene uyarılarımı yapayım; bug olabilir, hızlıca güncelledim. Sorumluluk kabul etmiyor, peşinen reddediyorum. PowerShell ISE ile scripti çalıştırabileceğinizi, çıktının C:/ ana dizini altında olacağını ve kullanıcı yetkisi gibi hatalar alırsanız aşağıda yazdığım şu kuralı çalıştırmanız gerektiğini unutmayın;
1 | Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser |
“Kontrolsüz” Güncellenmiş kodlar ise şöyle;
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 | # Created : 2020/05 - Revised : 2022/10 # hmustak - mustak.org $code = "EREGL" $ceyrek =3 #Son yıl $yil =2020 #Kolon isimleri ve ilk yılın (2014) artık dönemini burada şekillendiriyoruz $URL9 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=2014&period2=12&year3=2014&period3=9&year4=2014&period4=6" $Response9 = Invoke-WebRequest -Uri $URL9 $a9 = ConvertFrom-Json -InputObject $Response9 .Content $a8 = $a9 .value | Select ItemDescTr, value2,value3,value4 #2015 Yılı sleep(1) $yil =2015 $URL10 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response10 = Invoke-WebRequest -Uri $URL10 $a10 = ConvertFrom-Json -InputObject $Response10 .Content $a11 = $a10 .value | Select value1,value2,value3,value4 #2016 Yılı sleep(1) $yil =2016 $URL20 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response20 = Invoke-WebRequest -Uri $URL20 $a20 = ConvertFrom-Json -InputObject $Response20 .Content $a21 = $a20 .value | Select value1,value2,value3,value4 #2017 Yılı sleep(1) $yil =2017 $URL30 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response30 = Invoke-WebRequest -Uri $URL30 $a30 = ConvertFrom-Json -InputObject $Response30 .Content $a31 = $a30 .value | Select value1,value2,value3,value4 #2018 Yılı sleep(1) $yil =2018 $URL40 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response40 = Invoke-WebRequest -Uri $URL40 $a40 = ConvertFrom-Json -InputObject $Response40 .Content $a41 = $a40 .value | Select value1,value2,value3,value4 #2019 Yılı sleep(1) $yil =2019 $URL50 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response50 = Invoke-WebRequest -Uri $URL50 $a50 = ConvertFrom-Json -InputObject $Response50 .Content $a51 = $a50 .value | Select value1,value2,value3,value4 #2020 Yılı sleep(1) $yil =2020 $URL60 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response60 = Invoke-WebRequest -Uri $URL60 $a60 = ConvertFrom-Json -InputObject $Response60 .Content $a61 = $a60 .value | Select value1,value2,value3,value4 #2021 Yılı sleep(1) $yil =2021 $URL70 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response70 = Invoke-WebRequest -Uri $URL70 $a70 = ConvertFrom-Json -InputObject $Response70 .Content $a71 = $a70 .value | Select value1,value2,value3,value4 #2022 Yılı sleep(1) $yil =2022 $URL80 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=$yil&period2=9&year3=$yil&period3=6&year4=$yil&period4=3" $Response80 = Invoke-WebRequest -Uri $URL80 $a80 = ConvertFrom-Json -InputObject $Response80 .Content $a81 = $a80 .value | Select value1,value2,value3,value4 #4Ç Düzeltmesi #Burada tüm çeyrekler 12.ay : 2020-2019-2018 sleep(1) $URL1000 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=2020&period2=12&year3=2019&period3=12&year4=2018&period4=12" $Response1000 = Invoke-WebRequest -Uri $URL1000 $a1000 = ConvertFrom-Json -InputObject $Response1000 .Content $a1001 = $a1000 .value | Select value1,value2,value3,value4 #4Ç Düzeltmesi #Burada tüm çeyrekler 12.ay : 2017-2016-2015 sleep(1) $URL2000 = "https://www.isyatirim.com.tr/_layouts/15/IsYatirim.Website/Common/Data.aspx/MaliTablo?companyCode=$code&exchange=TRY&financialGroup=XI_29&year1=2020&period1=3&year2=2017&period2=12&year3=2016&period3=12&year4=2015&period4=12" $Response2000 = Invoke-WebRequest -Uri $URL2000 $a2000 = ConvertFrom-Json -InputObject $Response2000 .Content $a2001 = $a2000 .value | Select value1,value2,value3,value4 class CsvRow { [object] ${Kalem} [object] ${2022/12} [object] ${2022/9} [object] ${2022/6} [object] ${2022/3} [object] ${2021/12} [object] ${2021/9} [object] ${2021/6} [object] ${2021/3} [object] ${2020/12} [object] ${2020/9} [object] ${2020/6} [object] ${2020/3} [object] ${2019/12} [object] ${2019/9} [object] ${2019/6} [object] ${2019/3} [object] ${2018/12} [object] ${2018/9} [object] ${2018/6} [object] ${2018/3} [object] ${2017/12} [object] ${2017/9} [object] ${2017/6} [object] ${2017/3} [object] ${2016/12} [object] ${2016/9} [object] ${2016/6} [object] ${2016/3} [object] ${2015/12} [object] ${2015/9} [object] ${2015/6} [object] ${2015/3} [object] ${2014/12} [object] ${2014/9} [object] ${2014/6} } $count = $a8 .value1.Count-1 # Dizi sınıfını oluşturalım $arrayList = [System.Collections.ArrayList] ::new() # Loop foreach ( $ndx in 0.. $count ) { $rowObj = [CsvRow] ::new() # Dizi değerlerini atayalım $rowObj . 'Kalem' = $a8 .itemDescTr[ $ndx ] #$rowObj.'2022/12'= $a1001.value2[$ndx] #$rowObj.'2022/9' = $a81.value2[$ndx] $rowObj . '2022/6' = $a81 .value3[ $ndx ] $rowObj . '2022/3' = $a81 .value4[ $ndx ] $rowObj . '2021/12' = $a1001 .value2[ $ndx ] $rowObj . '2021/9' = $a71 .value2[ $ndx ] $rowObj . '2021/6' = $a71 .value3[ $ndx ] $rowObj . '2021/3' = $a71 .value4[ $ndx ] $rowObj . '2020/12' = $a1001 .value2[ $ndx ] $rowObj . '2020/9' = $a61 .value2[ $ndx ] $rowObj . '2020/6' = $a61 .value3[ $ndx ] $rowObj . '2020/3' = $a61 .value4[ $ndx ] $rowObj . '2019/12' = $a1001 .value3[ $ndx ] $rowObj . '2019/9' = $a51 .value2[ $ndx ] $rowObj . '2019/6' = $a51 .value3[ $ndx ] $rowObj . '2019/3' = $a51 .value4[ $ndx ] $rowObj . '2018/12' = $a1001 .value4[ $ndx ] $rowObj . '2018/9' = $a41 .value2[ $ndx ] $rowObj . '2018/6' = $a41 .value3[ $ndx ] $rowObj . '2018/3' = $a41 .value4[ $ndx ] $rowObj . '2017/12' = $a2001 .value2[ $ndx ] $rowObj . '2017/9' = $a31 .value2[ $ndx ] $rowObj . '2017/6' = $a31 .value3[ $ndx ] $rowObj . '2017/3' = $a31 .value4[ $ndx ] $rowObj . '2016/12' = $a2001 .value3[ $ndx ] $rowObj . '2016/9' = $a21 .value2[ $ndx ] $rowObj . '2016/6' = $a21 .value3[ $ndx ] $rowObj . '2016/3' = $a21 .value4[ $ndx ] $rowObj . '2015/12' = $a2001 .value4[ $ndx ] $rowObj . '2015/9' = $a11 .value2[ $ndx ] $rowObj . '2015/6' = $a11 .value3[ $ndx ] $rowObj . '2015/3' = $a11 .value4[ $ndx ] $rowObj . '2014/12' = $a8 .value2[ $ndx ] $rowObj . '2014/9' = $a8 .value3[ $ndx ] $rowObj . '2014/6' = $a8 .value4[ $ndx ] $null = $arrayList .Add( $rowObj ) } # Dizi çıktımızı CSV olarak verelim $arrayList | Export-Csv -NoTypeInformation -Path "C:\$code.csv" -Encoding UTF8 # Created : 2020/05 - Revised : 2022/10 # hmustak - mustak.org |
Umarım işinize yarar…
Hakan Müştak
Merhaba, Yukardaki kod ile örnek olarak AKBNK bilgileri çekilmiyor. anladığım kadarı ile financialGroup=XI_29 ile ilgili.. Banka bilgileri konusunda bildiğin bir kod varmı?
Zaman zaman sorun çıktı mesajları alıyorum sizin yazdığınız gibi. Açıkcası bende sorunsuz çalışıyor ve nedenini bilmiyorum. Sorun çıkanlar için alternatif olarak python versiyonunu yazdım. Onu deneyebilirsiniz.
Link : https://www.mustak.org/sirket-bilancolarini-toplu-indirme-python-guncellemesi/
İlk önce zaman ayırıp cevap yazdığın için teşekkürler. Diğer bütün sektör HİSSE senedi bilgilerini çekebiliyorum. O kısımda hic bir sorun yok.. Kod içinde sorun olsa hiç birisi gelmez. sadece bankalar gelmiyor. Bu konuda financialGroup=XI_29 ile ilgili olduğunu düşündüm. şans eseri 29 değiştirerek denemeler yaptım ama olmadı. Size sormak istedim. (AKBNK ISCTR)