Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions COVID.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions COVID/COVID.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.14.0" />
<PackageReference Include="Com.Airbnb.Xamarin.Forms.Lottie" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NScrape" Version="0.4.1" />
<PackageReference Include="Plugin.MediaManager.Forms" Version="0.9.6" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
Expand Down
3 changes: 2 additions & 1 deletion COVID/Models/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ namespace COVID.Models
{
public class Details
{

public Stats Stat { get; set; }
public string Date { get; set; }
public string Histoire { get; set; }
public string History { get; set; }

public string ActiveCases { get{ return Stat.ActiveCases.ToString();} }
public string Cured { get{ return Stat.Cured.ToString();} }
Expand Down
8 changes: 2 additions & 6 deletions COVID/Models/InfosCovid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
namespace COVID.Models
{
public class InfosCovid
{
public Stats InfosduJour { get { return Details.FirstOrDefault().Stat; } }
{
public List<Details> Details { get; set; }
public InfosCovid(List<Details> infos)
{
Details = infos;
}

}
}
31 changes: 31 additions & 0 deletions COVID/Services/AzureClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using COVID.Models;
using Newtonsoft.Json;

namespace COVID.Services
{
public static class AzureClient
{
private static string Url { get; } = "https://covidapi20200420180335.azurewebsites.net/covid19tg";
public static async Task<InfosCovid> RefreshDataAsync()
{
var uri = new Uri(Url);
HttpClient myClient = new HttpClient();

var response = await myClient.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();

var returnValue = new InfosCovid();
returnValue.Details=JsonConvert.DeserializeObject<List<Details>>(content);
return returnValue;
}
return null;
}
}
}
58 changes: 2 additions & 56 deletions COVID/Services/Covid19TgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,14 @@ namespace COVID.Services
{
public static class Covid19TgService
{
public static async Task<Stats> GetAsync()
{
// Load default configuration
var config = Configuration.Default.WithDefaultLoader();
// Create a new browsing context
var context = BrowsingContext.New(config);
// This is where the HTTP request happens, returns <IDocument> that // we can query later
try
{
var document = await context.OpenAsync("https://covid19.gouv.tg/");
string tmp = document.QuerySelector("#active-cases>div>h2").InnerHtml;
var stat = new Stats();
stat.ActiveCases = document.ReadInteger("#active-cases>div>h2");
stat.Cured = document.ReadInteger("#cured>div>h2");
stat.Deaths = document.ReadInteger("#deceased>div>h2");
return stat;
}catch(Exception e)
{
var t = e.Message;
return new Stats();
}
}
public static InfosCovid InfosCovid{get;set;}
public static Details InfoduJour {get{ return InfosCovid.Details.FirstOrDefault();}}
public static void AppelNumeroVert()
{
PhoneDialer.Open(Covid19TgService.NumeroVert);
}
public static string NumeroVert{get;set;}="111";
public static InfosCovid InfosCovid{get;set;}
public static async Task<InfosCovid> GetDetailsAsync()
{
var config = Configuration.Default.WithDefaultLoader();
var context = BrowsingContext.New(config);
var document = await context.OpenAsync("http://covid19.gouv.tg/situation-au-togo/");
var details = new List<Details>();

var sections = document.QuerySelectorAll(".ee-loop__item>article>div>div>div");
string xt = string.Empty;

foreach (var item in sections.Skip(1))
{
var itemDetails = new Details();
xt += "\n\n";
var itemsections = item.QuerySelectorAll("section");
var itemHtmlDetails = itemsections.FirstOrDefault().QuerySelectorAll("h2");
itemDetails.Date = $"{itemHtmlDetails[0].InnerHtml} à { itemHtmlDetails[1].InnerHtml}";

int i = 0;
Stats itemStats = new Stats();
itemStats.ActiveCases = itemHtmlDetails[3].InnerHtml.GetInt();
itemStats.Cured = itemHtmlDetails[4].InnerHtml.GetInt();
itemStats.Deaths = itemHtmlDetails[5].InnerHtml.GetInt();
itemDetails.Stat = itemStats;
foreach (var history in itemsections[1].QuerySelectorAll("p"))
{
itemDetails.Histoire += $"\n{history.InnerHtml}";
}
details.Add(itemDetails);

}

return new InfosCovid(details);
}

}
}
19 changes: 7 additions & 12 deletions COVID/ViewModels/DetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public List<Details> LeDetails
set { SetProperty(ref _details, value); }
}


public Stats Stat
{
get { return _stat; }
Expand All @@ -32,8 +31,6 @@ public Stats Stat
}
private Stats _stat;



private string _date;
public string Date
{
Expand All @@ -42,33 +39,31 @@ public string Date
set { SetProperty(ref _date, value); }
}


private string _histoire;
public string Histoire
private string _history;
public string History
{
get { return _histoire; }
get { return _history; }

set { SetProperty(ref _histoire, value); }
set { SetProperty(ref _history, value); }
}

public string ActiveCases { get { return Stat.ActiveCases.ToString(); } }
public string Cured { get { return Stat.Cured.ToString(); } }
public string Deaths { get { return Stat.Deaths.ToString(); } }
public string Total { get { return Stat.Total.ToString(); } }

public DetailViewModel()
{
_ = GetDetailsAsync();
_= GetDetailsAsync();

Appel = new Command(() => Appeler());
}

private async Task GetDetailsAsync()
{
Covid19TgService.InfosCovid= await Covid19TgService.GetDetailsAsync();
Covid19TgService.InfosCovid= await AzureClient.RefreshDataAsync();
LeDetails = Covid19TgService.InfosCovid.Details;
}

private void Appeler()
{
Covid19TgService.AppelNumeroVert();
Expand Down
18 changes: 7 additions & 11 deletions COVID/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,13 @@ public HomeViewModel()

async Task GetDetails()
{

//var stat = await Covid19TgService.GetAsync();

Covid19TgService.InfosCovid= await Covid19TgService.GetDetailsAsync();

CasActifs = Covid19TgService.InfosCovid.InfosduJour.ActiveCases.ToString();
CasGueris = Covid19TgService.InfosCovid.InfosduJour.Cured.ToString();
Deces = Covid19TgService.InfosCovid.InfosduJour.Deaths.ToString();
CasConfirmes = Covid19TgService.InfosCovid.InfosduJour.Total.ToString();
DateUpdate = Covid19TgService.InfosCovid.Details.FirstOrDefault().Date;

Covid19TgService.InfosCovid= await AzureClient.RefreshDataAsync();
var info = Covid19TgService.InfoduJour;
CasActifs = info.ActiveCases.ToString();
CasGueris = info.Cured.ToString();
Deces = info.Deaths.ToString();
CasConfirmes = info.Total.ToString();
DateUpdate = info.Date;
}

private void Appeler()
Expand Down
2 changes: 1 addition & 1 deletion COVID/Views/DetailsTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.ColumnSpan="4"
Text="{Binding Histoire }"
Text="{Binding History }"
FontFamily="{StaticResource MontserratMediumFont}"
FontSize="16"
Padding="10,30,10,10"
Expand Down