diff options
author | elisaado | 2018-01-30 08:48:57 +0100 |
---|---|---|
committer | elisaado | 2018-01-30 08:58:25 +0100 |
commit | 8246015cdaecc479fee3c1a5d023460d3935ebe2 (patch) | |
tree | 5fb58cfd48d1f4367bb7a35b191d24f43c536fe4 | |
download | aur-8246015cdaecc479fee3c1a5d023460d3935ebe2.tar.gz |
Create and finish crypto-cli and PKGBUILD
-rw-r--r-- | .SRCINFO | 12 | ||||
-rw-r--r-- | PKGBUILD | 16 | ||||
-rwxr-xr-x | crypto-cli | 119 |
3 files changed, 147 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..c578042d14ae --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,12 @@ +pkgbase = crypto-cli + pkgdesc = View the prices of (many) cryptocurrencies from your terminal + pkgver = 1.0.0 + pkgrel = 1 + arch = any + license = MIT + depends = ruby + source = crypto-cli + sha256sums = 001078b50c1a64b200b8901691970ec75bc8084f1c8af3a25d657c183f1ca27c + +pkgname = crypto-cli + diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..5a9d68ce8107 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,16 @@ +# Maintainer: Eli Saado <elimalkosaado@gmail.com> +pkgname=crypto-cli +pkgver=1.0.0 +pkgrel=1 +pkgdesc="View the prices of (many) cryptocurrencies from your terminal" +arch=('any') +license=('MIT') +depends=('ruby') +options=() +source=("crypto-cli") +sha256sums=('001078b50c1a64b200b8901691970ec75bc8084f1c8af3a25d657c183f1ca27c') + +package() { + cd "$srcdir" + install -Dm755 crypto-cli "$pkgdir/usr/bin/crypto-cli" +} diff --git a/crypto-cli b/crypto-cli new file mode 100755 index 000000000000..f5220839d49e --- /dev/null +++ b/crypto-cli @@ -0,0 +1,119 @@ +#!/usr/bin/env ruby +# This file is part of crypto-cli, https://github.com/elisaado/crypto-cli +# The prices are provided by Moonstats, an amazing website + +require 'faraday' +require 'json' + +currencies = [] + +# I love long lines +JSON.parse(Faraday.get('https://www.moonstats.com/cache/json/coins.json').body).sort_by {|currency| currency['name'].downcase}.each { |currency| currencies.push({slug: currency['slug'], name: currency['name']})} + +if ARGV[0].to_s.strip.size > 0 && (ARGV[1].to_s.strip.size > 0 || ARGV[0].to_s.downcase == 'list') + case ARGV[0].downcase + when 'list' + currencies.each do |currency| + puts "Name: #{currency[:name]}" + puts "Slug: #{currency[:slug].upcase}" + puts + end + when 'search' + term = ARGV[1].downcase + results = currencies.select {|currency| currency[:name].match(/#{term}/i) || currency[:slug].match(/#{term}/i) } + + if results.size > 0 + results.each do |currency| + puts "Name: #{currency[:name]}" + puts "Slug: #{currency[:slug].upcase}" + puts + end + else + puts 'No currencies were found using that term...' + end + when 'vearch' + term = ARGV[1].downcase + results = currencies.select {|currency| currency[:name].match(/#{term}/i) || currency[:slug].match(/#{term}/i) } + + if results.size > 0 + results.each do |currency| + puts "Name: #{currency[:name]}" + puts "Slug: #{currency[:slug].upcase}" + puts + puts 'Price:' + prices = JSON.parse(Faraday.get("https://www.moonstats.com/cache/json/#{currency[:slug]}/latest.json").body) + if ARGV[2].to_s.strip.size > 0 + price = prices[ARGV[2].strip.downcase] + if price.nil? + puts 'Unkown currency provided as third argument, using default...' + puts " BTC: Ƀ#{prices['btc']}" + puts " EUR: €#{prices['eur']}" + puts " USD: $#{prices['usd']}" + else + puts " #{ARGV[2].upcase}: #{price}#{ARGV[2]}" + end + else + puts " BTC: Ƀ#{prices['btc']}" + puts " EUR: €#{prices['eur']}" + puts " USD: $#{prices['usd']}" + end + + puts + puts 'Change:' + puts " #{JSON.parse(Faraday.get("https://www.moonstats.com/cache/json/#{currency[:slug]}/cmc.json").body)[2]}%" + puts + + sleep 0.5 if results.size > 1 # Don't wanna get rate-limited or DOS the website + end + else + puts 'No currencies were found using that term...' + puts + end + when 'view' + term = ARGV[1].downcase + currency = currencies.find {|currency| currency[:name].downcase == term.downcase || currency[:slug].downcase == term} + + if !currency.nil? + puts "Name: #{currency[:name]}" + puts "Slug: #{currency[:slug].upcase}" + puts + puts 'Price:' + prices = JSON.parse(Faraday.get("https://www.moonstats.com/cache/json/#{currency[:slug]}/latest.json").body) + if ARGV[2].to_s.strip.size > 0 + price = prices[ARGV[2].strip.downcase] + if price.nil? + puts 'Unkown currency provided as third argument, using default...' + puts " BTC: Ƀ#{prices['btc']}" + puts " EUR: €#{prices['eur']}" + puts " USD: $#{prices['usd']}" + else + puts " #{ARGV[2].upcase}: #{price}#{ARGV[2]}" + end + else + puts " BTC: Ƀ#{prices['btc']}" + puts " EUR: €#{prices['eur']}" + puts " USD: $#{prices['usd']}" + end + + puts + puts 'Change:' + puts " #{JSON.parse(Faraday.get("https://www.moonstats.com/cache/json/#{currency[:slug]}/cmc.json").body)[2]}%" + puts + else + puts 'Unkown currency provided as second argument...' + puts + end + end + puts 'Everything provided by Moonstats' + puts 'Crypto-CLI is made by Eli Saado and contributors' +else + puts 'Usage: crypto-cli [command] [command arguments]' + puts ' list -- List all cryptocurrencies this program supports (sorted alphabetically)' + puts ' search [term] -- Search through the list mentioned earlier' + puts ' vearch [term] [currency to show price in (optional)] -- Search and view the matched cryptocurrencies (BTC, EUR, and USD)' + puts ' view [slug or name] [currency to show price in (optional)] -- View cryptocurrency price (BTC, EUR, and USD)' + puts + puts 'Everything provided by Moonstats' + puts 'Crypto-CLI is made by Eli Saado and contributors' + exit +end |