diff --git a/.gitignore b/.gitignore index 750bcf3..f1c89b1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ nimcache/ nimblecache/ htmldocs/ - +bin/ diff --git a/SteamMoneyEstimator.nimble b/SteamMoneyEstimator.nimble new file mode 100644 index 0000000..6947d8a --- /dev/null +++ b/SteamMoneyEstimator.nimble @@ -0,0 +1,13 @@ +# Package + +version = "1.0.0" +author = "Michael Yick" +description = "Estimates how much money a piece of software makes on steam using information about its reviews." +license = "AGPL-3.0-only" +srcDir = "src" +bin = @["SteamMoneyEstimator"] +binDir = "bin" + +# Dependencies + +requires "nim >= 1.6.10" diff --git a/nim.cfg b/nim.cfg new file mode 100644 index 0000000..a0de51d --- /dev/null +++ b/nim.cfg @@ -0,0 +1 @@ +-d:release -d:ssl diff --git a/src/SteamMoneyEstimator.nim b/src/SteamMoneyEstimator.nim new file mode 100644 index 0000000..b445644 --- /dev/null +++ b/src/SteamMoneyEstimator.nim @@ -0,0 +1,79 @@ +import httpclient +import os +import htmlparser +import xmltree +import strutils +import re +import typetraits + +var client = newHttpClient() +let steamURL = os.paramStr(1) +let response = client.getContent(steamURL) + +var html = htmlparser.parseHtml(response) + +var reviewCount: int +var price: float +var onSale: bool +var yearOfRelease: string +var multiplier: int + +for meta in html.findall("meta"): + case meta.attr("itemprop"): + of "reviewCount": + reviewCount = parseInt(meta.attr("content")) + of "price": + price = parseFloat(meta.attr("content")) + case meta.attr("property"): + of "og:title": + if re.find(meta.attr("content"), re"Save .[0-100]% on.*") == -1: + onSale = false + else: + onSale = true + +for date in html.findall("div"): + if date.attr("class") == "date": + yearOfRelease = date.innerText.split(" ")[2] + +## https://vginsights.com/insights/article/how-to-estimate-steam-video-game-sales +case yearOfRelease: + of "2013": + multiplier = 79 + of "2014": + multiplier = 72 + of "2015": + multiplier = 62 + of "2016": + multiplier = 52 + of "2017": + multiplier = 43 + of "2018": + multiplier = 38 + of "2019": + multiplier = 36 + of "2020": + multiplier = 31 + of "2021": + multiplier = 31 + of "2022": ## From here onward, multiplier are made up based off instinct alone + multiplier = 31 + of "2023": + multiplier = 31 + +if onSale: + let steamID = steamURL.split("/")[4] + let response = client.getContent("https://store.steampowered.com/widget/" & steamID) + let widget = htmlparser.parseHTML(response) + for element in widget.findall("div"): + if element.attr("class") == "discount_original_price": + price = element.innerText.replace("$").parseFloat + break +echo "Link: " & os.paramStr(1) +echo "Price: " & $price +echo "Year of Release: " & yearOfRelease +echo "Year Multiplier (from VG Insights): " & $multiplier +echo "Reviews: " & $reviewCount +let estimatedSales = multiplier*reviewCount +echo "Estimated Sales: " & $estimatedSales +let estimatedRevenue = (toFloat(estimatedSales)*price)*0.70 +echo "Estimated revenue (including steam cut): " & $estimatedRevenue