GithubHelp home page GithubHelp logo

dotnet-price-parser's Introduction

dotnet-price-parser

The latest release can be downloaded via NuGet.

Open Source Love Awesome

dotnet-price-parser is an open source .NET library for parsing scraped prices. Save time tuning your XPath and CSS selectors to get amount and currency accuratedly parsed out of raw string texts.

This project is based on the open source Python library price-parser, by ScrapingHub.

Features

  • Prediction of thousands and decimal separator, if not specified.
  • Support for +150 currencies.
  • Currency hint specification as an alternate source for currency lookup.

Usage

C#

Examples

Price parsedPrice = Price.FromString("Price: $119.00");

double? amount = parsedPrice.Amount        // 119.00
string currency = parsedPrice.Currency     // "$"
Price price = Price.FromString("Price: $119.00")
// price.Amount = 119.00; price.Currency = "$"
Price price = Price.FromString("15 130 Р")
// price.Amount = 15130; price.Currency = "Р"
Price price = Price.FromString("151,200 تومان")
// price.Amount = 151200; price.Currency = "تومان"
Price price = Price.FromString("Rp 1.550.000")
// price.Amount = 15500000; price.Currency = "Rp"
Price price = Price.FromString("Běžná cena 75 990,00 Kč")
// price.Amount = 75990; price.Currency = "Kč"

Amount or currency not found

If either the amount or the currency are not found, the corresponding property for that price is set to null.

Price price = Price.FromString("Foo")
// price.Amount = null; price.Currency = null

Special cases

Price price = Price.FromString("Free")
// price.Amount = 0.0; price.Currency = null
Price price = Price.FromString("40% OFF")
// price.Amount = null; price.Currency = null

Currency hint

An alternate source string can be specified to try to extract the currency, if the latter could not be found in the provided raw price:

Price price = Price.FromString("8.29", rawCurrencyHint: "£ 8.29");
// price.Amount = 8.29; price.Currency = "£"
Price price = Price.FromString("8.29 EUR", rawCurrencyHint: "£ 8.29");
// price.Amount = 8.29; price.Currency = "EUR"

Decimal separator style

The library tries to predict both decimal and thousands separators but if this information is known beforehand, you can specify the style that is used:

Price price = Price.FromString("Price: $140.600", EDecimalSeparatorStyle.American)
// price.Amount = 140.6; price.Currency = "USD"
Price price = Price.FromString("Price: $140.600", EDecimalSeparatorStyle.European)
// price.Amount = 140600; price.Currency = "USD"
Price price = Price.FromString("Price: $140.600")
// price.Amount = 140600; price.Currency = "USD"

Note. The library assumes American and European styles use dots and commas as decimal separators, respectively.

Running the tests

The library is tested with +900 NUnit tests, which can be easily run from Visual Studio.

Donation

If this project helps you reduce development time, you may consider giving me a cup of coffee :-)

Donate

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.