Пример #1
0
        private static void Weather()
        {
            string City = "";

            string[]   Body       = { };
            WeatherTxt weatherTxt = new WeatherTxt();

            weatherTxt.DeleteBodyTxt();

            ImapClient client = new ImapClient("imap.gmail.com", true);

            if (client.Connect())
            {
                Console.WriteLine("connected");
                if (client.Login("*****@*****.**", "123456789dD"))
                {
                    Console.WriteLine("logined");
                    client.Folders.Inbox.Messages.Download("ALL", MessageFetchMode.Full, 5);
                    foreach (Message message in client.Folders.Inbox.Messages)
                    {
                        if (message.Seen != true)
                        {
                            Console.WriteLine("пытаюсь удалить txt и string");
                            weatherTxt.SetNewBody("");
                            weatherTxt.DeleteBodyTxt();
                            Console.WriteLine("удалил");
                            message.Seen = true;
                            if (CheckSubject(message.Subject) != "false")
                            {
                                Console.WriteLine(CheckSubject(message.Subject));
                                Console.WriteLine(message.From.Address.ToString());
                                City = Regex.Replace(message.Body.Text, "[-.?!)(,: }{1234567890]", "");
                                GetWeather(CheckSubject(message.Subject), City, ref weatherTxt);
                                SendMail("smtp.gmail.com",
                                         "*****@*****.**",
                                         "123456789dD",
                                         message.From.Address.ToString(),
                                         CheckSubject(message.Subject),
                                         weatherTxt.getBody(),
                                         @"C:\Users\Владимир\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\weather.txt"
                                         );
                                Console.WriteLine("сообщение отправлено");
                                Console.WriteLine(weatherTxt.getBody() + "\n--------------------------------------------------------------------------------");
                            }
                        }
                    }
                    int a = Console.Read();
                }
            }
        }
Пример #2
0
        public WeatherTxt GetWeather(string method, string city)
        {
            url  = "http://api.openweathermap.org/data/2.5/" + method + "?q=" + city + "&mode=xml&units=metric" + appId;
            date = @"H:\Users\denis\\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\\Debug\WeatherXml\" + Regex.Replace(System.DateTime.Now.ToLongTimeString(), "[:]", ".") + ".xml";
            Console.WriteLine(date);

            XDocument weather = new XDocument();

            weather = XDocument.Load(url);
            weather.Save(date);

            if (method == "weather")
            {
                foreach (XElement TemElement in weather.Element("current").Elements("temperature"))
                {
                    XAttribute valueAttribute = TemElement.Attribute("value");
                    SetBody(valueAttribute.Value);
                }
                BodyToTxt(getBody());
            }
            else if (method == "forecast")
            {
                foreach (XElement TimeElement in weather.Element("weatherdata").Element("forecast").Elements("time"))
                {
                    XAttribute valueAttribute = TimeElement.Element("temperature").Attribute("value");
                    SetBody(valueAttribute.Value);
                }
                BodyToTxt(getBody());
            }
            else if (method == "forecast/daily")
            {
                foreach (XElement TimeElement in weather.Element("weatherdata").Element("forecast").Elements("time"))
                {
                    XAttribute valueAttribute = TimeElement.Element("temperature").Attribute("day");
                    SetBody(valueAttribute.Value);
                }
                BodyToTxt(getBody());
            }

            WeatherTxt weatherTxt = new WeatherTxt(getBodyTxt(), getBody());

            return(weatherTxt);
        }
Пример #3
0
        private static void GetWeather(string method, string city, ref WeatherTxt weatherTxt)
        {
            //WeatherTxt weatherTxt = new WeatherTxt();
            string appId = File.ReadAllText(@"appId.txt");
            string url   = "http://api.openweathermap.org/data/2.5/" + method + "?q=" + city + "&mode=xml&units=metric" + appId;
            string data  = @"C:\Users\Владимир\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\WeatherXml\" + Regex.Replace(System.DateTime.Now.ToLongTimeString(), "[:]", ".") + ".xml";

            Console.WriteLine(data);

            XDocument weather = new XDocument();

            weather = XDocument.Load(url);
            weather.Save(data);

            if (method == "weather")
            {
                foreach (XElement TemElement in weather.Element("current").Elements("temperature"))
                {
                    XAttribute valueAttribute = TemElement.Attribute("value");
                    weatherTxt.SetBody(valueAttribute.Value);
                }
                weatherTxt.BodyToTxt(weatherTxt.getBody());
            }
            else if (method == "forecast")
            {
                foreach (XElement TimeElement in weather.Element("weatherdata").Element("forecast").Elements("time"))
                {
                    XAttribute valueAttribute = TimeElement.Element("temperature").Attribute("value");
                    weatherTxt.SetBody(valueAttribute.Value);
                }
                weatherTxt.BodyToTxt(weatherTxt.getBody());
            }

            else if (method == "forecast/daily")
            {
                foreach (XElement TimeElement in weather.Element("weatherdata").Element("forecast").Elements("time"))
                {
                    XAttribute valueAttribute = TimeElement.Element("temperature").Attribute("day");
                    weatherTxt.SetBody(valueAttribute.Value);
                }
                weatherTxt.BodyToTxt(weatherTxt.getBody());
            }
        }
Пример #4
0
        private static void Weather()
        {
            string City = "";

            string[]   Email      = File.ReadAllLines(@"Email.txt");
            WeatherTxt weatherTxt = new WeatherTxt();

            ImapClient client = new ImapClient("imap.gmail.com", true);

            if (client.Connect())
            {
                if (client.Login("*****@*****.**", "123456789dD"))
                {
                    client.Folders.Inbox.Messages.Download("ALL", MessageFetchMode.Full, 2);
                    foreach (Message message in client.Folders.Inbox.Messages)
                    {
                        Console.WriteLine(ReadFromExcel(message.From.Address.ToString()));
                        if ((message.Seen == false) && (CheckSubject(message.Subject) != "false") && (ReadFromExcel(message.From.Address.ToString())))
                        {
                            message.Seen = true;
                            Console.WriteLine(message.From.Address.ToString());
                            City = Regex.Replace(message.Body.Text, "[-.?!)(,: }{1234567890]", "");
                            weatherTxt.GetWeather(CheckSubject(message.Subject), City);
                            SendMail("smtp.gmail.com",
                                     Email[0],
                                     Email[1],
                                     message.From.Address.ToString(),
                                     CheckSubject(message.Subject),
                                     weatherTxt.getBody(),
                                     weatherTxt.GetDate());
                            Console.WriteLine("сообщение отправлено");
                            WriteToExcel(message);
                            weatherTxt.Clear();
                        }
                    }
                }
                int a = Console.Read();
            }
        }