Utilitaire pour indexer des informations de la blockchain et dessiner des Plots. Focalisé sur la toile de confiance. http://datajune.coinduf.eu/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

module Network
"module to get info from network"
using ..Config
using HTTP, JSON, Dates, ZipFile
export get_current_block, download_chunk, get_block
"get number of current block from BMA"
function get_current_block()
r = HTTP.request("GET", BMA_URL*"blockchain/current")
block = JSON.parse(String(r.body))
return block["number"]
end
"download chunk"
function download_chunk(folder, n)
filename = "chunk_$n-250.json"
r = HTTP.request("GET", CHUNKSERVER_URL*filename)
write(joinpath(folder, filename), r.body)
end
"get block through BMA"
function get_block(n)
r = HTTP.request("GET", BMA_URL*"blockchain/block/$n", retry=false, status_exception=false)
if r.status != 200
println()
if r.status == 503
error("reached connection quota")
end
error("request error $(r.status)")
end
block = JSON.parse(String(r.body))
delete!(block, "raw") # remove raw version
return block
end
"download forum subscription activity"
function forum_signups(name)
println("please go to https://$name/admin/reports/signups?end_date=$(today())&start_date=2010-01-01")
println("and click 'export' button, you will receive a like by DM with a link to a zip file")
println("paste de link here")
print("")
link = readline(stdin)
r = HTTP.request("GET", link)
buffer = IOBuffer(r.body)
z = ZipFile.Reader(buffer)
write(joinpath(API_PATH, "$(name)_signups.csv"), read(z.files[1]))
@info "file available in $API_PATH"
end
duniter_signups() = forum_signups("forum.duniter.org")
monnaie_libre_signups() = forum_signups("forum.monnaie-libre.fr")
end