Created
April 17, 2018 09:18
-
-
Save Tachibana446/19cd6289273c39f928f380ce41b637f1 to your computer and use it in GitHub Desktop.
購入履歴
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
# ファイル名は適宜 | |
shogyo = File.readlines('./購入記録商業180417.csv') | |
doujin = File.readlines('./購入記録同人180417.csv') | |
denshi = File.readlines('./購入記録電子書籍180417.csv') | |
data = {} | |
shogyo.each do |line| | |
next if line.strip == '' | |
sp = line.split(',') | |
price = sp[1].to_i | |
data[sp[0]] = { shogyo: 0, doujin: 0, denshi: 0 } unless data.key? sp[0] | |
data[sp[0]][:shogyo] += price | |
end | |
doujin.each do |line| | |
next if line.strip == '' | |
sp = line.split(',') | |
price = sp[1].to_i | |
data[sp[0]] = { shogyo: 0, doujin: 0, denshi: 0 } unless data.key? sp[0] | |
data[sp[0]][:doujin] += price | |
end | |
denshi.each do |line| | |
next if line.strip == '' | |
sp = line.split(',') | |
price = sp[1].to_i | |
data[sp[0]] = { shogyo: 0, doujin: 0, denshi: 0 } unless data.key? sp[0] | |
data[sp[0]][:denshi] += price | |
end | |
def to_csv(key, data) | |
"#{key},#{data[:doujin]},#{data[:shogyo]},#{data[:denshi]}" | |
end | |
File.open('./output.csv', 'w') do |f| | |
f.puts '日付,同人,商業,電子書籍' | |
data.map { |k, v| to_csv(k, v) }.each { |v| f.puts v } | |
end |
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
var priceList = {} | |
$('#unpaid_list > table > tbody > tr').each((i, tr) => { | |
let datestr = $(tr).children('.buy_date').text() | |
let match = /\d{4}\/\d\d\/\d\d/.exec(datestr) | |
if(!match){ | |
console.log(`日付以外なのでスキップ: ${datestr}`) | |
return true | |
} | |
let date = match[0] | |
let price = (/(.+)円/.exec($(tr).children('.work_price').text()))[1] | |
price = price.replace(/,/g, '') | |
price = parseInt(price) | |
if(price <= 0) | |
console.log(`minus: ${datestr}`) | |
if(priceList[date]) | |
priceList[date] += price | |
else | |
priceList[date] = price | |
}) | |
var resultStr = "" | |
var sum = 0 | |
for(let key in priceList){ | |
resultStr += `${key},${priceList[key]}\n` | |
sum += priceList[key] | |
} | |
console.log("合計:" + sum) | |
console.log(resultStr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment