NOT DEBUGED YET. update of the updatedeposits function.

This commit is contained in:
2021-11-05 01:07:15 +02:00
parent 4cdd960233
commit 86e0e35e41
4 changed files with 60 additions and 11 deletions

View File

@@ -1,5 +1,4 @@
using Deposits.SubDep; using Deposits.SubDep;
namespace Deposits { namespace Deposits {
class Program { class Program {
public static bool ToEncrypt() { public static bool ToEncrypt() {
@@ -39,6 +38,7 @@ namespace Deposits {
//Data data = new Data(true); //Data data = new Data(true);
//data.AddToData("{\"phone\":\"0547477082\"}"); //data.AddToData("{\"phone\":\"0547477082\"}");
//System.Console.WriteLine("yes"); //System.Console.WriteLine("yes");
} }
} }
} }

View File

@@ -6,12 +6,17 @@
//using System.Runtime.InteropServices; //using System.Runtime.InteropServices;
//using Microsoft.Office.Interop.Excel; //using Microsoft.Office.Interop.Excel;
//using OfficeOpenXml.Core; //using OfficeOpenXml.Core;
//using HtmlAgilityPack;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Deposits.SubDep { namespace Deposits.SubDep {
class Excel { class Excel {
private static System.IO.FileInfo file = new System.IO.FileInfo(DataDetails.ExcelLocation); private static System.IO.FileInfo file = new System.IO.FileInfo(DataDetails.ExcelLocation);
private OfficeOpenXml.ExcelPackage excelPackage = new OfficeOpenXml.ExcelPackage(file); private OfficeOpenXml.ExcelPackage excelPackage = new OfficeOpenXml.ExcelPackage(file);
public OfficeOpenXml.ExcelWorksheet deposits { get; } public OfficeOpenXml.ExcelWorksheet deposits { get; }
public OfficeOpenXml.ExcelWorksheet creditCard { get; } public OfficeOpenXml.ExcelWorksheet creditCard { get; }
public OfficeOpenXml.ExcelWorksheet depositHistory { get; }
public Excel() { public Excel() {
var wb = excelPackage.Workbook; var wb = excelPackage.Workbook;
foreach (var sheet in wb.Worksheets) { foreach (var sheet in wb.Worksheets) {
@@ -19,6 +24,8 @@ namespace Deposits.SubDep {
this.deposits = sheet; this.deposits = sheet;
} else if (sheet.Name.Contains("credit")) { } else if (sheet.Name.Contains("credit")) {
this.creditCard = sheet; this.creditCard = sheet;
} else if (sheet.Name.StartsWith("History")) {
this.depositHistory = sheet;
} }
} }
if (deposits == null) { if (deposits == null) {
@@ -27,10 +34,25 @@ namespace Deposits.SubDep {
if (creditCard == null) { if (creditCard == null) {
creditCard = wb.Worksheets.Add("credit card"); creditCard = wb.Worksheets.Add("credit card");
} }
if (depositHistory == null) {
creditCard = wb.Worksheets.Add("History of Deposits");
}
} }
public void UpdateDeposits() { public void UpdateDeposits(string htmlPage) {
HtmlAgilityPack.HtmlDocument document = new();
document.LoadHtml(htmlPage);
var s = document.DocumentNode.SelectNodes("//span");
List<float> data = new List<float>();
Regex regex = new Regex(@"(\d|.)+");
foreach (var item in s) {
if (item.Attributes["class"].Name == "bigLobbyImageSum") {
var v = regex.Match(item.Attributes["class"].Value).Value;
data.Add(float.Parse(v));
}
}
this.deposits.Cells["B2:B5"].Value = data.ToArray();
} }
} }
} }

View File

@@ -10,12 +10,12 @@ namespace Deposits.SubDep {
Url = url; Url = url;
Mail = mail; Mail = mail;
this.Driver.Url = Url; this.Driver.Url = Url;
Deposits.SubDep.Data data = new(true); Data data = new(true);
Data = (JObject)data.DataJson["humail"]; this.Data = (JObject)data.DataJson["humail"];
} }
public void DefineMailApp() { public void DefineMailApp() {
this.MailApp = new(); this.MailApp = new();
MailApp.RunWeb() MailApp.RunWeb();
} }
} }

View File

