wptools 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +2 -0
 - data/.idea/wptools.iml +33 -0
 - data/Gemfile.lock +4 -2
 - data/README.md +23 -5
 - data/lib/wptools/version.rb +1 -1
 - data/lib/wptools/wp_post.rb +28 -0
 - data/lib/wptools/wp_term.rb +19 -0
 - data/lib/wptools/wp_term_relationship.rb +10 -0
 - data/lib/wptools/wp_term_taxonomy.rb +40 -0
 - data/lib/wptools.rb +11 -6
 - metadata +4 -3
 - data/lib/wptools/wp_term_taxnomy.rb +0 -17
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4525916f493bf92ca63072d790555c33121062bebd781e4cff04dc7322972824
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a3c53d8f2c855fcc651059bae59d5b4a60c7949e906bd23b104511de0dd9677f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a9c76877aa47f2cab544f93d58dc83e46fd2cf5ec0b5abbbfb06aa9d1aa57ab8b38d070786e100872bed70fb321dea5bc3bd31d3c587383666e799a3af14381a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3aea5301d867def37ea02c01fe9221ade2d58a1fc9a2676c1e42f5e3954308f918b55bd877ba5b60aeed042f04e98abd03befe2ca56d908689d1e06a797e94eb
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.idea/wptools.iml
    CHANGED
    
    | 
         @@ -267,4 +267,37 @@ 
     | 
|
| 
       267 
267 
     | 
    
         
             
                  </library>
         
     | 
| 
       268 
268 
     | 
    
         
             
                </orderEntry>
         
     | 
| 
       269 
269 
     | 
    
         
             
              </component>
         
     | 
| 
      
 270 
     | 
    
         
            +
              <component name="RakeTasksCache-v2">
         
     | 
| 
      
 271 
     | 
    
         
            +
                <option name="myRootTask">
         
     | 
| 
      
 272 
     | 
    
         
            +
                  <RakeTaskImpl id="rake">
         
     | 
| 
      
 273 
     | 
    
         
            +
                    <subtasks>
         
     | 
| 
      
 274 
     | 
    
         
            +
                      <RakeTaskImpl description="Build wptools-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
         
     | 
| 
      
 275 
     | 
    
         
            +
                      <RakeTaskImpl id="build">
         
     | 
| 
      
 276 
     | 
    
         
            +
                        <subtasks>
         
     | 
| 
      
 277 
     | 
    
         
            +
                          <RakeTaskImpl description="Generate SHA512 checksum if wptools-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
         
     | 
| 
      
 278 
     | 
    
         
            +
                        </subtasks>
         
     | 
| 
      
 279 
     | 
    
         
            +
                      </RakeTaskImpl>
         
     | 
| 
      
 280 
     | 
    
         
            +
                      <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
         
     | 
| 
      
 281 
     | 
    
         
            +
                      <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
         
     | 
| 
      
 282 
     | 
    
         
            +
                      <RakeTaskImpl description="Build and install wptools-0.1.0.gem into system gems" fullCommand="install" id="install" />
         
     | 
| 
      
 283 
     | 
    
         
            +
                      <RakeTaskImpl id="install">
         
     | 
| 
      
 284 
     | 
    
         
            +
                        <subtasks>
         
     | 
| 
      
 285 
     | 
    
         
            +
                          <RakeTaskImpl description="Build and install wptools-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
         
     | 
| 
      
 286 
     | 
    
         
            +
                        </subtasks>
         
     | 
| 
      
 287 
     | 
    
         
            +
                      </RakeTaskImpl>
         
     | 
| 
      
 288 
     | 
    
         
            +
                      <RakeTaskImpl description="Create tag v0.1.0 and build and push wptools-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
         
     | 
| 
      
 289 
     | 
    
         
            +
                      <RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
         
     | 
| 
      
 290 
     | 
    
         
            +
                      <RakeTaskImpl description="" fullCommand="default" id="default" />
         
     | 
