Rank: Elder Joined: 3/19/2013 Posts: 2,552
|
Definition of spaghetti code.For educational purposes only Graphs
Code: using System; using System.IO; class ss { static void Main() { string[] bb = {"SCOM","ACCS","UNGA","MSC","ORCH","EVRD","EABL","CARB","BAT","BOC","TCL","OCH","CITY","ICDC","PAFR","CFCI","KNRE","JUB","CIC","BRIT","UMME","TOTL","KPLC","KENO","KEGN","PORT","CABL","BERG","BAMB","ARM","UCHM","TPSE","SGL","SCAN","NMG","LKL","KQ","XPRS","SCBK","NIC","NBK","KCB","HFCK","EQTY","DTK","COOP","CFC","BBK","FIRE","MASH","CMC","WTK","SASN","REA","LIMT","KAPC","KUKZ","EGAD","C%2526G","%5ENASI","%5EN20I"}; string inn = "http://live.mystocks.co.ke/graphs/"; string im = ".Chart?mspgsid=3e186ffb|4322|1364211724.4653;r="; string ie = ";f=w;t=avg;v=ovr;corp=0;id=1364212103737"; FileStream ff = new FileStream("nn.txt", FileMode.Create, FileAccess.Write); StreamWriter ww = new StreamWriter(ff); int[] pp = { 30, 60, 90, 180, 270, 360, 420, 540, 720, 1080, 1800, 3600, 7200 }; string dd; for(int i = 0; i<bb.Length; i++) { for(int j = 0; j< pp.Length; j++) { dd = inn+bb[i]+im+pp[j]+ie; ww.WriteLine(dd); } } ww.Close(); ff.Close(); } }
List
Code: using System; using System.Runtime.InteropServices; using System.Net; using Excel = Microsoft.Office.Interop.Excel; using HtmlAgilityPack; using System.IO;
namespace MyStocks { class Program { static int rr = 2; static int cc = 1; static void Main(string[] args) { for (int pp = 1; pp <= 31; pp++) { string dd; string ff = "201301"; if (pp < 10) { dd = ff + "0" + pp; } else { dd = ff + pp; } string str = "http://live.mystocks.co.ke/price_list/" + dd; WebClient aa = new WebClient(); var webget = new HtmlWeb(); var doc = webget.Load(str); var nod = doc.DocumentNode.SelectNodes("//tr[@class='row r1']"); var noda = doc.DocumentNode.SelectNodes("//tr[@class='row r0']"); Excel.Application app = new Excel.Application(); Excel.Workbook Wbook = app.Workbooks.Add(1); Excel.Worksheet sheet = (Excel.Worksheet)Wbook.Worksheets.Add(); sheet.Cells[1, 1] = "Name"; sheet.Cells[1, 2] = "Low-12"; sheet.Cells[1, 3] = "High-12"; sheet.Cells[1, 4] = "Low-Day"; sheet.Cells[1, 5] = "High-Day"; sheet.Cells[1, 6] = "Price"; sheet.Cells[1, 7] = "Previous"; sheet.Cells[1, 8] = "Change-Price"; sheet.Cells[1, 9] = "Change-Perc"; sheet.Cells[1, 10] = "Volume"; sheet.Cells[1, 11] = "Adjusted Price";
for (int yy = 0; yy < noda.Count; yy++) {
var gh = noda[yy].SelectNodes("td"); int gg = gh.Count; for (int i = 1; i < gh.Count; i++) { if (i == 8) { i = 11; sheet.Cells[rr, 8] = (sheet.Cells[rr, 6].Value) - (sheet.Cells[rr, 7].Value); sheet.Cells[rr, 9] = (sheet.Cells[rr, 8].Value) / (sheet.Cells[rr, 7].Value) + "%"; cc = 10; } sheet.Cells[rr, cc] = gh[i].InnerHtml; cc++; } rr++; cc = 1; } for (int yy = 0; yy < nod.Count; yy++) {
var gh = nod[yy].SelectNodes("td"); int gg = gh.Count; for (int i = 1; i < gh.Count; i++) { if (i == 8) { i = 11; sheet.Cells[rr, 8] = (sheet.Cells[rr, 6].Value) - (sheet.Cells[rr, 7].Value); sheet.Cells[rr, 9] = (sheet.Cells[rr, 8].Value) / (sheet.Cells[rr, 7].Value)*100+"%"; cc = 10; } sheet.Cells[rr, cc] = gh[i].InnerHtml; cc++; } rr++; cc = 1; } rr = 2; cc = 1; Wbook.SaveAs(@"C:\Finale\" + dd + ".xls"); app.Quit(); Marshal.ReleaseComObject(sheet); Marshal.ReleaseComObject(Wbook); Marshal.ReleaseComObject(app); } } } }
|