Compare commits
1 Commits
master
...
incomplete
Author | SHA1 | Date |
---|---|---|
Dom | b50d5837ab |
|
@ -1,57 +0,0 @@
|
|||
package paxan
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/jlaffaye/ftp"
|
||||
)
|
||||
|
||||
func DownloadFTP(user string, password string, path string) error {
|
||||
c, err := ftp.Dial("paxan-shop.de:21", ftp.DialWithTimeout(5*time.Second))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.Login(user, password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Quit()
|
||||
|
||||
//c.ChangeDir("desiredDir")
|
||||
|
||||
files, err := c.List("/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if file.Type != ftp.EntryTypeFile {
|
||||
continue
|
||||
}
|
||||
res, err := c.Retr(file.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outFile, err := os.Create(filepath.Join(path, file.Name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer outFile.Close()
|
||||
|
||||
_, err = io.Copy(outFile, res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res.Close()
|
||||
|
||||
err = os.Chtimes(filepath.Join(path, file.Name), file.Time, file.Time)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
145
webActions.go
145
webActions.go
|
@ -33,6 +33,26 @@ type paxanWebOrderEntry struct {
|
|||
Total2 string
|
||||
}
|
||||
|
||||
// WebOrder -
|
||||
type WebOrder struct {
|
||||
InvoiceNumber int
|
||||
Type string
|
||||
Date string
|
||||
Items2 []paxanWebOrderEntry
|
||||
/*Items []struct {
|
||||
Position string
|
||||
ArticleNumber int
|
||||
Description string
|
||||
ProductLink string
|
||||
Amount string
|
||||
Price string
|
||||
Total string
|
||||
Amount2 string
|
||||
Price2 string
|
||||
Total2 string
|
||||
}*/
|
||||
}
|
||||
|
||||
func convertStringToBool(value string) bool {
|
||||
if value == "X" {
|
||||
return true
|
||||
|
@ -270,71 +290,88 @@ func ExportNewOrders(client *http.Client, lastOrder int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type paxanWebClient struct {
|
||||
client *http.Client
|
||||
baseUrl string
|
||||
// GetOrders - Get orders
|
||||
func GetOrders(client *http.Client, lastOrder int) ([]WebOrder, error) {
|
||||
orders, err := paxanGetOrders(client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var objects []WebOrder
|
||||
|
||||
for _, order := range orders {
|
||||
if order.InvoiceNumber <= lastOrder {
|
||||
continue
|
||||
}
|
||||
|
||||
orderDetails, err := paxanGetOrderDetails(client, order.InvoiceNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
objects = append(objects, WebOrder{
|
||||
order.InvoiceNumber, order.Type, order.Date, orderDetails,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func Connect(user string, password string) (paxanWebClient, error) {
|
||||
var pwc paxanWebClient
|
||||
// New http client with cookie
|
||||
cookieJar, _ := cookiejar.New(nil)
|
||||
pwc.client = &http.Client{
|
||||
Jar: cookieJar,
|
||||
}
|
||||
|
||||
pwc.baseUrl = "https://www.hakopaxan-shop.de/html"
|
||||
|
||||
loginvalues := make(url.Values)
|
||||
loginvalues.Set("performAction", "processLogin")
|
||||
loginvalues.Set("personlogin", user)
|
||||
loginvalues.Set("personpwd", password)
|
||||
loginvalues.Set("firma", "paxan")
|
||||
_, err := pwc.client.PostForm("https://www.hakopaxan-shop.de/html/login.html", loginvalues)
|
||||
//TODO make it more like a class -> func (p *paxan) something(foo) {}
|
||||
/*
|
||||
func selectWishlist(client *http.Client, wishlistNumber int) error {
|
||||
url := "https://www.hakopaxan-shop.de/html/customerDocument-customerDocumentId-" + strconv.Itoa(orderNumber) + "-customerDocumentListId-invoice-requestedPeriod-365.html"
|
||||
r, err := client.Get(url)
|
||||
if err != nil {
|
||||
return paxanWebClient{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pwc, nil
|
||||
}
|
||||
|
||||
func (w *paxanWebClient) Disconnect() error {
|
||||
_, err := w.client.Get("https://www.hakopaxan-shop.de/html/logout-performAction-processLogout.html")
|
||||
doc, err := goquery.NewDocumentFromReader(io.Reader(r.Body))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Go through table row by row
|
||||
doc.Find(".tableRowGroup").Each(func(i int, s *goquery.Selection) {
|
||||
var row []string
|
||||
s.Find(".tableCell").Each(func(j int, s *goquery.Selection) {
|
||||
text := s.Contents().Text()
|
||||
// Column 3 contains some more info
|
||||
if j == 2 {
|
||||
text = s.Find(".lineItemName").Text()
|
||||
// Search for the link to the product page
|
||||
linkTag := s.Find("a")
|
||||
link, _ := linkTag.Attr("href")
|
||||
row = append(row, link)
|
||||
}
|
||||
|
||||
text = strings.Replace(text, "\n", "", -1)
|
||||
text = strings.TrimSpace(text)
|
||||
row = append(row, text)
|
||||
|
||||
})
|
||||
|
||||
num, _ := strconv.Atoi(row[1])
|
||||
n := paxanWebOrderEntry{Position: row[0],
|
||||
ArticleNumber: num,
|
||||
Description: row[3],
|
||||
ProductLink: row[2],
|
||||
Amount: row[4],
|
||||
Price: row[5],
|
||||
Total: row[6],
|
||||
Amount2: row[7],
|
||||
Price2: row[8],
|
||||
Total2: row[9]}
|
||||
list = append(list, n)
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *paxanWebClient) selectWishlist(id string) error {
|
||||
_, err := w.client.Get("https://www.hakopaxan-shop.de/html/wishlist-wishlist__switch-" + id + ".html")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func AddArticleWishlist(client *http.Client, wishlistNumber int, articleNumber int) error {
|
||||
// select wishlist (if not already selected)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *paxanWebClient) AddToWishlist(artnr string, wishlist string) error {
|
||||
//w.getWishList()
|
||||
w.selectWishlist("10")
|
||||
//w.client.PostForm()
|
||||
|
||||
formvalues := make(url.Values)
|
||||
//formvalues.Set("x", "10")
|
||||
//formvalues.Set("y", "8")
|
||||
formvalues.Set("itemId", artnr)
|
||||
formvalues.Set("wishlist_add_position", "true")
|
||||
formvalues.Set("wvarid", artnr)
|
||||
formvalues.Set("qty", "1")
|
||||
formvalues.Set("me", "0")
|
||||
_, err := w.client.PostForm("https://www.hakopaxan-shop.de/html/item.html", formvalues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
//set to old wishlist
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue