Last active
December 14, 2015 23:58
-
-
Save agerwick/5168965 to your computer and use it in GitHub Desktop.
Esniper script collection
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
Esniper script collection | |
Ever dreamt of importing esniper's logs to your spreadsheet? Wouldn't anybody dream of that? Well you don't have to dream any longer! This is a collection of esniper related scripts, which I'm releasing under GPL v.3.0. | |
Prerequisites: | |
Your esniper auction files are in ~/esniper-auctions (any temporary ones can be kept in subdirectories) and have .esniper as extension. | |
All these scripts are in the same directory. | |
You have a ~/.esniper-logs directory for the log files used by these routines (note the leading dot). | |
How it works: | |
When you have a few esniper auction files to run, use ~/esniper-auctions/runall | |
To stop them all use killall esniper | |
For a quick status check of next time the different esniper processes will refresh, use ~/esniper-auctions/status | |
For a detailed overview, run ~/esniper-auctions/overview , copy and paste the result to openoffice calc or another spreadsheet. | |
Enjoy! |
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
# Script to process esniper log files to produce a tab separated output that can be imported to spreadsheets | |
# (c)2013 Ronny Ager-Wick | |
# Licensed under GPL v.3.0 | |
def new_auction?(line=@line) | |
# "Auction 908070605040: Fustasjopphengsforkoblinger med grønne overledninger\n" | |
# ^^^^^^^^ | |
line[0..7] == "Auction " && @line = line | |
end | |
def time_remaining_line? | |
# "Time remaining: 19 hours 54 mins 36 secs (71676 seconds)" | |
# ^^^^^^^^^^^^^^^^ | |
@line[0..15] == "Time remaining: " | |
end | |
def bid_amount_line? | |
# "Currently: 21.00 (your maximum bid: 50.00)\n" | |
# ^^^^^^^^^^^ | |
@line[0..10] == "Currently: " | |
end | |
def num_bids_line? | |
# "# of bids: 10\n" | |
# ^^^^^^^^^^^ | |
@line[0..10] == "# of bids: " | |
end | |
def highest_bidder_line? | |
# "High bidder: a***b (NOT my-ebay-id)\n" | |
# ^^^^^^^^^^^^^ | |
@line[0..12] == "High bidder: " | |
end | |
def get_auction_id | |
# "Auction 908070605040: Fustasjopphengsforkoblinger med grønne overledninger\n" | |
# ^^^^^^^^^^^^ | |
return nil if !new_auction? | |
@tmp[:auction_id] = @line[8..@line.index(":")-1] | |
end | |
def get_auction_title | |
# "Auction 908070605040: Fustasjopphengsforkoblinger med grønne overledninger\n" | |
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
return nil if !new_auction? | |
@tmp[:auction_title] = @line[@line.index(":")+2..-2] | |
end | |
def get_time_remaining | |
# "Time remaining: 19 hours 54 mins 36 secs (71676 seconds)" | |
# ^^^^^ | |
return if !time_remaining_line? | |
seconds = @line[(@line.index("(") + 1)..(@line.index(" seconds)") - 1)].to_i | |
@tmp[:time_remaining_total_s] = seconds | |
@tmp[:time_remaining_d] = seconds / (60 * 60 * 24) | |
seconds -= (@tmp[:time_remaining_d] * 60 * 60 * 24) # deduct the days from the original seconds | |
@tmp[:time_remaining_h] = seconds / (60 * 60) | |
seconds -= (@tmp[:time_remaining_h] * 60 * 60) # deduct the hours from the remaining seconds | |
@tmp[:time_remaining_m] = seconds / 60 | |
seconds -= (@tmp[:time_remaining_m] * 60) # deduct the minutes from the remaining seconds | |
@tmp[:time_remaining_s] = seconds | |
end | |
def get_bid_amount | |
# "Currently: 21.00 (your maximum bid: 50.00)\n" | |
# ^^^^^ ^^^^^ | |
return if !bid_amount_line? | |
first_space = @line.index(" ") | |
second_space = @line[first_space+1..-1].index(" ") + first_space+1 | |
@tmp[:current_bid] = @line[first_space+1..second_space-1].to_f | |
@tmp[:maximum_bid] = @line[@line.index("bid:")+5..-3].to_f | |
end | |
def get_num_bids | |
# "# of bids: 10\n" | |
# ^^ | |
return if !num_bids_line? | |
@tmp[:num_bids] = @line[11..-2].to_i | |
end | |
def get_highest_bidder | |
# "High bidder: e***c (NOT my-ebay-id)\n" | |
# ^^^^^ | |
return if !highest_bidder_line? | |
@tmp[:highest_bidder] = @line.index("(NOT ") == nil | |
end | |
def save_data | |
@auctions = {} if not defined?(@auctions) | |
@auctions[@tmp[:auction_id]] = [ \ | |
@tmp[:auction_id], \ | |
@tmp[:num_bids], \ | |
@tmp[:highest_bidder], \ | |
@tmp[:current_bid], \ | |
@tmp[:maximum_bid], \ | |
@tmp[:time_remaining_d], @tmp[:time_remaining_h], @tmp[:time_remaining_m], @tmp[:time_remaining_s], \ | |
@filename, \ | |
@tmp[:auction_title] \ | |
] | |
@tmp = {} # reset temporary auction variable, making it ready for a new auction | |
end | |
@tmp = {} # we need to initialize this variable, as all methods assume it's already a hash | |
ARGV.each do |filename| | |
@filename = filename | |
File.open( filename ).each do |line| | |
@line = line | |
if new_auction? | |
if defined?(@tmp) && @tmp.class == Hash && @tmp.length > 0 # this excludes the first auction in the file, as there's nothing to save then | |
save_data # becuase this line indicates the start of a new auction we'll save the current one | |
end | |
get_auction_id | |
get_auction_title | |
else | |
get_time_remaining | |
get_bid_amount | |
get_num_bids | |
get_highest_bidder | |
end | |
end | |
save_data # if we reach the end of the file, we also need to save the last auction | |
end | |
# output the tab separated heading | |
printf \ | |
"auction_id\t"\ | |
"num_bids\t"\ | |
"highest_bidder\t"\ | |
"current_bid\t"\ | |
"maximum_bid\t"\ | |
"time_remaining_d\ttime_remaining_h\ttime_remaining_m\ttime_remaining_s\t"\ | |
"filename\t"\ | |
"auction_title\n" | |
# output the data we've collected | |
@auctions.keys.each do |id| | |
printf @auctions[id].collect { |c| (c.class==String || c.class==TrueClass || c.class==FalseClass) && '"' + c.to_s.gsub(/"/, '""') + '"' || c.to_s }.join("\t") + "\n" | |
end if @auctions |
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
#!/bin/bash | |
cd ~/.esniper-logs # if generate-overview is executed from here, the log names don't contain the path, which looks nicer | |
ruby ~/esniper-auctions/generate-overview.rb *.log |
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
#!/bin/sh | |
for file in ~/esniper-auctions/*.esniper | |
do | |
[ -f "$file" ] && esniper $file > ~/.esniper-logs/$(basename $file .esniper).log & | |
done | |
ps u -C esniper |
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
#!/bin/bash | |
tail ~/.esniper-logs/*.log | grep "Sleeping\|==>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment