Code cleanup
This commit is contained in:
34
ConsoleApp3/Artikel.cs
Normal file
34
ConsoleApp3/Artikel.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
internal class Artikel
|
||||||
|
{
|
||||||
|
public int Amount { get; set; }
|
||||||
|
public string GERName { get; set; } = "";
|
||||||
|
public string ENGName { get; set; } = "";
|
||||||
|
public string CardNumber { get; set; } = "";
|
||||||
|
public string Source { get; set; } = "";
|
||||||
|
public string Raritaet { get; set; } = "";
|
||||||
|
public string Preis { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Paid");
|
||||||
|
hwr.CookieContainer = cookieContainer;
|
||||||
|
hwr.Method = "GET";
|
||||||
|
hwr.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
|
||||||
|
WebResponse wr = hwr.GetResponse();
|
||||||
|
string s = new StreamReader(wr.GetResponseStream()).ReadToEnd();
|
||||||
|
Console.WriteLine(s);
|
||||||
|
|
||||||
|
string GetHashKey(string line)
|
||||||
|
{
|
||||||
|
var x = line.IndexOf("__cmtkn");
|
||||||
|
var d = line.Substring(x + 16);
|
||||||
|
var m = d.IndexOf("\"");
|
||||||
|
var a = d.Substring(0, m);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
108
ConsoleApp3/CardMarketParser.cs
Normal file
108
ConsoleApp3/CardMarketParser.cs
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CardmarketBot
|
||||||
|
{
|
||||||
|
class CardMarketParser
|
||||||
|
{
|
||||||
|
Dictionary<string, Helper.Porto> portoberechnung = new Dictionary<string, Helper.Porto>()
|
||||||
|
{
|
||||||
|
{"1,15 €", Helper.Porto.BRIEF085 },
|
||||||
|
{"1,30 €", Helper.Porto.BRIEF100 },
|
||||||
|
{"2,10 €", Helper.Porto.BRIEF160 },
|
||||||
|
{"3,25 €", Helper.Porto.BRIEF275 },
|
||||||
|
{"2,60 €", Helper.Porto.PRIO210 },
|
||||||
|
{"3,20 €", Helper.Porto.PRIO270 },
|
||||||
|
};
|
||||||
|
public List<Kunde> ParseCardMarket()
|
||||||
|
{
|
||||||
|
ChromeOptions options = new ChromeOptions();
|
||||||
|
options.AddArgument("start-maximized");
|
||||||
|
IWebDriver cd = new ChromeDriver(options);
|
||||||
|
cd.Url = @"https://www.cardmarket.com/de/OnePiece";
|
||||||
|
|
||||||
|
cd.Navigate();
|
||||||
|
cd.FindElement(By.CssSelector("#CookiesConsent > div > div > form > button")).Click();
|
||||||
|
cd.FindElement(By.Name("username")).Click();
|
||||||
|
cd.FindElement(By.Name("username")).SendKeys("Skywalkerex");
|
||||||
|
cd.FindElement(By.Name("userPassword")).Click();
|
||||||
|
|
||||||
|
|
||||||
|
cd.FindElement(By.Name("userPassword")).SendKeys("Magnatpower310!!");
|
||||||
|
cd.FindElement(By.CssSelector("#header-login > input.btn.AB-login-btn.btn-outline-primary.btn-sm")).Click();
|
||||||
|
|
||||||
|
|
||||||
|
CookieContainer cookieContainer = new CookieContainer();
|
||||||
|
foreach (var c in cd.Manage().Cookies.AllCookies)
|
||||||
|
{
|
||||||
|
string name = c.Name;
|
||||||
|
string value = c.Value;
|
||||||
|
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");
|
||||||
|
|
||||||
|
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>();
|
||||||
|
|
||||||
|
int maxCounter = 2;
|
||||||
|
int counter = 0;
|
||||||
|
foreach (string id in ids)
|
||||||
|
{
|
||||||
|
if (counter > maxCounter) break;
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
||||||
|
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"));
|
||||||
|
|
||||||
|
Kunde kunde = Helper.ConvertToKunde(element.Text);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// 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];
|
||||||
|
kunde.BestellungID = id;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Artikeln
|
||||||
|
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[5]/table/tbody"));
|
||||||
|
string artikeln = element.Text;
|
||||||
|
kunde.Artikels = Helper.ParseArtikeln(element.Text);
|
||||||
|
|
||||||
|
|
||||||
|
kunden.Add(kunde);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
return kunden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
61
ConsoleApp3/DeutschePost.cs
Normal file
61
ConsoleApp3/DeutschePost.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* referalPage: /de/OnePiece
|
||||||
|
username: Skywalkerex
|
||||||
|
userPassword: Magnatpower310!!
|
||||||
|
/de/OnePiece/PostGetAction/User_Login
|
||||||
|
|
||||||
|
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CardmarketBot
|
||||||
|
{
|
||||||
|
class DeutschePost
|
||||||
|
{
|
||||||
|
List<Kunde> kundenlist;
|
||||||
|
public DeutschePost(List<Kunde> kunden)
|
||||||
|
{
|
||||||
|
kundenlist = kunden;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GenerateCSV()
|
||||||
|
{
|
||||||
|
IEnumerable<IGrouping<Helper.Porto, Kunde>> groupedPorto = kundenlist.GroupBy(x => x.Versandskosten).Distinct();
|
||||||
|
|
||||||
|
foreach (IGrouping<Helper.Porto, Kunde> gkunde in groupedPorto)
|
||||||
|
{
|
||||||
|
//FileStream stream = File.Create(string.Format("test_{0}.csv", gkunde.Key.ToString()));
|
||||||
|
Helper.Porto porto = gkunde.Key;
|
||||||
|
using (StreamWriter writer = new StreamWriter(string.Format("./test_{0}.csv", gkunde.Key.ToString()), false, Encoding.Latin1))
|
||||||
|
{
|
||||||
|
|
||||||
|
string header = "NAME;ZUSATZ;STRASSE;NUMMER;PLZ;STADT;LAND;ADRESS_TYP;REFERENZ";
|
||||||
|
writer.WriteLine(header);
|
||||||
|
string absender = "W&W TECH UG;Lukas Winkelmann;Schwedenschanze;70;49808;LINGEN;DEU;HOUSE";
|
||||||
|
writer.WriteLine(absender);
|
||||||
|
foreach (Kunde n in gkunde)
|
||||||
|
{
|
||||||
|
string empfanger = string.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8}",
|
||||||
|
n.Name,
|
||||||
|
"",
|
||||||
|
n.Strasse,
|
||||||
|
n.Hausnummer,
|
||||||
|
n.Plz,
|
||||||
|
n.Ort,
|
||||||
|
"DEU",
|
||||||
|
//n.Land,
|
||||||
|
"HOUSE",
|
||||||
|
n.BestellungID
|
||||||
|
);
|
||||||
|
writer.WriteLine(empfanger);
|
||||||
|
}
|
||||||
|
writer.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
86
ConsoleApp3/Helper.cs
Normal file
86
ConsoleApp3/Helper.cs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
static class Helper
|
||||||
|
{
|
||||||
|
public enum Porto
|
||||||
|
{
|
||||||
|
BRIEF085,
|
||||||
|
BRIEF100,
|
||||||
|
BRIEF160,
|
||||||
|
BRIEF275,
|
||||||
|
PRIO210,
|
||||||
|
PRIO270
|
||||||
|
}
|
||||||
|
internal static Kunde ConvertToKunde(string text)
|
||||||
|
{
|
||||||
|
|
||||||
|
string[] datas = text.Split("\r\n");
|
||||||
|
string name = datas[0];
|
||||||
|
string adresseUNDHausnummer = datas[1];
|
||||||
|
string plzUNDOrt = datas[2];
|
||||||
|
string land = datas[3];
|
||||||
|
|
||||||
|
datas = plzUNDOrt.Split(" ");
|
||||||
|
string plz = datas[0];
|
||||||
|
string ort = datas[1];
|
||||||
|
|
||||||
|
datas = adresseUNDHausnummer.Split(" ");
|
||||||
|
string strasse = "";
|
||||||
|
for (int i = 0; i < datas.Length - 1; i++)
|
||||||
|
{
|
||||||
|
strasse += datas[i] + " ";
|
||||||
|
}
|
||||||
|
strasse = strasse.Trim();
|
||||||
|
string hausnummer = datas[datas.Length - 1];
|
||||||
|
|
||||||
|
return new Kunde(name, strasse, hausnummer, plz, ort, land);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static List<Artikel> ParseArtikeln(string text)
|
||||||
|
{
|
||||||
|
List<Artikel> result = new List<Artikel>();
|
||||||
|
string[] datas = text.Split("\r\n");
|
||||||
|
|
||||||
|
|
||||||
|
int anzahl = datas.Length / 6;
|
||||||
|
|
||||||
|
for (int i = 0; i < datas.Length; i += 6)
|
||||||
|
{
|
||||||
|
Artikel temp = new Artikel();
|
||||||
|
var xFound = datas[i].IndexOf("x");
|
||||||
|
var am = datas[i].Substring(0, xFound);
|
||||||
|
temp.Amount = Convert.ToInt32(am);
|
||||||
|
temp.GERName = datas[i].Substring(xFound + 1);
|
||||||
|
temp.ENGName = datas[i + 1];
|
||||||
|
temp.CardNumber = datas[i + 2];
|
||||||
|
temp.Source = datas[i + 3];
|
||||||
|
temp.Raritaet = datas[i + 4];
|
||||||
|
temp.Preis = datas[i + 5].Split(' ')[0];
|
||||||
|
result.Add(temp);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Paid");
|
||||||
|
hwr.CookieContainer = cookieContainer;
|
||||||
|
hwr.Method = "GET";
|
||||||
|
hwr.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
|
||||||
|
WebResponse wr = hwr.GetResponse();
|
||||||
|
string s = new StreamReader(wr.GetResponseStream()).ReadToEnd();
|
||||||
|
Console.WriteLine(s);
|
||||||
|
|
||||||
|
string GetHashKey(string line)
|
||||||
|
{
|
||||||
|
var x = line.IndexOf("__cmtkn");
|
||||||
|
var d = line.Substring(x + 16);
|
||||||
|
var m = d.IndexOf("\"");
|
||||||
|
var a = d.Substring(0, m);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
106
ConsoleApp3/InvoiceParser.cs
Normal file
106
ConsoleApp3/InvoiceParser.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
using ConsoleApp3.DataContracts;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* referalPage: /de/OnePiece
|
||||||
|
username: Skywalkerex
|
||||||
|
userPassword: Magnatpower310!!
|
||||||
|
/de/OnePiece/PostGetAction/User_Login
|
||||||
|
|
||||||
|
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CardmarketBot
|
||||||
|
{
|
||||||
|
class InvoiceParser
|
||||||
|
{
|
||||||
|
Dictionary<Helper.Porto, decimal> PortoPreis = new Dictionary<Helper.Porto, decimal>()
|
||||||
|
{
|
||||||
|
{Helper.Porto.BRIEF085, 1.15m },
|
||||||
|
{Helper.Porto.BRIEF100, 1.30m },
|
||||||
|
{Helper.Porto.BRIEF160, 2.10m },
|
||||||
|
{Helper.Porto.BRIEF275, 3.25m },
|
||||||
|
{Helper.Porto.PRIO210, 2.60m },
|
||||||
|
{Helper.Porto.PRIO270, 3.20m }
|
||||||
|
};
|
||||||
|
private static string DateTimeConverter(string input)
|
||||||
|
{
|
||||||
|
//2023-06-20T11:30:00"
|
||||||
|
//2023-02-22T00:00:00.000+01:0
|
||||||
|
string datum = input.Substring(0, 10);
|
||||||
|
string uhrzeit = input.Substring(10, input.Length - 10);
|
||||||
|
input = string.Format("{0} {1}", datum, uhrzeit);
|
||||||
|
DateTime converted = Convert.ToDateTime(input);
|
||||||
|
var format = "yyyy-MM-ddTHH:mm:ssK";
|
||||||
|
string res = converted.ToString(format);
|
||||||
|
return string.Format("{0}.000+01:00", res);
|
||||||
|
|
||||||
|
}
|
||||||
|
List<Kunde> kunden;
|
||||||
|
public InvoiceParser(List<Kunde> kunden)
|
||||||
|
{
|
||||||
|
this.kunden = kunden;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Invoice> GetInvoices()
|
||||||
|
{
|
||||||
|
List<Invoice> result = new List<Invoice>();
|
||||||
|
foreach (Kunde kunde in kunden)
|
||||||
|
{
|
||||||
|
Invoice invoice = new Invoice();
|
||||||
|
invoice.Language = "de";
|
||||||
|
invoice.VoucherDate = DateTimeConverter(kunde.Bezahldatum); // "2023-02-22T00:00:00.000+01:00"; //
|
||||||
|
invoice.Address = new InvoiceAddress()
|
||||||
|
{
|
||||||
|
Name = kunde.Name,
|
||||||
|
Street = kunde.Strasse + " " + kunde.Hausnummer,
|
||||||
|
City = kunde.Ort,
|
||||||
|
Zip = kunde.Plz,
|
||||||
|
CountryCode = "DE"
|
||||||
|
};
|
||||||
|
invoice.LineItems = new List<InvoiceLineItem>();
|
||||||
|
foreach (var artikel in kunde.Artikels)
|
||||||
|
{
|
||||||
|
invoice.LineItems.Add(new InvoiceLineItem()
|
||||||
|
{
|
||||||
|
Type = "custom",
|
||||||
|
Name = artikel.ENGName + "(" + artikel.Source + ")",
|
||||||
|
Quantity = artikel.Amount,
|
||||||
|
UnitName = "Stück",
|
||||||
|
UnitPrice = new InvoiceLineUnitPrice()
|
||||||
|
{
|
||||||
|
Currency = "EUR",
|
||||||
|
GrossAmount = Convert.ToDecimal(artikel.Preis),
|
||||||
|
TaxRatePercentage = 19
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
invoice.LineItems.Add(new InvoiceLineItem()
|
||||||
|
{
|
||||||
|
Type = "custom",
|
||||||
|
Name = "Versandkosten",
|
||||||
|
Quantity = 1,
|
||||||
|
UnitName = "Stück",
|
||||||
|
UnitPrice = new InvoiceLineUnitPrice()
|
||||||
|
{
|
||||||
|
Currency = "EUR",
|
||||||
|
GrossAmount = PortoPreis[kunde.Versandskosten],
|
||||||
|
TaxRatePercentage = 19
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
invoice.TotalPrice = new TotalPrice() { Currency = "EUR" };
|
||||||
|
invoice.TaxConditions = new TaxConditions() { TaxType = "gross" };
|
||||||
|
invoice.ShippingConditions = new ShippingConditions()
|
||||||
|
{
|
||||||
|
shippingDate = "2023-04-22T00:00:00.000+02:00",
|
||||||
|
shippingType = "delivery"
|
||||||
|
};
|
||||||
|
result.Add(invoice);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
ConsoleApp3/InvoiceService.cs
Normal file
44
ConsoleApp3/InvoiceService.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using ConsoleApp3.DataContracts;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* referalPage: /de/OnePiece
|
||||||
|
username: Skywalkerex
|
||||||
|
userPassword: Magnatpower310!!
|
||||||
|
/de/OnePiece/PostGetAction/User_Login
|
||||||
|
|
||||||
|
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CardmarketBot
|
||||||
|
{
|
||||||
|
class InvoiceService
|
||||||
|
{
|
||||||
|
private readonly WebRequest request;
|
||||||
|
|
||||||
|
public InvoiceService()
|
||||||
|
{
|
||||||
|
request = WebRequest.Create("https://api.lexoffice.io/v1/invoices");
|
||||||
|
request.Method = "POST";
|
||||||
|
request.Headers.Add("Authorization", "Bearer curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r");
|
||||||
|
request.Headers.Add("Accept", "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertInvoice(Invoice invoice)
|
||||||
|
{
|
||||||
|
var json = JsonConvert.SerializeObject(invoice);
|
||||||
|
byte[] bytearray = Encoding.UTF8.GetBytes(json);
|
||||||
|
request.ContentType = "application/json";
|
||||||
|
using var reqStream = request.GetRequestStream();
|
||||||
|
reqStream.Write(bytearray, 0, bytearray.Length);
|
||||||
|
using var response = request.GetResponse();
|
||||||
|
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||||||
|
reqStream.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
ConsoleApp3/Kunde.cs
Normal file
57
ConsoleApp3/Kunde.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
class Kunde
|
||||||
|
{
|
||||||
|
string bestellungID = "";
|
||||||
|
Helper.Porto versandskosten;
|
||||||
|
string name;
|
||||||
|
string strasse;
|
||||||
|
string hausnummer;
|
||||||
|
string plz;
|
||||||
|
string ort;
|
||||||
|
string land;
|
||||||
|
List<Artikel> artikels = new List<Artikel>();
|
||||||
|
public string Bezahldatum { get; set; } = "";
|
||||||
|
|
||||||
|
public string Name { get => name; set => name = value; }
|
||||||
|
public string Strasse { get => strasse; set => strasse = value; }
|
||||||
|
public string Plz { get => plz; set => plz = value; }
|
||||||
|
public string Ort { get => ort; set => ort = value; }
|
||||||
|
public string Land { get => land; set => land = value; }
|
||||||
|
public string BestellungID { get => bestellungID; set => bestellungID = value; }
|
||||||
|
public Helper.Porto Versandskosten { get => versandskosten; set => versandskosten = value; }
|
||||||
|
public string Hausnummer { get => hausnummer; set => hausnummer = value; }
|
||||||
|
internal List<Artikel> Artikels { get => artikels; set => artikels = value; }
|
||||||
|
|
||||||
|
public Kunde(string Name, string Strasse, string Hausnummer, string PLZ, string Ort, string Land)
|
||||||
|
{
|
||||||
|
name = Name;
|
||||||
|
hausnummer = Hausnummer;
|
||||||
|
strasse = Strasse;
|
||||||
|
plz = PLZ;
|
||||||
|
ort = Ort;
|
||||||
|
land = Land;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Paid");
|
||||||
|
hwr.CookieContainer = cookieContainer;
|
||||||
|
hwr.Method = "GET";
|
||||||
|
hwr.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
|
||||||
|
WebResponse wr = hwr.GetResponse();
|
||||||
|
string s = new StreamReader(wr.GetResponseStream()).ReadToEnd();
|
||||||
|
Console.WriteLine(s);
|
||||||
|
|
||||||
|
string GetHashKey(string line)
|
||||||
|
{
|
||||||
|
var x = line.IndexOf("__cmtkn");
|
||||||
|
var d = line.Substring(x + 16);
|
||||||
|
var m = d.IndexOf("\"");
|
||||||
|
var a = d.Substring(0, m);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
31
ConsoleApp3/LexofficeApiAddressesBuilder.cs
Normal file
31
ConsoleApp3/LexofficeApiAddressesBuilder.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* referalPage: /de/OnePiece
|
||||||
|
username: Skywalkerex
|
||||||
|
userPassword: Magnatpower310!!
|
||||||
|
/de/OnePiece/PostGetAction/User_Login
|
||||||
|
|
||||||
|
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CardmarketBot
|
||||||
|
{
|
||||||
|
static class LexofficeApiAddressesBuilder
|
||||||
|
{
|
||||||
|
private static string BaseAddress = @"https://api.lexoffice.io";
|
||||||
|
private static string Invoice = "v1/invoices";
|
||||||
|
|
||||||
|
public static string InvoiceUri(string id)
|
||||||
|
{
|
||||||
|
return $"{BaseAddress}/{Invoice}/{id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string CreateInvoice()
|
||||||
|
{
|
||||||
|
return $"{BaseAddress}/{Invoice}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
84
ConsoleApp3/LexofficeService.cs
Normal file
84
ConsoleApp3/LexofficeService.cs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
using System.Text;
|
||||||
|
using ConsoleApp3.DataContracts;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* referalPage: /de/OnePiece
|
||||||
|
username: Skywalkerex
|
||||||
|
userPassword: Magnatpower310!!
|
||||||
|
/de/OnePiece/PostGetAction/User_Login
|
||||||
|
|
||||||
|
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CardmarketBot
|
||||||
|
{
|
||||||
|
class LexofficeService
|
||||||
|
{
|
||||||
|
private readonly HttpClient _client;
|
||||||
|
private readonly Random _random = new();
|
||||||
|
|
||||||
|
public LexofficeService()
|
||||||
|
{
|
||||||
|
_client = new HttpClient
|
||||||
|
{
|
||||||
|
DefaultRequestHeaders =
|
||||||
|
{
|
||||||
|
{ "Authorization", "Bearer curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r" },
|
||||||
|
{ "Accept", "application/json" }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test()
|
||||||
|
{
|
||||||
|
var d = GetInvoiceAsync("d47936c1-71c6-4e22-b394-3630d7354ebf");
|
||||||
|
var m = d.Result;
|
||||||
|
Console.WriteLine(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void m(Invoice invoice)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void WriteInvoice(Invoice invoice)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var jsonSerializerSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Ignore
|
||||||
|
};
|
||||||
|
|
||||||
|
var s = JsonConvert.SerializeObject(invoice, jsonSerializerSettings);
|
||||||
|
|
||||||
|
var content = new StringContent(invoice.ToString(), Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
var uri = LexofficeApiAddressesBuilder.CreateInvoice();
|
||||||
|
var result = await _client.PostAsync(uri, content);
|
||||||
|
Console.WriteLine(result.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<Invoice> GetInvoiceAsync(string id)
|
||||||
|
{
|
||||||
|
var uri = LexofficeApiAddressesBuilder.InvoiceUri(id);
|
||||||
|
var response = await _client.GetAsync(uri).ConfigureAwait(false);
|
||||||
|
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var contents = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
var jsonSerializerSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Ignore
|
||||||
|
};
|
||||||
|
return JsonConvert.DeserializeObject<Invoice>(contents, jsonSerializerSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,496 +1,37 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
using OpenQA.Selenium.Chrome;
|
|
||||||
using OpenQA.Selenium;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using static System.Collections.Specialized.BitVector32;
|
using static System.Collections.Specialized.BitVector32;
|
||||||
using ConsoleApp3.DataContracts;
|
using ConsoleApp3.DataContracts;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* referalPage: /de/OnePiece
|
|
||||||
username: Skywalkerex
|
|
||||||
userPassword: Magnatpower310!!
|
|
||||||
/de/OnePiece/PostGetAction/User_Login
|
|
||||||
|
|
||||||
curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace CardmarketBot
|
namespace CardmarketBot
|
||||||
{
|
{
|
||||||
|
|
||||||
static class LexofficeApiAddressesBuilder
|
|
||||||
{
|
|
||||||
private static string BaseAddress = @"https://api.lexoffice.io";
|
|
||||||
private static string Invoice = "v1/invoices";
|
|
||||||
|
|
||||||
public static string InvoiceUri(string id)
|
|
||||||
{
|
|
||||||
return $"{BaseAddress}/{Invoice}/{id}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string CreateInvoice()
|
|
||||||
{
|
|
||||||
return $"{BaseAddress}/{Invoice}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class InvoiceService
|
|
||||||
{
|
|
||||||
private readonly WebRequest request;
|
|
||||||
|
|
||||||
public InvoiceService()
|
|
||||||
{
|
|
||||||
request = WebRequest.Create("https://api.lexoffice.io/v1/invoices");
|
|
||||||
request.Method = "POST";
|
|
||||||
request.Headers.Add("Authorization", "Bearer curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r");
|
|
||||||
request.Headers.Add("Accept", "application/json");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertInvoice(Invoice invoice)
|
|
||||||
{
|
|
||||||
var json = JsonConvert.SerializeObject(invoice);
|
|
||||||
byte[] bytearray = Encoding.UTF8.GetBytes(json);
|
|
||||||
request.ContentType = "application/json";
|
|
||||||
using var reqStream = request.GetRequestStream();
|
|
||||||
reqStream.Write(bytearray, 0, bytearray.Length);
|
|
||||||
using var response = request.GetResponse();
|
|
||||||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
|
||||||
reqStream.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LexofficeService
|
|
||||||
{
|
|
||||||
private readonly HttpClient _client;
|
|
||||||
private readonly Random _random = new();
|
|
||||||
|
|
||||||
public LexofficeService()
|
|
||||||
{
|
|
||||||
_client = new HttpClient
|
|
||||||
{
|
|
||||||
DefaultRequestHeaders =
|
|
||||||
{
|
|
||||||
{ "Authorization", "Bearer curbpJUJmtup1t.Tq0awbHIhIRwhzMW7vrsWxLAJu.pI9X4r" },
|
|
||||||
{ "Accept", "application/json" }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test()
|
|
||||||
{
|
|
||||||
var d = GetInvoiceAsync("d47936c1-71c6-4e22-b394-3630d7354ebf");
|
|
||||||
var m = d.Result;
|
|
||||||
Console.WriteLine(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void m(Invoice invoice)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void WriteInvoice(Invoice invoice)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var jsonSerializerSettings = new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
MissingMemberHandling = MissingMemberHandling.Ignore
|
|
||||||
};
|
|
||||||
|
|
||||||
var s = JsonConvert.SerializeObject(invoice, jsonSerializerSettings);
|
|
||||||
|
|
||||||
var content = new StringContent(invoice.ToString(), Encoding.UTF8, "application/json");
|
|
||||||
|
|
||||||
var uri = LexofficeApiAddressesBuilder.CreateInvoice();
|
|
||||||
var result = await _client.PostAsync(uri, content);
|
|
||||||
Console.WriteLine(result.Content);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<Invoice> GetInvoiceAsync(string id)
|
|
||||||
{
|
|
||||||
var uri = LexofficeApiAddressesBuilder.InvoiceUri(id);
|
|
||||||
var response = await _client.GetAsync(uri).ConfigureAwait(false);
|
|
||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
|
|
||||||
var contents = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
|
||||||
|
|
||||||
var jsonSerializerSettings = new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
MissingMemberHandling = MissingMemberHandling.Ignore
|
|
||||||
};
|
|
||||||
return JsonConvert.DeserializeObject<Invoice>(contents, jsonSerializerSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal class Programm
|
internal class Programm
|
||||||
{
|
{
|
||||||
static string DateTimeConverter(string input)
|
|
||||||
{
|
|
||||||
//2023-06-20T11:30:00"
|
|
||||||
//2023-02-22T00:00:00.000+01:0
|
|
||||||
string datum = input.Substring(0, 10);
|
|
||||||
string uhrzeit = input.Substring(10, input.Length - 10);
|
|
||||||
input = string.Format("{0} {1}", datum, uhrzeit);
|
|
||||||
DateTime converted = Convert.ToDateTime(input);
|
|
||||||
var format = "yyyy-MM-ddTHH:mm:ssK";
|
|
||||||
string res = converted.ToString(format);
|
|
||||||
return string.Format("{0}.000+01:00", res);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// Result 2023-02-22T00:00:00.000+01:00
|
// Kunden aus Cardmarket erstellen
|
||||||
/*string input = "20.06.202311:30";
|
|
||||||
|
|
||||||
|
|
||||||
var localTime = new DateTime(2022, 1, 13, 16, 25, 35, 125, DateTimeKind.Local);
|
|
||||||
|
|
||||||
Console.WriteLine(converted.ToString(format));
|
|
||||||
|
|
||||||
Debugger.Break();
|
|
||||||
return;
|
|
||||||
*/
|
|
||||||
|
|
||||||
Dictionary<string, Helper.Porto> portoberechnung = new Dictionary<string, Helper.Porto>()
|
|
||||||
{
|
|
||||||
{"1,15 €", Helper.Porto.BRIEF085 },
|
|
||||||
{"1,30 €", Helper.Porto.BRIEF100 },
|
|
||||||
{"2,10 €", Helper.Porto.BRIEF160 },
|
|
||||||
{"3,25 €", Helper.Porto.BRIEF275 },
|
|
||||||
{"2,60 €", Helper.Porto.PRIO210 },
|
|
||||||
{"3,20 €", Helper.Porto.PRIO270 },
|
|
||||||
};
|
|
||||||
|
|
||||||
Dictionary<Helper.Porto, decimal> PortoPreis = new Dictionary<Helper.Porto, decimal>()
|
|
||||||
{
|
|
||||||
{Helper.Porto.BRIEF085, 1.15m },
|
|
||||||
{Helper.Porto.BRIEF100, 1.30m },
|
|
||||||
{Helper.Porto.BRIEF160, 2.10m },
|
|
||||||
{Helper.Porto.BRIEF275, 3.25m },
|
|
||||||
{Helper.Porto.PRIO210, 2.60m },
|
|
||||||
{Helper.Porto.PRIO270, 3.20m }
|
|
||||||
};
|
|
||||||
ChromeOptions options = new ChromeOptions();
|
|
||||||
options.AddArgument("start-maximized");
|
|
||||||
IWebDriver cd = new ChromeDriver(options);
|
|
||||||
cd.Url = @"https://www.cardmarket.com/de/OnePiece";
|
|
||||||
|
|
||||||
cd.Navigate();
|
|
||||||
cd.FindElement(By.CssSelector("#CookiesConsent > div > div > form > button")).Click();
|
|
||||||
cd.FindElement(By.Name("username")).Click();
|
|
||||||
cd.FindElement(By.Name("username")).SendKeys("Skywalkerex");
|
|
||||||
cd.FindElement(By.Name("userPassword")).Click();
|
|
||||||
|
|
||||||
|
|
||||||
cd.FindElement(By.Name("userPassword")).SendKeys("Magnatpower310!!");
|
|
||||||
cd.FindElement(By.CssSelector("#header-login > input.btn.AB-login-btn.btn-outline-primary.btn-sm")).Click();
|
|
||||||
|
|
||||||
|
|
||||||
CookieContainer cookieContainer = new CookieContainer();
|
|
||||||
foreach (var c in cd.Manage().Cookies.AllCookies)
|
|
||||||
{
|
|
||||||
string name = c.Name;
|
|
||||||
string value = c.Value;
|
|
||||||
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");
|
|
||||||
|
|
||||||
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>();
|
List<Kunde> kunden = new List<Kunde>();
|
||||||
|
CardMarketParser cardMarketParser = new CardMarketParser();
|
||||||
|
kunden = cardMarketParser.ParseCardMarket();
|
||||||
|
|
||||||
int maxCounter = 2;
|
// Rechnungen generieren
|
||||||
int counter = 0;
|
|
||||||
foreach (string id in ids)
|
|
||||||
{
|
|
||||||
if (counter > maxCounter) break;
|
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(5));
|
|
||||||
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"));
|
|
||||||
|
|
||||||
Kunde kunde = Helper.ConvertToKunde(element.Text);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
// 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];
|
|
||||||
kunde.BestellungID = id;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Artikeln
|
|
||||||
element = cd.FindElement(By.XPath("/html/body/main/section/div/div[1]/div/div[5]/table/tbody"));
|
|
||||||
string artikeln = element.Text;
|
|
||||||
kunde.Artikels = Helper.ParseArtikeln(element.Text);
|
|
||||||
|
|
||||||
|
|
||||||
kunden.Add(kunde);
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Invoice> rechnungen = new List<Invoice>();
|
List<Invoice> rechnungen = new List<Invoice>();
|
||||||
|
InvoiceParser invoiceParser = new InvoiceParser(kunden);
|
||||||
foreach(Kunde kunde in kunden)
|
rechnungen = invoiceParser.GetInvoices();
|
||||||
{
|
|
||||||
Invoice invoice = new Invoice();
|
|
||||||
invoice.Language = "de";
|
|
||||||
invoice.VoucherDate = DateTimeConverter(kunde.Bezahldatum); // "2023-02-22T00:00:00.000+01:00"; //
|
|
||||||
invoice.Address = new InvoiceAddress()
|
|
||||||
{
|
|
||||||
Name = kunde.Name,
|
|
||||||
Street = kunde.Strasse + " " + kunde.Hausnummer,
|
|
||||||
City = kunde.Ort,
|
|
||||||
Zip = kunde.Plz,
|
|
||||||
CountryCode = "DE"
|
|
||||||
};
|
|
||||||
invoice.LineItems = new List<InvoiceLineItem>();
|
|
||||||
foreach(var artikel in kunde.Artikels)
|
|
||||||
{
|
|
||||||
invoice.LineItems.Add(new InvoiceLineItem()
|
|
||||||
{
|
|
||||||
Type = "custom",
|
|
||||||
Name = artikel.ENGName + "(" + artikel.Source + ")",
|
|
||||||
Quantity = artikel.Amount,
|
|
||||||
UnitName = "Stück",
|
|
||||||
UnitPrice = new InvoiceLineUnitPrice()
|
|
||||||
{
|
|
||||||
Currency = "EUR",
|
|
||||||
GrossAmount = Convert.ToDecimal(artikel.Preis),
|
|
||||||
TaxRatePercentage = 19
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
invoice.LineItems.Add(new InvoiceLineItem()
|
|
||||||
{
|
|
||||||
Type = "custom",
|
|
||||||
Name = "Versandkosten",
|
|
||||||
Quantity = 1,
|
|
||||||
UnitName = "Stück",
|
|
||||||
UnitPrice = new InvoiceLineUnitPrice()
|
|
||||||
{
|
|
||||||
Currency = "EUR",
|
|
||||||
GrossAmount = PortoPreis[kunde.Versandskosten],
|
|
||||||
TaxRatePercentage = 19
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
invoice.TotalPrice = new TotalPrice() { Currency = "EUR" };
|
|
||||||
invoice.TaxConditions = new TaxConditions() { TaxType = "gross" };
|
|
||||||
invoice.ShippingConditions = new ShippingConditions()
|
|
||||||
{
|
|
||||||
shippingDate = "2023-04-22T00:00:00.000+02:00",
|
|
||||||
shippingType = "delivery"
|
|
||||||
};
|
|
||||||
rechnungen.Add(invoice);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var item in rechnungen)
|
foreach (var item in rechnungen)
|
||||||
{
|
{
|
||||||
InvoiceService invoiceService = new InvoiceService();
|
InvoiceService invoiceService = new InvoiceService();
|
||||||
invoiceService.InsertInvoice(item);
|
invoiceService.InsertInvoice(item);
|
||||||
}
|
}
|
||||||
Debugger.Break();
|
|
||||||
|
|
||||||
|
|
||||||
// Post CSV Erstellen
|
// Post CSV Erstellen
|
||||||
IEnumerable<IGrouping<Helper.Porto, Kunde>> groupedPorto = kunden.GroupBy(x => x.Versandskosten).Distinct();
|
DeutschePost deutschePost = new DeutschePost(kunden);
|
||||||
|
deutschePost.GenerateCSV();
|
||||||
|
|
||||||
foreach (IGrouping<Helper.Porto, Kunde> gkunde in groupedPorto)
|
|
||||||
{
|
|
||||||
//FileStream stream = File.Create(string.Format("test_{0}.csv", gkunde.Key.ToString()));
|
|
||||||
Helper.Porto porto = gkunde.Key;
|
|
||||||
using (StreamWriter writer = new StreamWriter(string.Format("./test_{0}.csv", gkunde.Key.ToString()), false, Encoding.Latin1))
|
|
||||||
{
|
|
||||||
|
|
||||||
string header = "NAME;ZUSATZ;STRASSE;NUMMER;PLZ;STADT;LAND;ADRESS_TYP;REFERENZ";
|
|
||||||
writer.WriteLine(header);
|
|
||||||
string absender = "W&W TECH UG;Lukas Winkelmann;Schwedenschanze;70;49808;LINGEN;DEU;HOUSE";
|
|
||||||
writer.WriteLine(absender);
|
|
||||||
foreach (Kunde n in gkunde)
|
|
||||||
{
|
|
||||||
string empfanger = string.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8}",
|
|
||||||
n.Name,
|
|
||||||
"",
|
|
||||||
n.Strasse,
|
|
||||||
n.Hausnummer,
|
|
||||||
n.Plz,
|
|
||||||
n.Ort,
|
|
||||||
"DEU",
|
|
||||||
//n.Land,
|
|
||||||
"HOUSE",
|
|
||||||
n.BestellungID
|
|
||||||
);
|
|
||||||
writer.WriteLine(empfanger);
|
|
||||||
}
|
|
||||||
writer.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Fertig");
|
Console.WriteLine("Fertig");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Helper
|
|
||||||
{
|
|
||||||
public enum Porto
|
|
||||||
{
|
|
||||||
BRIEF085,
|
|
||||||
BRIEF100,
|
|
||||||
BRIEF160,
|
|
||||||
BRIEF275,
|
|
||||||
PRIO210,
|
|
||||||
PRIO270
|
|
||||||
}
|
|
||||||
internal static Kunde ConvertToKunde(string text)
|
|
||||||
{
|
|
||||||
|
|
||||||
string[] datas = text.Split("\r\n");
|
|
||||||
string name = datas[0];
|
|
||||||
string adresseUNDHausnummer = datas[1];
|
|
||||||
string plzUNDOrt = datas[2];
|
|
||||||
string land = datas[3];
|
|
||||||
|
|
||||||
datas = plzUNDOrt.Split(" ");
|
|
||||||
string plz = datas[0];
|
|
||||||
string ort = datas[1];
|
|
||||||
|
|
||||||
datas = adresseUNDHausnummer.Split(" ");
|
|
||||||
string strasse = "";
|
|
||||||
for (int i = 0; i < datas.Length - 1; i++)
|
|
||||||
{
|
|
||||||
strasse += datas[i] + " ";
|
|
||||||
}
|
|
||||||
strasse = strasse.Trim();
|
|
||||||
string hausnummer = datas[datas.Length - 1];
|
|
||||||
|
|
||||||
return new Kunde(name, strasse, hausnummer, plz, ort, land);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static List<Artikel> ParseArtikeln(string text)
|
|
||||||
{
|
|
||||||
List<Artikel> result = new List<Artikel>();
|
|
||||||
string[] datas = text.Split("\r\n");
|
|
||||||
|
|
||||||
|
|
||||||
int anzahl = datas.Length / 6;
|
|
||||||
|
|
||||||
for (int i = 0; i < datas.Length; i += 6)
|
|
||||||
{
|
|
||||||
Artikel temp = new Artikel();
|
|
||||||
var xFound = datas[i].IndexOf("x");
|
|
||||||
var am = datas[i].Substring(0, xFound);
|
|
||||||
temp.Amount = Convert.ToInt32(am);
|
|
||||||
temp.GERName = datas[i].Substring(xFound + 1);
|
|
||||||
temp.ENGName = datas[i + 1];
|
|
||||||
temp.CardNumber = datas[i + 2];
|
|
||||||
temp.Source = datas[i + 3];
|
|
||||||
temp.Raritaet = datas[i + 4];
|
|
||||||
temp.Preis = datas[i + 5].Split(' ')[0];
|
|
||||||
result.Add(temp);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class Artikel
|
|
||||||
{
|
|
||||||
public int Amount { get; set; }
|
|
||||||
public string GERName { get; set; } = "";
|
|
||||||
public string ENGName { get; set; } = "";
|
|
||||||
public string CardNumber { get; set; } = "";
|
|
||||||
public string Source { get; set; } = "";
|
|
||||||
public string Raritaet { get; set; } = "";
|
|
||||||
public string Preis { get; set; } = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
class Kunde
|
|
||||||
{
|
|
||||||
string bestellungID = "";
|
|
||||||
Helper.Porto versandskosten;
|
|
||||||
string name;
|
|
||||||
string strasse;
|
|
||||||
string hausnummer;
|
|
||||||
string plz;
|
|
||||||
string ort;
|
|
||||||
string land;
|
|
||||||
List<Artikel> artikels = new List<Artikel>();
|
|
||||||
public string Bezahldatum { get; set; } = "";
|
|
||||||
|
|
||||||
public string Name { get => name; set => name = value; }
|
|
||||||
public string Strasse { get => strasse; set => strasse = value; }
|
|
||||||
public string Plz { get => plz; set => plz = value; }
|
|
||||||
public string Ort { get => ort; set => ort = value; }
|
|
||||||
public string Land { get => land; set => land = value; }
|
|
||||||
public string BestellungID { get => bestellungID; set => bestellungID = value; }
|
|
||||||
public Helper.Porto Versandskosten { get => versandskosten; set => versandskosten = value; }
|
|
||||||
public string Hausnummer { get => hausnummer; set => hausnummer = value; }
|
|
||||||
internal List<Artikel> Artikels { get => artikels; set => artikels = value; }
|
|
||||||
|
|
||||||
public Kunde(string Name, string Strasse, string Hausnummer, string PLZ, string Ort, string Land)
|
|
||||||
{
|
|
||||||
name = Name;
|
|
||||||
hausnummer = Hausnummer;
|
|
||||||
strasse = Strasse;
|
|
||||||
plz = PLZ;
|
|
||||||
ort = Ort;
|
|
||||||
land = Land;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(@"https://www.cardmarket.com/de/OnePiece/Orders/Sales/Paid");
|
|
||||||
hwr.CookieContainer = cookieContainer;
|
|
||||||
hwr.Method = "GET";
|
|
||||||
hwr.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
|
|
||||||
WebResponse wr = hwr.GetResponse();
|
|
||||||
string s = new StreamReader(wr.GetResponseStream()).ReadToEnd();
|
|
||||||
Console.WriteLine(s);
|
|
||||||
|
|
||||||
string GetHashKey(string line)
|
|
||||||
{
|
|
||||||
var x = line.IndexOf("__cmtkn");
|
|
||||||
var d = line.Substring(x + 16);
|
|
||||||
var m = d.IndexOf("\"");
|
|
||||||
var a = d.Substring(0, m);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
Reference in New Issue
Block a user