using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace Hava_Durumu_Deneme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
HavaDurumu("İstanbul");
}
private static string BilgiCek(string url)
{
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.UTF8.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
return sb.ToString();
}
private static string ToClearText(string tarih)
{
return Regex.Replace(tarih, @"<(.|\n)*?>", string.Empty);
}
string deger,durum="";
private void HavaDurumu(string gelen_Sehir)
{
string url = "http://www.mgm.gov.tr/tahmin/il-ve-ilceler.aspx?m=" + gelen_Sehir;
string html = BilgiCek(url);
deger = "";
string havadurumu = @"<em class";
int pos1 = html.IndexOf(havadurumu);
int pos2 = html.IndexOf("</em>", pos1);
string derece = html.Substring(pos1, pos2 - pos1);
string sondurum = @"/FILES/img";
int pos5 = html.IndexOf(sondurum);
int pos6 = html.IndexOf(".png", pos5);
string sdurum = html.Substring(pos5, pos6 - pos5);
sdurum = ToClearText(sdurum);
string resim = sdurum + ".png";
derece = ToClearText(derece);
pictureBox1.Image = Resim(@"http://www.mgm.gov.tr/" + resim);
string durum = @"<tbody>";
int pos3 = html.IndexOf(durum);
int pos4 = html.IndexOf("</tbody>", pos3);
string ddeg = html.Substring(pos3, pos4 - pos3);
ddeg = ToClearText(ddeg);
string[] pars2 = ddeg.Split("".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] pars = derece.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
label1.Text = gelen_Sehir;
string dene = pars[0];
int i = 0;
while (dene[i] != '#')
{
deger += dene[i];
i++;
}
if (resim == "/FILES/imgIcon/99/e_72x72t_png/-23.png")
durum = "Çok Bulutlu";
if (resim == "/FILES/imgIcon/99/e_72x72t_png/-29.png")
durum = ("Güneşli");
if (resim == "/FILES/imgIcon/99/e_36x36t_png/63.png")
durum = ("Yağmurlu");
if (resim == "/FILES/imgIcon/99/e_36x36t_png/-25.png")
durum = ("Parçalı Bulutlu");
if (resim == "/FILES/imgIcon/99/e_36x36t_png/68.png")
durum = ("Karla Karışık Yağmurlu");
if (resim == "/FILES/imgIcon/99/e_36x36t_png/73.png")
durum = ("Kar Yağışlı");
if (resim == "/FILES/imgIcon/99/e_36x36t_png/73.png")
durum = ("Kar Yağışlı");
if (resim == "/FILES/imgIcon/99/e_36x36t_png/82.png")
durum = ("Kuvvetli Sağanak Yağışlı");
if (resim == "/FILES/imgIcon/99/e_36x36t_png/75.png")
durum = ("Yoğun Kar Yağışlı");
if (resim == "/FILES/imgIcon/99/e_72x72t_png/45.png")
durum = ("Sisli");
if (resim == "/FILES/imgIcon/99/e_72x72t_png/-28.png")
durum = ("Az Bulutlu");
label1.Text = gelen_Sehir + " " + deger + "° C " + durum;
}
Bitmap Resim(string Url)
{
WebRequest rs = WebRequest.Create(Url);
return (Bitmap)Bitmap.FromStream(rs.GetResponse().GetResponseStream());
}
private void button1_Click(object sender, EventArgs e)
{
HavaDurumu(textBox1.Text);
}
}
}