From 71dc2fc768ea20b67ab77cba5173a1ba9492bfb5 Mon Sep 17 00:00:00 2001 From: Michael Yick Date: Thu, 10 Aug 2023 01:44:19 -0500 Subject: [PATCH] add file saving capabilities --- README.md | 10 +++++++++- SteamMoneyEstimator.nimble | 2 +- src/SteamMoneyEstimator.nim | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c5d2d72..781b3ec 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # SteamMoneyEstimator -Estimates how much money a piece of software makes on steam using information about its reviews. \ No newline at end of file +Estimates how much money a piece of software makes on steam using information about its reviews. + +## Usage + +This will save a file locally along with printing the results: +`SteamMoneyEstimator true "https://store.steampowered.com/app/1895350/I_Wani_Hug_that_Gator/"` + +This will simply output the results without saving a file locally +`SteamMoneyEstimator true "https://store.steampowered.com/app/1895350/I_Wani_Hug_that_Gator/"` diff --git a/SteamMoneyEstimator.nimble b/SteamMoneyEstimator.nimble index 6947d8a..5851de3 100644 --- a/SteamMoneyEstimator.nimble +++ b/SteamMoneyEstimator.nimble @@ -1,6 +1,6 @@ # Package -version = "1.0.0" +version = "1.0.1" 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" diff --git a/src/SteamMoneyEstimator.nim b/src/SteamMoneyEstimator.nim index b445644..faec222 100644 --- a/src/SteamMoneyEstimator.nim +++ b/src/SteamMoneyEstimator.nim @@ -4,10 +4,10 @@ import htmlparser import xmltree import strutils import re -import typetraits var client = newHttpClient() -let steamURL = os.paramStr(1) +let save = parseBool(os.paramStr(1)) +let steamURL = os.paramStr(2) let response = client.getContent(steamURL) var html = htmlparser.parseHtml(response) @@ -68,7 +68,7 @@ if onSale: if element.attr("class") == "discount_original_price": price = element.innerText.replace("$").parseFloat break -echo "Link: " & os.paramStr(1) +echo "Link: " & os.paramStr(2) echo "Price: " & $price echo "Year of Release: " & yearOfRelease echo "Year Multiplier (from VG Insights): " & $multiplier @@ -77,3 +77,17 @@ let estimatedSales = multiplier*reviewCount echo "Estimated Sales: " & $estimatedSales let estimatedRevenue = (toFloat(estimatedSales)*price)*0.70 echo "Estimated revenue (including steam cut): " & $estimatedRevenue + +if save: + for name in html.findall("span"): + if name.attr("itemprop") == "name": + var output = """ +Link: $1 +Price: $2 +Year of Release: $3 +Year Multiplier (from VG Insights): $4 +Reviews: : $5 +Estimated Sales: $6 +Estimated revenue (including steam cut): $7""" % [os.paramStr(2), $price, yearOfRelease, $multiplier, $reviewCount, $estimatedSales, $estimatedRevenue] + + writeFile(name.innerText, output)