nofxx-pyradise 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/pyradise.rb +20 -20
- data/pyradise.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/pyradise.rb
CHANGED
@@ -9,13 +9,18 @@ require 'pyradise/stat'
|
|
9
9
|
#TODO: def init
|
10
10
|
HOME = ENV['HOME'] + "/.pyradise/"
|
11
11
|
#DataMapper.setup(:default, :adapter => 'tokyo_cabinet', :database => 'data.tct', :path => HOME)
|
12
|
-
|
13
|
-
|
12
|
+
DataMapper.setup(:default, :adapter => 'sqlite3', :database => HOME + "py.sqlite3")
|
13
|
+
|
14
|
+
unless File.exists? HOME
|
15
|
+
FileUtils.mkdir_p HOME
|
16
|
+
DataMapper.auto_migrate!
|
17
|
+
end
|
14
18
|
|
15
19
|
module Pyradise
|
16
20
|
|
17
|
-
|
18
|
-
|
21
|
+
CONF = YAML.load(File.new(HOME + "conf.yml"))
|
22
|
+
RATE = CONF[:rate] || 2.1
|
23
|
+
TAX = CONF[:tax] || 1.3
|
19
24
|
|
20
25
|
class << self
|
21
26
|
|
@@ -69,13 +74,6 @@ module Pyradise
|
|
69
74
|
products
|
70
75
|
end
|
71
76
|
|
72
|
-
def get_or_create_home
|
73
|
-
unless File.exists? HOME
|
74
|
-
FileUtils.mkdir_p HOME
|
75
|
-
end
|
76
|
-
HOME
|
77
|
-
end
|
78
|
-
|
79
77
|
def list(*query)
|
80
78
|
t = Time.now
|
81
79
|
w = terminal_size[0]
|
@@ -85,20 +83,21 @@ module Pyradise
|
|
85
83
|
puts "Searching #{'"' + query[0] + '"' if query[0]}... Order by: #{query[1] || 'name'}"
|
86
84
|
puts "_" * w
|
87
85
|
prods = q.empty? ? Product.all : Product.all(q)
|
88
|
-
prods.
|
86
|
+
prods.each_with_index do |prod, i|
|
89
87
|
s = w - 35
|
90
88
|
name = prod.name.length > s ? prod.name[0..s] + ".." : prod.name
|
91
|
-
|
89
|
+
out = sprintf("%-6s | %-5s | %-#{w-38}s %-3d | R$ %d", prod.store, prod.sid, name, prod.price, prod.price * RATE * TAX)
|
90
|
+
puts i % 2 == 0 ? bold(out) : out
|
92
91
|
end
|
93
92
|
puts "_" * w
|
94
|
-
puts "Total: #{prods.length} (#{Time.now - t}s)"
|
93
|
+
puts green("Total: #{prods.length} (#{Time.now - t}s)")
|
95
94
|
end
|
96
95
|
|
97
|
-
def view(sid)
|
96
|
+
def view(sid=nil)
|
98
97
|
if !sid
|
99
|
-
puts "Use: pyradise view <ID>"
|
98
|
+
puts red("Use: pyradise view <ID>")
|
100
99
|
elsif !prod = Product.first(:sid => sid.to_i)
|
101
|
-
puts "Product not found."
|
100
|
+
puts yellow("Product not found.")
|
102
101
|
else
|
103
102
|
w = terminal_size[0] - 20
|
104
103
|
prices = prod.prices
|
@@ -119,8 +118,9 @@ module Pyradise
|
|
119
118
|
`stty size`.split.map { |x| x.to_i }.reverse
|
120
119
|
end
|
121
120
|
|
122
|
-
def red(txt)
|
123
|
-
|
124
|
-
end
|
121
|
+
def red(txt); "\e[31m#{txt}\e[0m"; end
|
122
|
+
def green(txt); "\e[32m#{txt}\e[0m"; end
|
123
|
+
def yellow(txt); "\e[33m#{txt}\e[0m"; end
|
124
|
+
def bold(txt); "\e[2m#{txt}\e[0m"; end
|
125
125
|
end
|
126
126
|
end
|
data/pyradise.gemspec
CHANGED