| 
      
 291 
     | 
    
         
            +
                      <RakeTaskImpl description="" fullCommand="release" id="release" />
         
     | 
| 
      
 292 
     | 
    
         
            +
                      <RakeTaskImpl id="release">
         
     | 
| 
      
 293 
     | 
    
         
            +
                        <subtasks>
         
     | 
| 
      
 294 
     | 
    
         
            +
                          <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
         
     | 
| 
      
 295 
     | 
    
         
            +
                          <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
         
     | 
| 
      
 296 
     | 
    
         
            +
                          <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
         
     | 
| 
      
 297 
     | 
    
         
            +
                        </subtasks>
         
     | 
| 
      
 298 
     | 
    
         
            +
                      </RakeTaskImpl>
         
     | 
| 
      
 299 
     | 
    
         
            +
                    </subtasks>
         
     | 
| 
      
 300 
     | 
    
         
            +
                  </RakeTaskImpl>
         
     | 
| 
      
 301 
     | 
    
         
            +
                </option>
         
     | 
| 
      
 302 
     | 
    
         
            +
              </component>
         
     | 
| 
       270 
303 
     | 
    
         
             
            </module>
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                wptools (0. 
     | 
| 
      
 4 
     | 
    
         
            +
                wptools (0.2.0)
         
     | 
| 
       5 
5 
     | 
    
         
             
                  activerecord
         
     | 
| 
       6 
6 
     | 
    
         
             
                  mysql2
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
         @@ -29,11 +29,13 @@ GEM 
     | 
|
| 
       29 
29 
     | 
    
         
             
                concurrent-ruby (1.2.3)
         
     | 
| 
       30 
30 
     | 
    
         
             
                connection_pool (2.4.1)
         
     | 
| 
       31 
31 
     | 
    
         
             
                drb (2.2.1)
         
     | 
| 
       32 
     | 
    
         
            -
                i18n (1.14. 
     | 
| 
      
 32 
     | 
    
         
            +
                i18n (1.14.3)
         
     | 
| 
       33 
33 
     | 
    
         
             
                  concurrent-ruby (~> 1.0)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  racc (~> 1.7)
         
     | 
| 
       34 
35 
     | 
    
         
             
                minitest (5.22.2)
         
     | 
| 
       35 
36 
     | 
    
         
             
                mutex_m (0.2.0)
         
     | 
| 
       36 
37 
     | 
    
         
             
                mysql2 (0.5.6)
         
     | 
| 
      
 38 
     | 
    
         
            +
                racc (1.7.3)
         
     | 
| 
       37 
39 
     | 
    
         
             
                rake (10.5.0)
         
     | 
| 
       38 
40 
     | 
    
         
             
                timeout (0.4.1)
         
     | 
| 
       39 
41 
     | 
    
         
             
                tzinfo (2.0.6)
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -17,22 +17,40 @@ WordPressのテーブルを扱うスクリプト 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            ### 記事一覧の表示
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
            -  
     | 
| 
      
 20 
     | 
    
         
            +
            - 「--command=list」を指定すると記事一覧を表示する。「-l 10」で10件表示する。
         
     | 
| 
       21 
21 
     | 
    
         
             
            ```
         
     | 
| 
       22 
     | 
    
         
            -
            ./ 
     | 
| 
      
 22 
     | 
    
         
            +
            ./run_wptools.sh --command=list -l 10 config/config_sample.yml
         
     | 
| 
       23 
23 
     | 
    
         
             
            ```
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
            ### バズった記事の表示
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
            - DBから取得したページ一覧とGoogleAnalyticsのCSVデータを突き合わせる
         
     | 
| 
       28 
28 
     | 
    
         
             
            - Googleアナリスティックスで「行動 > サイトコンテンツ > すべてのページ」を開く。
         
     | 
| 
       29 
     | 
    
         
            -
              
     | 
| 
       30 
     | 
    
         
            -
            -  
     | 
| 
      
 29 
     | 
    
         
            +
            - 期間を月単位で指定して表示する行数を5000に。CSV形式でエクスポートを実行。
         
     | 
| 
      
 30 
     | 
    
         
            +
            - 「--command=buzz」を指定するとバズった記事を表示する。「-b」でGoogleAnalyticsのCSVデータを指定する。
         
     | 
| 
       31 
31 
     | 
    
         
             
            ```
         
     | 
| 
       32 
     | 
    
         
            -
            ./ 
     | 
| 
      
 32 
     | 
    
         
            +
            ./run_wptools.sh --command=buzz data/Analytics_20200201-20200229.csv
         
     | 
| 
       33 
33 
     | 
    
         
             
            ```
         
     | 
| 
       34 
34 
     | 
    
         
             
            - 結果をGoogleスプレッドシートに貼り付け。貼り付けたあと右下のメニューから列を選択すればCSV形式になる。
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
            ### DBを操作する
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            - 以下のようなrbスクリプト(test.rb)を作成。
         
     | 
| 
      
 39 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 40 
     | 
    
         
            +
            require "wptools"
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            STDOUT.sync = true
         
     | 
| 
      
 43 
     | 
    
         
            +
            Wptools::Command.run(ARGV)
         
     | 
| 
      
 44 
     | 
    
         
            +
            Wptools::WpPost.published_posts.order(post_date: "DESC").limit(100).each do | post|
         
     | 
| 
      
 45 
     | 
    
         
            +
              print "#{post.id} #{post.post_type} #{post.post_date_str} #{post.post_title} #{post.post_name}\n"
         
     | 
| 
      
 46 
     | 
    
         
            +
            end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            ```
         
     | 
| 
      
 49 
     | 
    
         
            +
            - これを「--command=none」で呼び出す。
         
     | 
| 
      
 50 
     | 
    
         
            +
            ```
         
     | 
| 
      
 51 
     | 
    
         
            +
            ruby test.rb --command=none config/config_sample.yml
         
     | 
| 
      
 52 
     | 
    
         
            +
            ```
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       36 
54 
     | 
    
         | 
| 
       37 
55 
     | 
    
         
             
            ## ライセンス
         
     | 
| 
       38 
56 
     | 
    
         | 
    
        data/lib/wptools/version.rb
    CHANGED
    
    
    
        data/lib/wptools/wp_post.rb
    CHANGED
    
    | 
         @@ -4,6 +4,34 @@ require 'active_record' 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            module Wptools
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
              # +-----------------------+-----------------+------+-----+---------------------+----------------+
         
     | 
| 
      
 8 
     | 
    
         
            +
              # | Field                 | Type            | Null | Key | Default             | Extra          |
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   +-----------------------+-----------------+------+-----+---------------------+----------------+
         
     | 
| 
      
 10 
     | 
    
         
            +
              # | ID                    | bigint unsigned | NO   | PRI | NULL                | auto_increment |
         
     | 
| 
      
 11 
     | 
    
         
            +
              # | post_author           | bigint unsigned | NO   | MUL | 0                   |                |
         
     | 
| 
      
 12 
     | 
    
         
            +
              # | post_date             | datetime        | NO   |     | 0000-00-00 00:00:00 |                |
         
     | 
| 
      
 13 
     | 
    
         
            +
              # | post_date_gmt         | datetime        | NO   |     | 0000-00-00 00:00:00 |                |
         
     | 
| 
      
 14 
     | 
    
         
            +
              # | post_content          | longtext        | NO   | MUL | NULL                |                |
         
     | 
| 
      
 15 
     | 
    
         
            +
              # | post_title            | mediumtext      | NO   | MUL | NULL                |                |
         
     | 
| 
      
 16 
     | 
    
         
            +
              # | post_excerpt          | mediumtext      | NO   |     | NULL                |                |
         
     | 
| 
      
 17 
     | 
    
         
            +
              # | post_status           | varchar(20)     | NO   |     | publish             |                |
         
     | 
| 
      
 18 
     | 
    
         
            +
              # | comment_status        | varchar(20)     | NO   |     | open                |                |
         
     | 
| 
      
 19 
     | 
    
         
            +
              # | ping_status           | varchar(20)     | NO   |     | open                |                |
         
     | 
| 
      
 20 
     | 
    
         
            +
              # | post_password         | varchar(255)    | NO   |     |                     |                |
         
     | 
| 
      
 21 
     | 
    
         
            +
              # | post_name             | varchar(200)    | NO   | MUL |                     |                |
         
     | 
| 
      
 22 
     | 
    
         
            +
              # | to_ping               | mediumtext      | NO   |     | NULL                |                |
         
     | 
| 
      
 23 
     | 
    
         
            +
              # | pinged                | mediumtext      | NO   |     | NULL                |                |
         
     | 
| 
      
 24 
     | 
    
         
            +
              # | post_modified         | datetime        | NO   |     | 0000-00-00 00:00:00 |                |
         
     | 
| 
      
 25 
     | 
    
         
            +
              # | post_modified_gmt     | datetime        | NO   |     | 0000-00-00 00:00:00 |                |
         
     | 
| 
      
 26 
     | 
    
         
            +
              # | post_content_filtered | longtext        | NO   |     | NULL                |                |
         
     | 
| 
      
 27 
     | 
    
         
            +
              # | post_parent           | bigint unsigned | NO   | MUL | 0                   |                |
         
     | 
| 
      
 28 
     | 
    
         
            +
              # | guid                  | varchar(255)    | NO   |     |                     |                |
         
     | 
| 
      
 29 
     | 
    
         
            +
              # | menu_order            | int             | NO   |     | 0                   |                |
         
     | 
| 
      
 30 
     | 
    
         
            +
              # | post_type             | varchar(20)     | NO   | MUL | post                |                |
         
     | 
| 
      
 31 
     | 
    
         
            +
              # | post_mime_type        | varchar(100)    | NO   |     |                     |                |
         
     | 
| 
      
 32 
     | 
    
         
            +
              # | comment_count         | bigint          | NO   |     | 0                   |                |
         
     | 
| 
      
 33 
     | 
    
         
            +
              # +-----------------------+-----------------+------+-----+---------------------+----------------+
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       7 
35 
     | 
    
         
             
              ##### wp_posts: 投稿などを保存
         
     | 
| 
       8 
36 
     | 
    
         
             
              # id: 投稿ID
         
     | 
| 
       9 
37 
     | 
    
         
             
              # post_title: タイトル
         
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Wptools
         
     | 
| 
      
 2 
     | 
    
         
            +
              # +------------+---------------------+------+-----+---------+----------------+
         
     | 
| 
      
 3 
     | 
    
         
            +
              # | Field      | Type                | Null | Key | Default | Extra          |
         
     | 
| 
      
 4 
     | 
    
         
            +
              # +------------+---------------------+------+-----+---------+----------------+
         
     | 
| 
      
 5 
     | 
    
         
            +
              # | term_id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
         
     | 
| 
      
 6 
     | 
    
         
            +
              # | name       | varchar(200)        | NO   | MUL |         |                |
         
     | 
| 
      
 7 
     | 
    
         
            +
              # | slug       | varchar(200)        | NO   | UNI |         |                |
         
     | 
| 
      
 8 
     | 
    
         
            +
              # | term_group | bigint(10)          | NO   |     | 0       |                |
         
     | 
| 
      
 9 
     | 
    
         
            +
              # +------------+---------------------+------+-----+---------+----------------+
         
     | 
| 
      
 10 
     | 
    
         
            +
              #
         
     | 
| 
      
 11 
     | 
    
         
            +
              # タグやカテゴリーの情報が保存されている
         
     | 
| 
      
 12 
     | 
    
         
            +
              #
         
     | 
| 
      
 13 
     | 
    
         
            +
              class WpTerm < ActiveRecord::Base
         
     | 
| 
      
 14 
     | 
    
         
            +
                self.primary_key = 'term_id'
         
     | 
| 
      
 15 
     | 
    
         
            +
                has_one :wp_term_taxonomy, foreign_key: :term_id
         
     | 
| 
      
 16 
     | 
    
         
            +
                has_many :wp_term_relationships, through: :wp_term_taxonomy
         
     | 
| 
      
 17 
     | 
    
         
            +
                has_many :wp_posts, through: :wp_term_relationships
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,7 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'active_record'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Wptools
         
     | 
| 
      
 4 
     | 
    
         
            +
              # +------------------+---------------------+------+-----+---------+-------+
         
     | 
| 
      
 5 
     | 
    
         
            +
              # | Field            | Type                | Null | Key | Default | Extra |
         
     | 
| 
      
 6 
     | 
    
         
            +
              # +------------------+---------------------+------+-----+---------+-------+
         
     | 
| 
      
 7 
     | 
    
         
            +
              # | object_id        | bigint(20) unsigned | NO   | PRI | 0       |       |
         
     | 
| 
      
 8 
     | 
    
         
            +
              # | term_taxonomy_id | bigint(20) unsigned | NO   | PRI | 0       |       |
         
     | 
| 
      
 9 
     | 
    
         
            +
              # | term_order       | int(11)             | NO   |     | 0       |       |
         
     | 
| 
      
 10 
     | 
    
         
            +
              # +------------------+---------------------+------+-----+---------+-------+
         
     | 
| 
      
 11 
     | 
    
         
            +
              #  object_idとterm_taxonomy_idの組み合わせが主キー
         
     | 
| 
      
 12 
     | 
    
         
            +
              #
         
     | 
| 
       4 
13 
     | 
    
         
             
              class WpTermRelationship < ActiveRecord::Base
         
     | 
| 
      
 14 
     | 
    
         
            +
                self.primary_key = 'term_taxonomy_id'
         
     | 
| 
       5 
15 
     | 
    
         
             
                belongs_to :wp_post, foreign_key: :object_id
         
     | 
| 
       6 
16 
     | 
    
         
             
                belongs_to :wp_term_taxonomy, foreign_key: :term_taxonomy_id
         
     | 
| 
       7 
17 
     | 
    
         
             
              end
         
     | 
| 
         @@ -0,0 +1,40 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'active_record'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Wptools
         
     | 
| 
      
 4 
     | 
    
         
            +
              # +------------------+---------------------+------+-----+---------+----------------+
         
     | 
| 
      
 5 
     | 
    
         
            +
              # | Field            | Type                | Null | Key | Default | Extra          |
         
     | 
| 
      
 6 
     | 
    
         
            +
              # +------------------+---------------------+------+-----+---------+----------------+
         
     | 
| 
      
 7 
     | 
    
         
            +
              # | term_taxonomy_id | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
         
     | 
| 
      
 8 
     | 
    
         
            +
              # | term_id          | bigint(20) unsigned | NO   | MUL | 0       |                |
         
     | 
| 
      
 9 
     | 
    
         
            +
              # | taxonomy         | varchar(32)         | NO   | MUL |         |                |
         
     | 
| 
      
 10 
     | 
    
         
            +
              # | description      | longtext            | NO   |     | NULL    |                |
         
     | 
| 
      
 11 
     | 
    
         
            +
              # | parent           | bigint(20) unsigned | NO   |     | 0       |                |
         
     | 
| 
      
 12 
     | 
    
         
            +
              # | count            | bigint(20)          | NO   |     | 0       |                |
         
     | 
| 
      
 13 
     | 
    
         
            +
              # +------------------+---------------------+------+-----+---------+----------------+
         
     | 
| 
      
 14 
     | 
    
         
            +
              #
         
     | 
| 
      
 15 
     | 
    
         
            +
              # サンプルデータ
         
     | 
| 
      
 16 
     | 
    
         
            +
              # +------------------+---------+---------------+-------------+--------+-------+
         
     | 
| 
      
 17 
     | 
    
         
            +
              # | term_taxonomy_id | term_id | taxonomy      | description | parent | count |
         
     | 
| 
      
 18 
     | 
    
         
            +
              # +------------------+---------+---------------+-------------+--------+-------+
         
     | 
| 
      
 19 
     | 
    
         
            +
              # |                1 |       1 | category      |             |      0 |   451 |
         
     | 
| 
      
 20 
     | 
    
         
            +
              # |                2 |       2 | link_category |             |      0 |     7 |
         
     | 
| 
      
 21 
     | 
    
         
            +
              # |                3 |       3 | category      |             |      0 |  4184 |
         
     | 
| 
      
 22 
     | 
    
         
            +
              # |               37 |      34 | post_tag      |             |      0 |     2 |
         
     | 
| 
      
 23 
     | 
    
         
            +
              # +------------------+---------+---------------+-------------+--------+-------+
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              # wp_termに格納されている情報がタグなのかカテゴリーなのか。あと親情報とか使用数とか
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              class WpTermTaxonomy < ActiveRecord::Base
         
     | 
| 
      
 28 
     | 
    
         
            +
                self.table_name = 'wp_term_taxonomy'
         
     | 
| 
      
 29 
     | 
    
         
            +
                belongs_to :wp_term, foreign_key: :term_id
         
     | 
| 
      
 30 
     | 
    
         
            +
                has_many :wp_term_relationships, foreign_key: :term_taxonomy_id
         
     | 
| 
      
 31 
     | 
    
         
            +
                has_many :wp_posts, through: :wp_term_relationships
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                scope :tags, -> { where(taxonomy: 'post_tag') }
         
     | 
| 
      
 34 
     | 
    
         
            +
                scope :categories, -> { where(taxonomy: 'category') }
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                def list
         
     | 
| 
      
 37 
     | 
    
         
            +
                  wp_terms.map { |wp_term| { wp_term.slug => wp_term.name } }.flatten
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/wptools.rb
    CHANGED
    
    | 
         @@ -1,6 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # coding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require "wptools/version"
         
     | 
| 
       3 
3 
     | 
    
         
             
            require "wptools/wp_post"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "wptools/wp_term_relationship"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "wptools/wp_term_taxonomy"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "wptools/wp_term"
         
     | 
| 
       4 
7 
     | 
    
         
             
            require 'yaml'
         
     | 
| 
       5 
8 
     | 
    
         
             
            require 'optparse'
         
     | 
| 
       6 
9 
     | 
    
         
             
            require 'csv'
         
     | 
| 
         @@ -54,8 +57,10 @@ module Wptools 
     | 
|
| 
       54 
57 
     | 
    
         
             
                  end
         
     | 
| 
       55 
58 
     | 
    
         
             
                  opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v}
         
     | 
| 
       56 
59 
     | 
    
         
             
                  opt.on('-n', '--dry-run', 'Message only') {|v| opts[:n] = v}
         
     | 
| 
       57 
     | 
    
         
            -
                   
     | 
| 
       58 
     | 
    
         
            -
                  opt.on('- 
     | 
| 
      
 60 
     | 
    
         
            +
                  commands = ['list', 'buzz', 'none']
         
     | 
| 
      
 61 
     | 
    
         
            +
                  opt.on('-c COMMAND', '--command=COMMAND', commands, commands.join('|')) {|v| opts[:c] = v}
         
     | 
| 
      
 62 
     | 
    
         
            +
                  opt.on('-l NUM', '--limit NUM', 'Limit number') {|v| opts[:l] = v.to_i}
         
     | 
| 
      
 63 
     | 
    
         
            +
                  opt.on('-d DATAFILE', '--data DATAFILE', 'CSV Datafile') {|v| opts[:d] = v }
         
     | 
| 
       59 
64 
     | 
    
         
             
                  opt.parse!(argv)
         
     | 
| 
       60 
65 
     | 
    
         
             
                  if argv.empty?
         
     | 
| 
       61 
66 
     | 
    
         
             
                    puts opt.help
         
     | 
| 
         @@ -75,15 +80,15 @@ module Wptools 
     | 
|
| 
       75 
80 
     | 
    
         
             
                end
         
     | 
| 
       76 
81 
     | 
    
         | 
| 
       77 
82 
     | 
    
         
             
                def run
         
     | 
| 
       78 
     | 
    
         
            -
                  if @opts[: 
     | 
| 
      
 83 
     | 
    
         
            +
                  if @opts[:c] == 'list'
         
     | 
| 
       79 
84 
     | 
    
         
             
                    list(@opts[:l])
         
     | 
| 
       80 
     | 
    
         
            -
                  elsif @opts[: 
     | 
| 
       81 
     | 
    
         
            -
                    buzz(@opts[: 
     | 
| 
      
 85 
     | 
    
         
            +
                  elsif @opts[:c] == 'buzz'
         
     | 
| 
      
 86 
     | 
    
         
            +
                    buzz(@opts[:d])
         
     | 
| 
      
 87 
     | 
    
         
            +
                  elsif @opts[:c] == 'none'
         
     | 
| 
       82 
88 
     | 
    
         
             
                  end
         
     | 
| 
       83 
89 
     | 
    
         
             
                end
         
     | 
| 
       84 
90 
     | 
    
         | 
| 
       85 
91 
     | 
    
         
             
                def list(num)
         
     | 
| 
       86 
     | 
    
         
            -
                  p num
         
     | 
| 
       87 
92 
     | 
    
         
             
                  WpPost.published_posts.order(post_date: "DESC").limit(num).each do | post|
         
     | 
| 
       88 
93 
     | 
    
         
             
                    print "#{post.id} #{post.post_type} #{post.post_date_str} #{post.post_title} #{post.post_name}\n"
         
     | 
| 
       89 
94 
     | 
    
         
             
                  end      
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: wptools
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - src
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-03- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-03-06 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activerecord
         
     | 
| 
         @@ -110,8 +110,9 @@ files: 
     | 
|
| 
       110 
110 
     | 
    
         
             
            - lib/wptools.rb
         
     | 
| 
       111 
111 
     | 
    
         
             
            - lib/wptools/version.rb
         
     | 
| 
       112 
112 
     | 
    
         
             
            - lib/wptools/wp_post.rb
         
     | 
| 
      
 113 
     | 
    
         
            +
            - lib/wptools/wp_term.rb
         
     | 
| 
       113 
114 
     | 
    
         
             
            - lib/wptools/wp_term_relationship.rb
         
     | 
| 
       114 
     | 
    
         
            -
            - lib/wptools/ 
     | 
| 
      
 115 
     | 
    
         
            +
            - lib/wptools/wp_term_taxonomy.rb
         
     | 
| 
       115 
116 
     | 
    
         
             
            - run_wptools.sh
         
     | 
| 
       116 
117 
     | 
    
         
             
            - wptools.gemspec
         
     | 
| 
       117 
118 
     | 
    
         
             
            homepage: http://srcw.net/
         
     | 
| 
         @@ -1,17 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'active_record'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Wptools
         
     | 
| 
       4 
     | 
    
         
            -
              class WpTermTaxnomy < ActiveRecord::Base
         
     | 
| 
       5 
     | 
    
         
            -
                self.table_name = 'wp_term_taxonomy'
         
     | 
| 
       6 
     | 
    
         
            -
                has_many :wp_terms, foreign_key: :term_id
         
     | 
| 
       7 
     | 
    
         
            -
                has_many :wp_term_relationships, foreign_key: :term_taxonomy_id
         
     | 
| 
       8 
     | 
    
         
            -
                has_many :wp_posts, through: :wp_term_relationships
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                scope :tags, -> { where(taxonomy: 'post_tag') }
         
     | 
| 
       11 
     | 
    
         
            -
                scope :categories, -> { where(taxonomy: 'category') }
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                def list
         
     | 
| 
       14 
     | 
    
         
            -
                  wp_terms.map { |wp_term| { wp_term.slug => wp_term.name } }.flatten
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
            end
         
     |