|
1 | | -using console_weather.API; |
| 1 | +using System.Net; |
| 2 | +using console_weather.API; |
2 | 3 |
|
3 | 4 | namespace console_weather.Icons; |
4 | 5 |
|
5 | 6 | public static class IconsHandler { |
6 | | - private static readonly string DayIconsPath = @"Icons\Day\"; |
7 | | - private static readonly string NightIconsPath = @"Icons\Night\"; |
| 7 | + // icons |
| 8 | + private static readonly string DayIconsUrl = "https://raw.githubusercontent.com/pazurkota/console-weather/master/console-weather/Icons/day/"; |
| 9 | + private static readonly string NightIconsUrl = "https://raw.githubusercontent.com/pazurkota/console-weather/master/console-weather/Icons/night/"; |
8 | 10 |
|
| 11 | + // data |
9 | 12 | private static readonly int IsDay = ApiData.ParseData().Current.IsDay; |
10 | | - private static readonly int ConditionCole = ApiData.ParseData().Current.Condition.ConditionCode; |
| 13 | + private static readonly int ConditionCode = ApiData.ParseData().Current.Condition.ConditionCode; |
11 | 14 |
|
12 | 15 | public static string GetIcon() { |
13 | | - var icon = IsDay == 1 ? GetDayIcon() : GetNightIcon(); |
14 | | - var iconContent = File.ReadAllText(icon); |
| 16 | + var iconsUrl = IsDay == 1 ? DayIconsUrl : NightIconsUrl; |
| 17 | + var icon = GetIconFromUrl(iconsUrl + GetConditionCode()[ConditionCode] + ".txt"); |
15 | 18 |
|
16 | | - return iconContent; |
17 | | - } |
18 | | - |
19 | | - private static string GetDayIcon() { |
20 | | - var dayIcons = Directory.GetFiles(DayIconsPath); |
21 | | - var conditionCode = GetConditionCode()[ConditionCole]; |
22 | | - var icon = dayIcons.FirstOrDefault(icon => icon.Contains(conditionCode)); |
23 | | - |
24 | 19 | return icon; |
25 | 20 | } |
26 | | - |
27 | | - private static string GetNightIcon() { |
28 | | - var nightIcons = Directory.GetFiles(NightIconsPath); |
29 | | - var conditionCode = GetConditionCode()[ConditionCole]; |
30 | | - var icon = nightIcons.FirstOrDefault(icon => icon.Contains(conditionCode)); |
| 21 | + |
| 22 | + private static string GetIconFromUrl(string url) { |
| 23 | + var client = new WebClient(); |
| 24 | + var icon = client.DownloadString(url); |
31 | 25 |
|
32 | 26 | return icon; |
33 | 27 | } |
|
0 commit comments