-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwpxmlrpcline.rb
47 lines (38 loc) · 1.1 KB
/
wpxmlrpcline.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env ruby
# coding: utf-8
require 'time'
require 'xmlrpc/client'
require 'uri'
require 'dotenv'
require 'csv'
Dotenv.load
sleeptime = ENV["SLEEPTIME"].to_i
def post(title , description)
wordpress_host = ENV["WORDPRESS_HOST"]
wordpress_userid = ENV["WORDPRESS_USERID"]
wordpress_password = ENV["WORDPRESS_PASSWORD"]
wordpress_categories = ENV["WORDPRESS_CATEGORIES"]
post = 'post'
date = Time.now
publish = 1 # 0:draft,1:publich
server = XMLRPC::Client.new(wordpress_host, '/xmlrpc.php')
struct = {
'title' => title,
'categories' => [wordpress_categories],
'description' => description,
'dateCreated' => date
}
id = server.call("metaWeblog.newPost",1,wordpress_userid,wordpress_password,struct,publish)
end
CSV(STDIN, :col_sep => "\t").each do |row|
title = row[0].split(/ /)[0] << " " << row[2]
placeenc = URI.encode(row[3].split(/ /)[0])
description = <<"EOS"
開始 #{row[0]}
終了 #{row[1]}
場所 <a href="https://www.google.co.jp/maps/place/#{placeenc}">#{row[3]}</a>
URL <a href="#{row[4]}">#{row[4]}</a>
EOS
post(title , description)
sleep(sleeptime)
end