Skip to content

Commit ecaea26

Browse files
authored
Merge pull request #829 from nschonni/write-fetch-us
feat: update-us script to update data file
2 parents 17ceb79 + 4fa00f5 commit ecaea26

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

_data/governments.yml

+3
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ U.S. Federal:
745745
- department-of-veterans-affairs
746746
- didsr
747747
- digital-analytics-program
748+
- dodcio
748749
- doecode
749750
- DOIOSS
750751
- EEOC
@@ -802,6 +803,7 @@ U.S. Federal:
802803
- NMML
803804
- noaa-gfdl
804805
- NOAA-ORR-ERD
806+
- noaa-pmel
805807
- ntia
806808
- ombegov
807809
- Open-Sat
@@ -863,6 +865,7 @@ U.S. Federal:
863865
- USGS-WiM
864866
- usindianaffairs
865867
- usnationalarchives
868+
- usopm
866869
- USPS
867870
- USPTO
868871
- USSBA

script/fetch-cfa

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module CFA
2424
logger.info "Found #{brigades.count} Brigades"
2525

2626
to_be_removed = org_file['Code For America'] - brigades - code_for_all_orgs
27-
msg = "The following orgs aren't listed on http://codeforamerica.org/api/#api-organizations: \n"
27+
msg = "The following orgs aren't listed on http://api.codeforamerica.org/api/#api-organizations: \n"
2828
logger.info msg + to_be_removed.join("\n") unless to_be_removed.empty?
2929

3030
org_file['Code For America'] = brigades

script/fetch-us

+25-17
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,45 @@ require 'yaml'
1010
require 'typhoeus'
1111

1212
def org_exists?(org)
13-
Typhoeus.head("https://github.com/#{org}", accept_encoding: 'gzip').success?
13+
Typhoeus.head("https://github.com/orgs/#{org}/people", accept_encoding: 'gzip').success?
1414
rescue TyphoeusError
1515
false
1616
end
1717

18-
org_file = YAML.load_file('./_data/governments.yml')
18+
def org_file_path
19+
File.expand_path '../_data/governments.yml', File.dirname(__FILE__)
20+
end
21+
22+
def org_file
23+
@org_file ||= YAML.load_file org_file_path
24+
end
25+
1926
gov = org_file.values.flatten
2027
us_gov = org_file['U.S. Federal'].map(&:downcase)
2128
research = YAML.load_file('./_data/research.yml').values.flatten
2229
existing = (gov + research).flatten.map(&:downcase)
2330

24-
orgs = JSON.parse open('https://usdigitalregistry.digitalgov.gov/api/v1/social_media.json?services=github').read
31+
orgs = JSON.parse URI.open('https://usdigitalregistry.digitalgov.gov/api/v1/social_media.json?services=github').read
2532
orgs = orgs['results'].collect { |data| data['account'] }
33+
orgs.delete('')
2634

2735
orgs.each do |org|
28-
next if existing.include?(org.downcase)
29-
next unless org_exists? org
30-
31-
org_file['U.S. Federal'].push(org.downcase)
36+
next if existing.any? { |s| s.casecmp(org).zero? }
37+
if org_exists? org
38+
org_file['U.S. Federal'].push(org)
39+
else
40+
puts "\n\nIn the registry, but not valid '#{org}'"
41+
end
3242
end
3343

34-
output = {
35-
'U.S. Federal' => org_file['U.S. Federal'].uniq.sort_by(&:upcase)
36-
}
37-
puts 'To be pasted into _data/governments.yml'
38-
puts output.to_yaml
39-
40-
orgs.map!(&:downcase)
44+
org_file['U.S. Federal'] = org_file['U.S. Federal'].uniq.sort_by(&:upcase)
4145

4246
puts "\n\nMissing from registry:"
43-
puts((us_gov - orgs).to_yaml)
47+
puts((us_gov - orgs.map(&:downcase)).to_yaml)
48+
49+
comment = File.open(org_file_path).read.lines.first
50+
output = comment
51+
output << "\n"
52+
output << org_file.to_yaml.sub(/\A---\n/, '').gsub(/^-/, ' -').gsub(/\n([^ ])/, "\n\n\\1")
4453

45-
puts "\n\nIn the registry, but not valid"
46-
puts((orgs - existing).to_yaml)
54+
File.write(org_file_path, output)

0 commit comments

Comments
 (0)