rubyhexagon 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/examples/sync.rb CHANGED
@@ -77,16 +77,21 @@ class Sync
77
77
  File.open(File.expand_path(E621::Config.paths["j#{mod}s"])) do |f|
78
78
  sets = f.read.parse
79
79
  end
80
- @set_files = File.expand_path(E621::Config.paths["sets"])
80
+ @set_files = File.expand_path(E621::Config.paths["#{mod}s"])
81
81
  api = API.new(mod)
82
82
  sets.each do |oset|
83
83
  id = mod == "set" ? oset["id"] : oset
84
84
  if mod == "set" then
85
- set = Set.new(api.get("show", {"id"=>id}))
85
+ set = Set.new(id)
86
86
  elsif mod == "pool" then
87
- set = Pool.new(api.get("show", {"id"=>id}))
87
+ set = Pool.new(id)
88
+ end
89
+ begin
90
+ set.name = set.name.gsub("_"," ")
91
+ rescue
92
+ @log.error("Error on #{mod} #{id}")
93
+ raise
88
94
  end
89
- set.name = set.name.gsub("_"," ")
90
95
  @log.info("Fetching #{mod} \"#{set.name}\"")
91
96
  set.name = "Love_Can_Be_Different" if set.name == "Love_can_be_different"
92
97
  set.name = set.name.gsub("_"," ").encode("us-ascii", :invalid => :replace, :undef => :replace, :replace => "")
@@ -97,6 +102,7 @@ class Sync
97
102
  end
98
103
  File.open(@set_files+"/#{name}.json"){|f|@posts = f.read.parse}
99
104
  @posts.store("updated_at",0) if !@posts.has_key?("updated_at")
105
+ @posts.store("downloads",@posts["posts"]) if @posts["posts"]
100
106
  next if set.updated_at.to_i <= @posts["updated_at"].to_i
101
107
  dname = mod == "pool" ? set.name : name
102
108
  Dir.mkdir(dname) unless File.exist?(dname)
@@ -106,21 +112,22 @@ class Sync
106
112
  download(post,dname,set,i)
107
113
  i += 1
108
114
  end
109
- advanced_set(oset) if mod == "set"
115
+ advanced_set(oset,name,set) if mod == "set"
116
+ @posts["updated_at"] = set.updated_at.to_i
117
+ jposts = @posts.to_json
118
+ File.open(@set_files+"/#{name}.json","w"){|f|f.print jposts}
110
119
  end
111
120
  end
112
- @posts["updated_at"] = set.updated_at.to_i
113
- jposts = @posts.to_json
114
- File.open(@set_files+"/#{name}.json","w"){|f|f.print jposts}
115
121
  end
116
122
 
117
- def set(set)
123
+ def advanced_set(set,name,s)
118
124
  sid, owner, query = set["id"], set["owner"], set["search"]
119
- if owner == uid then
125
+ if owner == @uid then
120
126
  Search.new("fav:maxine_red #{query} order:id".split(" ")).each_post do |post|
121
127
  next if @posts["downloads"].include?(post.id)
122
- download(post,name,set)
128
+ download(post,name,s)
123
129
  end
130
+ api = API.new("set")
124
131
  set = api.get("show", {"id"=>sid})
125
132
  posts = set["posts"].map{|post|Post.new(post).id}
126
133
  name = set["shortname"]
data/lib/pool.rb CHANGED
@@ -23,7 +23,13 @@ module E621
23
23
  class Pool < Container
24
24
  def initialize(post)
25
25
  @api = API.new("pool")
26
- set_variables(post)
26
+ if post.is_a?(Hash) then
27
+ set_variables(post)
28
+ elsif post.is_a?(Fixnum) then
29
+ set_variables(@api.get("show",{"id"=>post}))
30
+ else
31
+ raise ArgumentError, "Parameter must be Hash or Number."
32
+ end
27
33
  end
28
34
 
29
35
  def keys
data/lib/rubyhexagon.rb CHANGED
@@ -30,5 +30,5 @@ require "pool"
30
30
 
31
31
  module E621
32
32
  Name = "rubyhexagon"
33
- Version = "0.1.3"
33
+ Version = "0.1.4"
34
34
  end
data/lib/set.rb CHANGED
@@ -20,7 +20,7 @@
20
20
  module E621
21
21
  class Set < Container
22
22
  def initialize(post)
23
- @api,@page = API.new("set"),1
23
+ @api = API.new("set")
24
24
  if post.is_a?(Hash) then
25
25
  set_variables(post)
26
26
  elsif post.is_a?(Fixnum) then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyhexagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-01 00:00:00.000000000 Z
12
+ date: 2015-03-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rubyhexagon provides Ruby bindings for the e621 [dot] net API.
15
15
  email: maxine_red1@yahoo.com