Си диез / Говнокод #1782 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
/// <summary>
    ///  Retrieve currency rates from an external site to be sure they are up to date.
    /// In this case just checking the one currency (Australian Dollar) so no need to dynamically parse the site.
    /// </summary>
    /// <returns>currency rates or msg indicating an error</returns>
    private String getCurrencyRates()
    {
        string strURL = @"http://www.x-rates.com/d/JPY/table.html";
        HttpWebRequest txtRequest = (HttpWebRequest)WebRequest.Create(strURL);

        txtRequest.Method = "GET";
        txtRequest.ContentType = "application/x-www-form-urlencoded";
        string response;
        using (StreamReader streamReader = new StreamReader(txtRequest.GetResponse().GetResponseStream()))
        {
            response = streamReader.ReadToEnd();
            if (response.IndexOf("Australian Dollar") > 0)
            {
                //parse the returned page for the two values of the currency rate based on the existing design
                int ind_jpy = (response.IndexOf("/d/AUD/JPY/graph120.html") + 39);
                int ind_aud = (response.IndexOf("/d/JPY/AUD/graph120.html") + 39);
                String jpy_aud = response.Substring(ind_jpy, (response.IndexOf("</a>",ind_jpy) - ind_jpy) );
                String aud_jpy = response.Substring(ind_aud, (response.IndexOf("</a>", ind_aud) - ind_aud));
                Session["curr_rate"] = "set";
                Session["JPY"] = jpy_aud;
                Session["AUD"] = aud_jpy;
                return aud_jpy + " / " + jpy_aud;
            }
            //else present msg to user that unable to obtain currency rates
        }
        return "";
    }

Еще один кандидат

Запостил: OlgaWolga OlgaWolga, (Updated )

Комментарии (6) RSS

  • слушайте, а это хорошая идея собирать контент на говнокод.ру 🙂

    /me пошел размещать вакансии
    Ответить
  • Обращаюсь к авторам: Не всегда очевидно на что нужно обращать внимание, особенно, когда кода больше 10 строк, поэтому пишите пояснения!
    Ответить
  • > Еще один кандидат
    Это неявная ссылка на предыдущий говнокод.
    Тема та же: парсинг вместо сервиса
    Ответить
    • для начала пробуем найти на этом сайте сервис
      Ответить
  • - Ну нет, благодарю покорно, я к нему больше близко не подойду!
    Ответить

Добавить комментарий

Переведи на "PHP", guest!

    А не использовать ли нам bbcode?


    8