add CSV support
This commit is contained in:
13
README.md
13
README.md
@ -4,8 +4,13 @@ Estimates how much money a piece of software makes on steam using information ab
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
This will save a file locally along with printing the results:
|
`SteamMoneyEstimator {FORMAT} [URLS]`
|
||||||
`SteamMoneyEstimator true "https://store.steampowered.com/app/1895350/I_Wani_Hug_that_Gator/"`
|
|
||||||
|
|
||||||
This will simply output the results without saving a file locally
|
This will save a file locally
|
||||||
`SteamMoneyEstimator true "https://store.steampowered.com/app/1895350/I_Wani_Hug_that_Gator/"`
|
`SteamMoneyEstimator plain "https://store.steampowered.com/app/1895350/I_Wani_Hug_that_Gator/"`
|
||||||
|
|
||||||
|
This will simply output the results to stdout
|
||||||
|
`SteamMoneyEstimator stdout "https://store.steampowered.com/app/1895350/I_Wani_Hug_that_Gator/"`
|
||||||
|
|
||||||
|
Will output all urls data in a csv format
|
||||||
|
`SteamMoneyEstimator csv "https://store.steampowered.com/app/1895350/I_Wani_Hug_that_Gator/"`
|
||||||
|
@ -6,8 +6,12 @@ import strutils
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
var client = newHttpClient()
|
var client = newHttpClient()
|
||||||
let save = parseBool(os.paramStr(1))
|
let save = os.paramStr(1)
|
||||||
let steamURL = os.paramStr(2)
|
if save == "csv":
|
||||||
|
writeFile("games.csv", "link,price,yearOfRelease,multiplier,reviewCount,estimatedSales,estimatedRevenue\n")
|
||||||
|
let commandLine = os.commandLineParams()
|
||||||
|
let steamURLS = commandLine[1..paramCount()-1]
|
||||||
|
for steamURL in steamURLS:
|
||||||
let response = client.getContent(steamURL)
|
let response = client.getContent(steamURL)
|
||||||
|
|
||||||
var html = htmlparser.parseHtml(response)
|
var html = htmlparser.parseHtml(response)
|
||||||
@ -68,17 +72,12 @@ if onSale:
|
|||||||
if element.attr("class") == "discount_original_price":
|
if element.attr("class") == "discount_original_price":
|
||||||
price = element.innerText.replace("$").parseFloat
|
price = element.innerText.replace("$").parseFloat
|
||||||
break
|
break
|
||||||
echo "Link: " & os.paramStr(2)
|
|
||||||
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
|
|
||||||
|
|
||||||
if save:
|
let estimatedSales = multiplier*reviewCount
|
||||||
|
let estimatedRevenue = (toFloat(estimatedSales)*price)*0.70
|
||||||
|
|
||||||
|
case save:
|
||||||
|
of "plain":
|
||||||
for name in html.findall("span"):
|
for name in html.findall("span"):
|
||||||
if name.attr("itemprop") == "name":
|
if name.attr("itemprop") == "name":
|
||||||
var output = """
|
var output = """
|
||||||
@ -88,6 +87,19 @@ Year of Release: $3
|
|||||||
Year Multiplier (from VG Insights): $4
|
Year Multiplier (from VG Insights): $4
|
||||||
Reviews: : $5
|
Reviews: : $5
|
||||||
Estimated Sales: $6
|
Estimated Sales: $6
|
||||||
Estimated revenue (including steam cut): $7""" % [os.paramStr(2), $price, yearOfRelease, $multiplier, $reviewCount, $estimatedSales, $estimatedRevenue]
|
Estimated revenue (including steam cut): $7""" % [steamURL, $price, yearOfRelease, $multiplier, $reviewCount, $estimatedSales, $estimatedRevenue]
|
||||||
|
|
||||||
writeFile(name.innerText.replace("/"), output)
|
writeFile(name.innerText.replace("/"), output)
|
||||||
|
of "csv":
|
||||||
|
let f = open("games.csv", fmAppend)
|
||||||
|
var output = """$1,$2,$3,$4,$5,$6,$7""" % [steamURL, $price, yearOfRelease, $multiplier, $reviewCount, $estimatedSales, $estimatedRevenue]
|
||||||
|
f.writeLine(output)
|
||||||
|
f.close()
|
||||||
|
of "stdout":
|
||||||
|
echo "Link: " & steamURL
|
||||||
|
echo "Price: " & $price
|
||||||
|
echo "Year of Release: " & yearOfRelease
|
||||||
|
echo "Year Multiplier (from VG Insights): " & $multiplier
|
||||||
|
echo "Reviews: " & $reviewCount
|
||||||
|
echo "Estimated Sales: " & $estimatedSales
|
||||||
|
echo "Estimated revenue (including steam cut): " & $estimatedRevenue
|
||||||
|
Reference in New Issue
Block a user