@@ -1,4 +1,6 @@
using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Firefox;
using System.Collections.Generic;
using System.Text;
namespace Deposits.SubDep { namespace Deposits.SubDep {
class WebDriver { class WebDriver {
FirefoxOptions options = new(); FirefoxOptions options = new();
@@ -6,24 +8,27 @@ namespace Deposits.SubDep {
string?[] Urls; string?[] Urls;
public FirefoxDriver Driver; public FirefoxDriver Driver;
//JObject UrlAndActions //JObject UrlAndActions
public WebDriver() {
CodePagesEncodingProvider.Instance.GetEncoding(437);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
//System.IO.Path.Join("bins");
SetOption();
this.Driver = new("bins", this.options);
}
private void SetProfile() { private void SetProfile() {
this.profile.SetPreference("browser.download.folderList", 2); this.profile.SetPreference("browser.download.folderList", 2);
this.profile.SetPreference("browser.download.manager.showWhenStarting", false); //this.profile.SetPreference("browser.download.manager.showWhenStarting", false);
this.profile.SetPreference("browser.download.dir", "D:/Neutral Folder/"); this.profile.SetPreference("browser.download.dir", "D:/Neutral Folder/");
this.profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "attachment/csv, text/plain, application/octet-stream, application/binary, text/csv, application/csv, application/excel, text/comma-separated-values, text/xml, application/xml, application/xls, excel/xls, application/excel 97-2003,application/Microsoft Excel 97-2003 Worksheet, application/vnd.ms-excel"); this.profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "attachment/csv, text/plain, application/octet-stream, application/binary, text/csv, application/csv, application/excel, text/comma-separated-values, text/xml, application/xml, application/xls, excel/xls, application/excel 97-2003,application/Microsoft Excel 97-2003 Worksheet, application/vnd.ms-excel");
this.profile.SetPreference("browser.helperApps.neverAsk.openFile", "application/PDF, application/FDF, application/XFDF, application/LSL, application/LSO, application/LSS, application/IQY, application/RQY, application/XLK, application/XLS, application/XLT, application/POT application/PPS, application/PPT, application/DOS, application/DOT, application/WKS, application/BAT, application/PS, application/EPS, application/WCH, application/WCM, application/WB1, application/WB3, application/RTF, application/DOC, application/MDB, application/MDE, application/WBK, application/WB1, application/WCH, application/WCM, application/AD, application/ADP, application/vnd.ms-excel"); this.profile.SetPreference("browser.helperApps.neverAsk.openFile", "application/PDF, application/FDF, application/XFDF, application/LSL, application/LSO, application/LSS, application/IQY, application/RQY, application/XLK, application/XLS, application/XLT, application/POT application/PPS, application/PPT, application/DOS, application/DOT, application/WKS, application/BAT, application/PS, application/EPS, application/WCH, application/WCM, application/WB1, application/WB3, application/RTF, application/DOC, application/MDB, application/MDE, application/WBK, application/WB1, application/WCH, application/WCM, application/AD, application/ADP, application/vnd.ms-excel");
this.profile.SetPreference("browser.download.panel.shown", false); this.profile.SetPreference("browser.download.panel.shown", false);
} }
private void SetOption() { private void SetOption() {
SetProfile(); SetProfile();
this.options.Profile = this.profile; this.options.Profile = this.profile;
this.options.AddArgument("--lang=EN"); this.options.AddArgument("--lang=EN");
} }
public WebDriver() {
//System.IO.Path.Join("bins\\geckodriver.exe");
SetOption();
this.Driver = new($"bins", options);
}
public void RunWeb(int timeToWait = 0, params string[] urls) { public void RunWeb(int timeToWait = 0, params string[] urls) {
//System.Timers.Timer timer = new(timeToWait * 1000); //System.Timers.Timer timer = new(timeToWait * 1000);
foreach (var url in urls) { foreach (var url in urls) {
@@ -31,5 +36,27 @@ namespace Deposits.SubDep {
System.Threading.Thread.Sleep(timeToWait * 1000); System.Threading.Thread.Sleep(timeToWait * 1000);
} }
} }
public void EnterDataToWeb(string url, Dictionary<string, string> idToData) {
Driver.Url = url;
var v = "";
System.Threading.Thread.Sleep(30000);
try {
foreach (var dataid in idToData) {
Driver.FindElementById(dataid.Key).SendKeys(dataid.Value);
System.Threading.Thread.Sleep(100);
v = dataid.Key;
}
Driver.FindElementById(v).SendKeys(OpenQA.Selenium.Keys.Enter);
} catch {
foreach (var dataid in idToData) {
Driver.FindElementByName(dataid.Key).SendKeys(dataid.Value.Split('@')[0]);
System.Threading.Thread.Sleep(100);
v = dataid.Key;
}
Driver.FindElementByName(v).SendKeys(OpenQA.Selenium.Keys.Enter);
}
}
} }
} }