Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Last active March 26, 2018 01:35
Show Gist options
  • Save nijikokun/59e714dac3fccc0e691ecff18eb75b9f to your computer and use it in GitHub Desktop.
Save nijikokun/59e714dac3fccc0e691ecff18eb75b9f to your computer and use it in GitHub Desktop.
Open <Trade Macro Folder>/resources/ahk/TradeMacro.ahk and replace the following functions, then reload or restart TradeMacro:
TradeFunc_DoPoePricesRequest(RawItemData, ByRef retCurl) {
EncodedItemData := StringToBase64UriEncoded(RawItemData, true)
postData := "l=" UriEncode(TradeGlobals.Get("LeagueName")) "&i=" EncodedItemData "&w=1"
payLength := StrLen(postData)
url := "https://www.poeprices.info/api"
; url .= postData
; TradeFunc_OpenUrlInBrowser(url)
options := "RequestType: GET"
options .= "`n" "ReturnHeaders: skip"
options .= "`n" "TimeOut: 20"
reqHeaders := []
reqHeaders.push("Host: www.poeprices.info")
reqHeaders.push("Connection: keep-alive")
reqHeaders.push("Cache-Control: max-age=0")
reqHeaders.push("Origin: https://poeprices.info")
reqHeaders.push("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
ShowToolTip("Getting price prediction... ")
retCurl := true
response := PoEScripts_Download(url, postData, reqHeaders, options, false, false, false, "", "", true, retCurl)
If (TradeOpts.Debug) {
FileDelete, %A_ScriptDir%\temp\DebugSearchOutput.html
FileAppend, %response%, %A_ScriptDir%\temp\DebugSearchOutput.html
}
responseObj := {}
; Try {
; responseObj := JSON.Load(response)
; } Catch e {
; responseObj.failed := "ERROR: Parsing response failed, invalid JSON! "
; }
If (not isObject(responseObj)) {
responseObj := {}
}
If (not StrLen(response)) {
responseObj.failed := "ERROR: Parsing response failed, empty response! "
}
RegExMatch(response, "price_highlight"">(?P<Price>[^<]+)", Match)
responseObj.min_max := MatchPrice
RegExMatch(response, "td class=""price_highlight"">(?P<Text>[a-z]+)", Match)
responseObj.currency := MatchText
RegExMatch(response, "span class=""price_highlight"">(?P<Value>[^<]+)", Match)
responseObj.recommended := MatchValue
responseObj.added := {}
responseObj.added.encodedData := EncodedItemData
responseObj.added.league := TradeGlobals.Get("LeagueName")
responseObj.added.requestUrl := url "?" postData
responseObj.added.browserUrl := url "?" postData
Return responseObj
}
TradeFunc_ParsePoePricesInfoData(response) {
Global Item, ItemData, TradeOpts
LeagueName := TradeGlobals.Get("LeagueName")
Name := (Item.IsRare and not Item.IsMap) ? Item.Name " " Item.BaseName : Item.Name
headLine := Trim(StrReplace(Name, "Superior", ""))
; add corrupted tag
If (Item.IsCorrupted) {
headLine .= " [Corrupted] "
}
; add gem quality and level
If (Item.IsGem) {
headLine := Item.Name ", Q" Item.Quality "%"
If (Item.Level >= 16) {
headLine := Item.Name ", " Item.Level "`/" Item.Quality "%"
}
}
; add item sockets and links
If (ItemData.Sockets >= 5) {
headLine := Name " " ItemData.Sockets "s" ItemData.Links "l"
}
If (showItemLevel) {
headLine .= ", iLvl: " iLvl
}
headLine .= ", (" LeagueName ")"
; Gui, PredictedPricing:Add, Text, x+5 yp+0 BackgroundTrans, % Trim(data.min_max) Trim(data.currency)
; Gui, PredictedPricing:Add, Text, x20 w90 y+5 BackgroundTrans, % "Recommended: " Trim(data.recommended)
lines := []
lines.push(["~~ Predicted item pricing (poeprices.info) ~~", "center", true])
lines.push([headLine, "left", true])
lines.push(["", "left"])
lines.push([" Price Range: " Trim(response.min_max) " " Trim(response.currency), "left"])
lines.push([" Recommended: " Trim(response.recommended), "left"])
lines.push(["", "left", true])
lines.push(["", "left"])
maxWidth := 0
For i, line in lines {
maxWidth := StrLen(line[1]) > maxWidth ? StrLen(line[1]) : maxWidth
}
Title := ""
For i, line in lines {
If (RegExMatch(line[2], "i)center")) {
diff := maxWidth - StrLen(line[1])
line[1] := StrPad(line[1], maxWidth - Floor(diff / 2), "left")
}
If (RegExMatch(line[2], "i)right")) {
line[1] := StrPad(line[1], maxWidth, "left")
}
Title .= line[1] "`n"
If (line[3]) {
seperator := ""
Loop, % maxWidth {
seperator .= "-"
}
Title .= seperator "`n"
}
}
Return Title
}
TradeFunc_ShowPredictedPricingFeedbackUI(data) {
Global
_Name := (Item.IsRare and not Item.IsMap) ? Item.Name " " Item.BaseName : Item.Name
_headLine := Trim(StrReplace(_Name, "Superior", ""))
; add corrupted tag
If (Item.IsCorrupted) {
_headLine .= " [Corrupted] "
}
; add gem quality and level
If (Item.IsGem) {
_headLine := Item.Name ", Q" Item.Quality "%"
If (Item.Level >= 16) {
_headLine := Item.Name ", " Item.Level "`/" Item.Quality "%"
}
}
; add item sockets and links
If (ItemData.Sockets >= 5) {
_headLine := _Name " " ItemData.Sockets "s" ItemData.Links "l"
}
If (showItemLevel) {
_headLine .= ", iLvl: " iLvl
}
_headLine .= ", (" TradeGlobals.Get("LeagueName") ")"
Gui, PredictedPricing:Destroy
Gui, PredictedPricing:Margin, 10, 10
Gui, PredictedPricing:Font, bold s8, Verdana
Gui, PredictedPricing:Add, Text, BackgroundTrans, Priced using machine learning algorithms.
Gui, PredictedPricing:Add, Text, BackgroundTrans x+5 yp+0 cRed, (Close with ESC)
Gui, PredictedPricing:Add, GroupBox, w400 h200 y+10 x10, Results
Gui, PredictedPricing:Font, norm s10, Consolas
Gui, PredictedPricing:Add, Text, yp+25 x20 w380 BackgroundTrans, % _headLine
Gui, PredictedPricing:Font, norm bold, Consolas
Gui, PredictedPricing:Add, Text, x20 w90 y+10 BackgroundTrans, % "Price range: "
Gui, PredictedPricing:Font, norm, Consolas
Gui, PredictedPricing:Add, Text, x+5 yp+0 BackgroundTrans, % Trim(data.min_max) Trim(data.currency)
Gui, PredictedPricing:Add, Text, x20 w90 y+5 BackgroundTrans, % "Recommended: " Trim(data.recommended)
; Gui, PredictedPricing:Add, Text, x+5 yp+0 BackgroundTrans, % Round(Trim(data.min), 2) " ~ " Round(Trim(data.max), 2) " " Trim(data.currency)
_url := data.added.browserUrl
Gui, PredictedPricing:Add, Link, x245 y199 cBlue BackgroundTrans, <a href="%_url%">Open on poeprices.info</a>
; Gui, PredictedPricing:Font, norm s8 italic, Verdana
; Gui, PredictedPricing:Add, Text, BackgroundTrans x15 y135 w390, % "You can disable this GUI in favour of a simple result tooltip. Settings menu -> under 'Search' group. Or even disable this predicted search entirely."
; Gui, PredictedPricing:Font, bold s8, Verdana
; Gui, PredictedPricing:Add, GroupBox, w400 h230 y180 x10, Feedback
; Gui, PredictedPricing:Font, norm, Verdana
; Gui, PredictedPricing:Add, Text, x20 yp+25 BackgroundTrans, You think the predicted price range is?
; Gui, PredictedPricing:Add, Progress, x16 yp+18 w2 h56 BackgroundRed hwndPredictedPricingHiddenControl1
; GuiControl, Hide, % PredictedPricingHiddenControl1
; Gui, PredictedPricing:Add, Radio, x20 yp+2 vPredictionPricingRadio1 Group BackgroundTrans, Low
; Gui, PredictedPricing:Add, Radio, x20 yp+20 vPredictionPricingRadio2 BackgroundRed, Fair
; Gui, PredictedPricing:Add, Radio, x20 yp+20 vPredictionPricingRadio3 BackgroundTrans, High
; Gui, PredictedPricing:Add, Text, x20 yp+30 BackgroundTrans, % "Add comment (max. 1000 characters):"
; Gui, PredictedPricing:Add, Edit, x20 yp+20 w380 r4 limit1000 vPredictedPricingComment,
; Gui, PredictedPricing:Add, Text, x100 y+10 cRed hwndPredictedPricingHiddenControl2, Please select a rating first!
; GuiControl, Hide, % PredictedPricingHiddenControl2
; Gui, PredictedPricing:Add, Button, x260 w90 yp-5 gPredictedPricingSendFeedback, Send && Close
; Gui, PredictedPricing:Add, Button, x+11 w40 gPredictedPricingClose, Close
; Gui, PredictedPricing:Font, bold s8, Verdana
; Gui, PredictedPricing:Add, Text, x15 y+20 cGreen BackgroundTrans, % "This feature is powered by poeprices.info!"
; Gui, PredictedPricing:Font, norm, Verdana
; Gui, PredictedPricing:Add, Link, x15 y+5 cBlue BackgroundTrans, <a href="https://www.paypal.me/poeprices/5">Support them via PayPal</a>
; Gui, PredictedPricing:Add, Text, x+5 yp+0 cDefault BackgroundTrans, % "or"
; Gui, PredictedPricing:Add, Link, x+5 yp+0 cBlue BackgroundTrans, <a href="https://www.patreon.com/bePatron?u=5966037">Patreon</a>
; invisible fields
Gui, PredictedPricing:Add, Edit, x+0 yp+0 w0 h0 ReadOnly vPredictedPricingEncodedData, % data.added.encodedData
Gui, PredictedPricing:Add, Edit, x+0 yp+0 w0 h0 ReadOnly vPredictedPricingLeague, % data.added.League
Gui, PredictedPricing:Add, Edit, x+0 yp+0 w0 h0 ReadOnly vPredictedPricingMin, % data.min
Gui, PredictedPricing:Add, Edit, x+0 yp+0 w0 h0 ReadOnly vPredictedPricingMax, % data.max
Gui, PredictedPricing:Add, Edit, x+0 yp+0 w0 h0 ReadOnly vPredictedPricingCurrency, % data.currency
Gui, PredictedPricing:Color, FFFFFF
Gui, PredictedPricing:Show, AutoSize, Predicted Item Pricing
ControlFocus, Send && Close, Predicted Item Pricing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment