Ticket #23804: newsletter-job.patch

File newsletter-job.patch, 4.7 KB (added by hiro, 2 years ago)
  • new file slaves/linux/newsletter-build-static/build

    From 483e77436e5aeb8b32b51b609e34d5e46062844d Mon Sep 17 00:00:00 2001
    From: hiromipaw <hiro@torproject.org>
    Date: Mon, 9 Oct 2017 16:14:46 -0400
    Subject: [PATCH] Make build job for newsletter
    
    ---
     slaves/linux/newsletter-build-static/build         | 14 ++++
     .../newsletter-build-static/etc/build-depends      |  3 +
     .../newsletter-build-static/make-static-pages      | 75 ++++++++++++++++++++++
     .../setup/05-apt-get-update                        |  1 +
     .../setup/15-install-build-depends                 |  1 +
     5 files changed, 94 insertions(+)
     create mode 100755 slaves/linux/newsletter-build-static/build
     create mode 100644 slaves/linux/newsletter-build-static/etc/build-depends
     create mode 100755 slaves/linux/newsletter-build-static/make-static-pages
     create mode 120000 slaves/linux/newsletter-build-static/setup/05-apt-get-update
     create mode 120000 slaves/linux/newsletter-build-static/setup/15-install-build-depends
    
    diff --git a/slaves/linux/newsletter-build-static/build b/slaves/linux/newsletter-build-static/build
    new file mode 100755
    index 0000000..048bf80
    - +  
     1#!/bin/bash
     2
     3set -e
     4set -x
     5set -u
     6
     7rm -rf blog-snippets.wmi RESULT
     8
     9thisscriptdir=$(dirname "$0")
     10thisscriptdir=$(readlink -f "$thisscriptdir")
     11"$thisscriptdir"/make-recent-posts > blog-snippets.wmi
     12
     13mkdir RESULT
     14mv blog-snippets.wmi RESULT
  • new file slaves/linux/newsletter-build-static/etc/build-depends

    diff --git a/slaves/linux/newsletter-build-static/etc/build-depends b/slaves/linux/newsletter-build-static/etc/build-depends
    new file mode 100644
    index 0000000..958cb25
    - +  
     1ruby
     2ruby-gem
     3ruby-net-http-digest-auth
  • new file slaves/linux/newsletter-build-static/make-static-pages

    diff --git a/slaves/linux/newsletter-build-static/make-static-pages b/slaves/linux/newsletter-build-static/make-static-pages
    new file mode 100755
    index 0000000..7a62ac2
    - +  
     1#!/usr/bin/env ruby
     2
     3require 'uri'
     4require 'net/http'
     5require 'net/http/digest_auth'
     6require 'rss'
     7
     8@user="test"
     9@pw="ices-bard"
     10
     11list="https://newsletter-master.torproject.org/rss"
     12
     13
     14def make_auth_request(url, user, pw)
     15  digest_auth = Net::HTTP::DigestAuth.new
     16  uri = URI.parse url
     17  uri.user = user
     18  uri.password = pw
     19
     20  Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
     21    req = Net::HTTP::Get.new uri
     22
     23    res = http.request req
     24 
     25    # res is a 401 response with a WWW-Authenticate header
     26    www_auth_response = res['www-authenticate']
     27 
     28    auth = digest_auth.auth_header uri, www_auth_response, 'GET'
     29
     30    # create a new request with the Authorization header
     31    req = Net::HTTP::Get.new uri.request_uri
     32    req.add_field 'Authorization', auth
     33
     34    return http.request req
     35  end
     36end
     37
     38res = make_auth_request("https://newsletter-master.torproject.org/archive", @user, @pw)
     39if res.code == "200"
     40  Dir.mkdir("archive") unless File.exists?("archive")
     41  File.write("archive/index.html", res.body)
     42end
     43
     44res = make_auth_request("https://newsletter-master.torproject.org/", @user, @pw)
     45if res.code == "200"
     46    File.write("index.html", res.body)
     47end
     48
     49res = make_auth_request(list, @user, @pw)
     50if res.code == "200"
     51  feed = RSS::Parser.parse(res.body)
     52
     53  Dir.mkdir("rss") unless File.exists?("rss")
     54  File.write("rss/index.xml", feed)
     55 
     56  feed.items.each do |item|
     57    page = item.link.split('/').last
     58    link = "https://newsletter-master.torproject.org/archive/#{page}"
     59    res = make_auth_request(link, @user, @pw)
     60    if res.code == "200"
     61      Dir.mkdir("archive/#{page}") unless File.exists?("archive/#{page}")
     62      File.write("archive/#{page}/index.html", res.body)
     63    end
     64    link = "https://newsletter-master.torproject.org/archive/#{page}/text"
     65    res = make_auth_request(link, @user, @pw)
     66    if res.code == "200"
     67      Dir.mkdir("archive/#{page}/text") unless File.exists?("archive/#{page}/text")
     68      File.write("archive/#{page}/text/index.html", res.body)
     69    end
     70  end
     71end
     72
     73
     74
     75
  • new file slaves/linux/newsletter-build-static/setup/05-apt-get-update

    diff --git a/slaves/linux/newsletter-build-static/setup/05-apt-get-update b/slaves/linux/newsletter-build-static/setup/05-apt-get-update
    new file mode 120000
    index 0000000..42fd078
    - +  
     1../../common/setup/05-apt-get-update
     2 No newline at end of file
  • new file slaves/linux/newsletter-build-static/setup/15-install-build-depends

    diff --git a/slaves/linux/newsletter-build-static/setup/15-install-build-depends b/slaves/linux/newsletter-build-static/setup/15-install-build-depends
    new file mode 120000
    index 0000000..6113be0
    - +  
     1../../common/setup/15-install-build-depends
     2 No newline at end of file