#!/usr/bin/env ruby # coding: utf-8 require 'sqlite3' require "json" require "csv" db=SQLite3::Database.new("viewer.sq3") db.execute("CREATE TABLE IF NOT EXISTS " + "mapdate2( name text, period text, address text, season text, viewer text, latlng text, type text)") thiscgi = "./"+File.basename($0) dbn = db.execute("SELECT * from mapdate WHERE viewer=1") hash = {"type"=>"FeatureCollection","features" => [{"type" =>"Feature","properties"=>{"name"=>dbn[0][0],"description"=>dbn[0][1]},"geometry" =>{"type" => dbn[0][6],"coordinates"=>[dbn[0][5]]}}]} #### csv読み取ってDBに挿入 data = CSV.read("debug.csv", {:headers => true}) data.each{|r| db.execute("insert into mapdate2 values ( ?, ?, ?, ?, ?, ?,?)",[r["name"],r["period"],r["address"],r["season"],r["viewer"],r["latlng"],r["type"]]) } open("geojson/test.geojson",'w') do |row| geojson = JSON.pretty_generate(hash) row.print geojson print("geojsonできたよ\n") puts geojson end system("sh auto_push.sh") print("pushされたよ\n")