-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,7 @@ def is_1pixel_image?(url) | |
# return (isthere.to_s == "1") | ||
# else # no... wget it | ||
begin | ||
url="http://"+url if not url.include? "://" | ||
pixels=FastImage.size(url, :timeout=>2) | ||
pixels=FastImage.size("http://"+url, :timeout=>2) | ||
return pixels.to_s,url if pixels!=nil | ||
rescue Exception => e | ||
if not e.message.include? "Network is unreachable" | ||
|
@@ -32,99 +31,85 @@ def store(line,filename) | |
fw.close | ||
end | ||
|
||
def offload() | ||
while @results.size>0 | ||
pixels,url=@results.pop | ||
if pixels!=nil | ||
@count+=1 if pixels=="[1, 1]" | ||
else | ||
pixels="-1" | ||
end | ||
res="lala" | ||
res=@db.insertBEACON("beaconURLs",[pixels,url]) if url!=nil | ||
@dictionary[url]=pixels | ||
# puts pixels+" "+url.to_s+" "+res.to_s | ||
end | ||
end | ||
|
||
startScript=Time.now | ||
filename=ARGV[0] | ||
@defines=Defines.new(filename.gsub("BEACONS_","")) | ||
dbname=filename.rpartition("/")[0]+"beaconsDB.db" | ||
@db = Database.new(@defines,dbname) | ||
#if not File.file?(dbname) | ||
@db.create("beaconURLs",'imageSize VARCHAR, url VARCHAR PRIMARY KEY') | ||
#end | ||
system("rm -f "+filename+"beaconDetectorTHREADS.csv") | ||
@db.create("beaconURLs",'imageSize VARCHAR, url VARCHAR PRIMARY KEY') | ||
results=@db.getAll("beaconURLs",nil,nil,nil,true) | ||
@dictionary=Hash.new | ||
for res in results | ||
@dictionary[res["url"]]=res["imageSize"] | ||
end | ||
puts "Loaded previous snapshot of "+@dictionary.size.to_s+" elements" | ||
#system("rm -f "+filename+"beaconDetectorTHREADS.csv") | ||
f=File.new(filename) | ||
total=0 | ||
totalLines= `wc -l "#{filename}"`.strip.split(' ')[0] | ||
@count=0 | ||
h=Hash.new | ||
start=Time.now | ||
threads=[10] | ||
results=[10] | ||
threads=[] | ||
@results=[] | ||
while line=f.gets | ||
begin | ||
next if h[line.chop]!=nil | ||
h[line.chop]=true | ||
#puts line.chop+"\typarxei?\t"[email protected]("beaconURLs","imageSize","url",line.chop).to_s | ||
next if @db.get("beaconURLs","imageSize","url",line.chop)!=nil | ||
threads[total]=Thread.new{ | ||
puts is_1pixel_image?(line.chop)[1] | ||
Thread.exit} | ||
total+=1 | ||
if threads.size==10 | ||
total=0 | ||
for thr in threads | ||
thr.join | ||
for cell in results | ||
puts cell.to_s | ||
next if h[line.chop]!=nil | ||
h[line.chop]=true | ||
end | ||
end | ||
|
||
|
||
|
||
abort | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
while threads.size>0 | ||
t=threads.pop | ||
pixels,url=t[:output] | ||
if pixels!=nil | ||
@count+=1 if pixels=="[1, 1]" | ||
else | ||
pixels="-1" | ||
end | ||
res="lala" | ||
res=@db.insertBEACON("beaconURLs",[pixels,url]) if url!=nil | ||
puts pixels+" "+url.to_s+" "+res.to_s | ||
end | ||
puts "\t"+total.to_s+"/"+totalLines+" lines so far... "+(Time.now - start).to_s+" seconds" | ||
start=Time.now | ||
end | ||
f.close | ||
total=0 | ||
found=0 | ||
start=Time.now | ||
h.keys.each{|url| | ||
if @dictionary!=nil and @dictionary[url]!=nil | ||
found+=1 | ||
next | ||
end | ||
begin | ||
threads.push(Thread.new{ | ||
@results.push(is_1pixel_image?(url)) | ||
}) | ||
rescue ThreadError => e | ||
puts "ThreadError "+e.to_s+"\n"+total.to_s+" lines" | ||
while threads.size>0 | ||
t=threads.pop | ||
t.join | ||
pixels,url=t[:output] | ||
if pixels!=nil | ||
@count+=1 if pixels=="[1, 1]" | ||
else | ||
pixels="-1" | ||
end | ||
@db.insertBEACON("beaconURLs",[pixels,url]) if url!=nil | ||
thr=threads.pop | ||
thr.join | ||
end | ||
#try again | ||
threads.push(Thread.new{ | ||
@results.push(is_1pixel_image?(url)) | ||
}) | ||
end | ||
end | ||
while threads.size>0 | ||
t=threads.pop | ||
t.join | ||
pixels,url=t[:output] | ||
if pixels!=nil | ||
@count+=1 if pixels=="[1, 1]" | ||
else | ||
pixels="-1" | ||
total+=1 | ||
if threads.size==10 | ||
puts "\t"+total.to_s+"/"+totalLines+" lines so far... "+(Time.now - start).to_s+" seconds" | ||
while threads.size>0 | ||
thr=threads.pop | ||
thr.join | ||
end | ||
start=Time.now | ||
offload() | ||
end | ||
@db.insertBEACON("beaconURLs",[pixels,url]) if url!=nil | ||
} | ||
while threads.size>0 | ||
thr=threads.pop | ||
thr.join | ||
end | ||
f.close | ||
puts "THREADS, I found "+@count.to_s+" Beacons out of "+total.to_s+" examined URLs for "+filename | ||
offload() | ||
puts "THREADS, I found "+@count.to_s+" Beacons from "+total.to_s+" examined URLs from "+totalLines.to_s+" lines of "+filename | ||
puts "Already found: "+found.to_s | ||
store(@count,filename) | ||
puts "Finished in "+(Time.now - startScript).to_s+" seconds" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters