Skip to content

Instantly share code, notes, and snippets.

@keisei1092
Last active August 26, 2017 15:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keisei1092/a11da84d91d17c63f79e75286b5246aa to your computer and use it in GitHub Desktop.
Save keisei1092/a11da84d91d17c63f79e75286b5246aa to your computer and use it in GitHub Desktop.
Twiplaからスクレイピングして名刺作るやつ

Example

https://twitter.com/keisei_1092/status/861206475472904193

Sources

main.rb

require 'sinatra'
require 'slim'
require 'open-uri'

get '/' do
  page_source = open('http://twipla.jp/events/printlist/247207', 'r:UTF-8', &:read)
  @attendees = page_source.scan(%r!<tr><td><img src="(.+?)" width.+?</td><td>(.+?)<br>(.+?)</td><td>.+?</td></tr>!)
  slim :index
end

views/index.slim

doctype html
html
  head
    title My Slim Template App
    css:
      * {
        font-family: sans-serif;
      }
  body
    - if @attendees.any?
      div style='display: -webkit-flex; -webkit-flex-wrap: wrap;'
        - @attendees.each_with_index do |attendee, index|
          table style='width: 47%; padding: 16px; border: 1px solid #DDD;'
            tr
              td style='font-size: 24px;'
                | 整理番号&nbsp;
                = index
            tr
              td style='width: 166px;'
                img src=attendee[0] style='width: 150px; border-radius: 75px;'
              td style='font-size: 24px;'
                span style='color: #1B95E0;'
                  = attendee[1]
                br
                b style='font-size: 36px;'
                  = attendee[2]
            tr
              td colspan=2
                center
                  img src='hoge.png' style='width: 90%;'
    - else
      No attendees here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment