Umgeschrieben auf Sevdesk
This commit is contained in:
@@ -3,16 +3,8 @@
|
||||
using OpenQA.Selenium.Chrome;
|
||||
using OpenQA.Selenium;
|
||||
using System.Net;
|
||||
|
||||
/*
|
||||
*
|
||||
* referalPage: /de/OnePiece
|
||||
username: Skywalkerex
|
||||
userPassword: Magnatpower310!!
|
||||
/de/OnePiece/PostGetAction/User_Login
|
||||
|
||||
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
||||
*/
|
||||
using System.Diagnostics;
|
||||
using ConsoleApp3.Contracts;
|
||||
|
||||
namespace CardmarketBot
|
||||
{
|
||||
@@ -20,6 +12,7 @@ namespace CardmarketBot
|
||||
{
|
||||
private readonly string username;
|
||||
private readonly string password;
|
||||
private readonly IUsedRepository _usedRepository;
|
||||
|
||||
Dictionary<string, Helper.Porto> portoberechnung = new Dictionary<string, Helper.Porto>()
|
||||
{
|
||||
@@ -31,10 +24,11 @@ namespace CardmarketBot
|
||||
{"3,20 €", Helper.Porto.PRIO270 },
|
||||
};
|
||||
|
||||
public CardMarketParser(string username, string password)
|
||||
public CardMarketParser(string username, string password, IUsedRepository repository)
|
||||
{
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
_usedRepository = repository;
|
||||
}
|
||||
|
||||
public List<Kunde> ParseCardMarket()
|
||||
@@ -65,27 +59,39 @@ namespace CardmarketBot
|
||||
cookieContainer.Add(new System.Net.Cookie(name, value, c.Path, c.Domain));
|
||||
}
|
||||
|
||||
//cd.Navigate().GoToUrl(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Paid");
|
||||
cd.Navigate().GoToUrl(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Sent");
|
||||
|
||||
IWebElement element = cd.FindElement(By.XPath("/html/body/main/section/div[3]/div[3]/div[2]"));
|
||||
string content = element.Text;
|
||||
|
||||
string[] datas = content.Split("\r\n");
|
||||
cd.Navigate().GoToUrl(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Paid");
|
||||
//cd.Navigate().GoToUrl(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Sent");
|
||||
|
||||
List<string> ids = new List<string>();
|
||||
for (int i = 0; i < datas.Length; i += 7)
|
||||
{
|
||||
ids.Add(datas[i]);
|
||||
}
|
||||
|
||||
List<Kunde> kunden = new List<Kunde>();
|
||||
IWebElement element;
|
||||
try
|
||||
{
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div[3]/div[3]/div[2]"));
|
||||
string content = element.Text;
|
||||
|
||||
int maxCounter = 2;
|
||||
int counter = 0;
|
||||
List<string> bereitsbearbeitet = _usedRepository.Query;
|
||||
string[] datas = content.Split("\r\n");
|
||||
|
||||
|
||||
for (int i = 0; i < datas.Length; i += 7)
|
||||
{
|
||||
if (bereitsbearbeitet.Find(x => x.Equals(datas[i])) != null) continue;
|
||||
ids.Add(datas[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch(OpenQA.Selenium.NotFoundException ex)
|
||||
{
|
||||
Console.WriteLine("Keine Verkäufe aktuell");
|
||||
return kunden;
|
||||
}
|
||||
|
||||
foreach (string id in ids)
|
||||
{
|
||||
if (counter > maxCounter) break;
|
||||
|
||||
Console.WriteLine(id);
|
||||
cd.Navigate().GoToUrl(string.Format(@"https://www.cardmarket.com/de/OnePiece/Orders/{0}", id));
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[3]/div[2]/div[2]/div/div"));
|
||||
@@ -94,12 +100,22 @@ namespace CardmarketBot
|
||||
|
||||
// Bezahldatum
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[2]/div/div[2]/div[2]"));
|
||||
kunde.Bezahldatum = element.Text;
|
||||
//Debugger.Break();
|
||||
kunde.Bezahldatum = Helper.ConvertBezahlDatum(element.Text);
|
||||
|
||||
|
||||
// Versandkosten
|
||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[3]/div[1]/div[2]/div/div[3]/span[2]"));
|
||||
kunde.Versandskosten = portoberechnung[element.Text];
|
||||
Helper.Porto resul;
|
||||
if(portoberechnung.TryGetValue(element.Text, out resul))
|
||||
{
|
||||
kunde.Versandskosten = resul;
|
||||
}
|
||||
else
|
||||
{
|
||||
kunde.OverrideVersandskosten = element.Text;
|
||||
Console.WriteLine(@"Achtung bei ID {id} wurde kein Richtige Porto berechnet. Liegt es im Ausland?");
|
||||
}
|
||||
//kunde.Versandskosten = portoberechnung[element.Text];
|
||||
kunde.BestellungID = id;
|
||||
|
||||
|
||||
@@ -111,7 +127,6 @@ namespace CardmarketBot
|
||||
|
||||
|
||||
kunden.Add(kunde);
|
||||
counter++;
|
||||
Thread.Sleep(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
return kunden;
|
||||
|
||||
Reference in New Issue
Block a user