-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # source/tei/shan.L001.xml
- Loading branch information
Showing
267 changed files
with
19,675 additions
and
7,252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "datura", git: "https://github.com/CDRH/datura.git", tag: "v0.1.0" | ||
gem "datura", git: "https://github.com/CDRH/datura.git", tag: "v0.1.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Cartas a la Familia: De la migración de Jesusita a Jane | ||
|
||
Family Letters: On the Migration from Jesusita to Jane | ||
|
||
This repository is intended for use with the [CDRH API](https://github.com/CDRH/api) and the [Family Letters Ruby on Rails application](https://github.com/CDRH/family_letters). | ||
|
||
## Updating | ||
|
||
See the [Datura documentation](https://github.com/CDRH/datura) for general updating and posting instructions. **NOTE: do not edit the CSV files -- they are generated from a spreadsheet (documents.csv) and a [mediacommons](https://mediacommons.unl.edu/luna/servlet/UNL~111~111) export (photographs.csv)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require "json" | ||
require "open-uri" | ||
require "uri" | ||
|
||
class Datura::DataManager | ||
|
||
def build_html(urls) | ||
combined = "" | ||
# retrieve and then combine into a single file which can be parsed | ||
urls.each do |url| | ||
lang = url.include?("/en/") ? "en" : "es" | ||
raw = open(url) { |f| f.read } | ||
|
||
# wrap the web scraping results in a div that describes the language | ||
combined << "<div lang=\"#{lang}\">" | ||
html = Nokogiri::HTML(raw) | ||
combined << html.at_xpath("//div[@id='content-wrapper']").inner_html | ||
combined << "</div>" | ||
end | ||
combined | ||
rescue => exception | ||
print_error(exception, urls) | ||
end | ||
|
||
def pre_file_preparation | ||
if @options["scrape_website"] | ||
url = File.join(@options["site_url"], @options["scrape_endpoint"]) | ||
puts "getting list of urls to scrape from #{url}" | ||
list_of_pages = open(url) { |f| f.read } | ||
# family letters has urls such as research and en/research | ||
# representing spanish and english views of the same content | ||
# so the urls are returned in pairs | ||
JSON.parse(list_of_pages).each do |pair| | ||
# share an id for the two files | ||
site_url_for_regex = @options["site_url"] | ||
.gsub("/", "\/") | ||
.gsub(".", "\.") | ||
id = pair | ||
.first[/^#{site_url_for_regex}\/(.*)/, 1] | ||
.gsub("/", "_") | ||
output_file = "#{@options["collection_dir"]}/source/webs/#{id}.html" | ||
|
||
html = build_html(pair) | ||
File.open(output_file, 'w') { |file| file.write(html) } | ||
end | ||
else | ||
puts %{Files in source/webs are not being refreshed from the website | ||
contents. If you wish to scrape the family letters website, please | ||
add or update config/public.yml to use "scrape_website: true"} | ||
end | ||
rescue => exception | ||
print_error(exception, url) | ||
end | ||
|
||
def print_error(e, url) | ||
puts %{Something went wrong while scraping the family letters website: | ||
URL(S): #{url} | ||
ERROR: #{e} | ||
To post content, please check the endpoint in config/public.yml, or | ||
temporarily disable the scrape_website setting in that file}.red | ||
end | ||
|
||
end |
Oops, something went wrong.