Skip to content

Commit

Permalink
importing of funds and projects
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Aug 21, 2024
1 parent 7a7f577 commit c1d4d30
Show file tree
Hide file tree
Showing 9 changed files with 941 additions and 2 deletions.
21 changes: 20 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,27 @@ gem "sprockets-rails"
gem "pg", "~> 1.5"
gem "puma", "~> 6.3"
gem "jbuilder"

gem "bootsnap", require: false
gem "sassc-rails"
gem "counter_culture"
gem "faraday"
gem "faraday-retry"
gem "faraday-follow_redirects"
gem "pagy"
gem "pghero"
gem "pg_query"
gem 'bootstrap'
gem "rack-attack"
gem "rack-attack-rate-limit", require: "rack/attack/rate-limit"
gem 'rack-cors'
gem 'rswag-api'
gem 'rswag-ui'
gem 'jquery-rails'
gem 'faraday-typhoeus'
gem 'sidekiq'
gem 'sidekiq-unique-jobs'
gem 'sidekiq-status'


group :development, :test do
gem "debug", platforms: %i[ mri mingw x64_mingw ]
Expand Down
120 changes: 120 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,24 @@ GEM
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
autoprefixer-rails (10.4.19.0)
execjs (~> 2)
base64 (0.2.0)
bigdecimal (3.1.8)
bindex (0.8.1)
bootsnap (1.18.4)
msgpack (~> 1.2)
bootstrap (5.3.3)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 2.11.8, < 3)
builder (3.3.0)
chronic_duration (0.10.6)
numerizer (~> 0.1.1)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
counter_culture (3.7.0)
activerecord (>= 4.2)
activesupport (>= 4.2)
crack (1.0.0)
bigdecimal
rexml
Expand All @@ -91,8 +101,47 @@ GEM
reline (>= 0.3.8)
drb (2.2.1)
erubi (1.13.0)
ethon (0.16.0)
ffi (>= 1.15.0)
execjs (2.9.1)
faraday (2.10.1)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-net_http (3.1.1)
net-http
faraday-retry (2.2.1)
faraday (~> 2.0)
faraday-typhoeus (1.1.0)
faraday (~> 2.0)
typhoeus (~> 1.4)
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-arm-linux-gnu)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86-linux-gnu)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
globalid (1.2.1)
activesupport (>= 6.1)
google-protobuf (4.27.3)
bigdecimal
rake (>= 13)
google-protobuf (4.27.3-aarch64-linux)
bigdecimal
rake (>= 13)
google-protobuf (4.27.3-arm64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.27.3-x86-linux)
bigdecimal
rake (>= 13)
google-protobuf (4.27.3-x86_64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.27.3-x86_64-linux)
bigdecimal
rake (>= 13)
hashdiff (1.1.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
Expand All @@ -103,6 +152,10 @@ GEM
jbuilder (2.12.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
Expand All @@ -118,6 +171,8 @@ GEM
mocha (2.4.5)
ruby2_keywords (>= 0.0.5)
msgpack (1.7.2)
net-http (0.4.1)
uri
net-imap (0.4.14)
date
net-protocol
Expand All @@ -140,14 +195,27 @@ GEM
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
numerizer (0.1.1)
pagy (9.0.5)
pg (1.5.7)
pg_query (5.1.0)
google-protobuf (>= 3.22.3)
pghero (3.6.0)
activerecord (>= 6.1)
popper_js (2.11.8)
psych (5.1.2)
stringio
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.7)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-attack-rate-limit (1.1.0)
rack
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -191,15 +259,44 @@ GEM
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
redis-client (0.22.2)
connection_pool
reline (0.5.9)
io-console (~> 0.5)
rexml (3.3.5)
strscan
rswag-api (2.14.0)
activesupport (>= 5.2, < 8.0)
railties (>= 5.2, < 8.0)
rswag-ui (2.14.0)
actionpack (>= 5.2, < 8.0)
railties (>= 5.2, < 8.0)
ruby2_keywords (0.0.5)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
securerandom (0.3.1)
shoulda-context (2.0.0)
shoulda-matchers (6.4.0)
activesupport (>= 5.2.0)
sidekiq (7.3.1)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
logger
rack (>= 2.2.4)
redis-client (>= 0.22.2)
sidekiq-status (3.0.3)
chronic_duration
sidekiq (>= 6.0, < 8)
sidekiq-unique-jobs (8.0.10)
concurrent-ruby (~> 1.0, >= 1.0.5)
sidekiq (>= 7.0.0, < 8.0.0)
thor (>= 1.0, < 3.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand All @@ -210,9 +307,13 @@ GEM
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.1)
tilt (2.4.0)
timeout (0.4.1)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uri (0.13.0)
useragent (0.16.10)
web-console (4.2.1)
actionview (>= 6.0.0)
Expand All @@ -239,15 +340,34 @@ PLATFORMS

DEPENDENCIES
bootsnap
bootstrap
counter_culture
debug
faraday
faraday-follow_redirects
faraday-retry
faraday-typhoeus
jbuilder
jquery-rails
mocha
pagy
pg (~> 1.5)
pg_query
pghero
puma (~> 6.3)
rack-attack
rack-attack-rate-limit
rack-cors
rails (~> 7.2.0)
rails-controller-testing
rswag-api
rswag-ui
sassc-rails
shoulda-context
shoulda-matchers
sidekiq
sidekiq-status
sidekiq-unique-jobs
sprockets-rails
web-console
webmock
Expand Down
57 changes: 57 additions & 0 deletions app/models/fund.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,59 @@
class Fund < ApplicationRecord
validates :name, presence: true
validates :slug, presence: true, uniqueness: true

def self.import_from_topic(topic)
topic_url = "https://awesome.ecosyste.ms/api/v1/topics/#{topic}"

resp = Faraday.get topic_url
return unless resp.status == 200

topic = JSON.parse(resp.body)

fund = Fund.find_or_create_by(name: topic['name'], slug: topic['slug'])

fund.primary_topic = topic['slug']
fund.secondary_topics = topic['aliases']
fund.description = topic['short_description']
fund.wikipedia_url = topic['wikipedia_url']
fund.github_url = topic['github_url']

fund.save!
end

def logo_url
"https://explore-feed.github.com/topics/#{slug}/#{slug}.png"
end

def all_keywords
[primary_topic, *secondary_topics].compact
end

def import_projects
all_keywords.each do |keyword|
import_projects_from_packages(keyword)
end
end

def import_projects_from_packages(keyword)
page = 1
loop do
puts "Fetching page #{page} of projects for #{name}"
resp = Faraday.get("https://packages.ecosyste.ms/api/v1/keywords/#{keyword}?per_page=100&page=#{page}")
break unless resp.status == 200

data = JSON.parse(resp.body)
packages = data['packages']
break if packages.empty?

urls = packages.reject { |p| p['status'].present? }.map { |p| p['repository_url'] }.uniq.reject(&:blank?)
urls.each do |url|
puts url
project = Project.find_or_create_by(url: url)
project.sync_async unless project.last_synced_at.present?
end

page += 1
end
end
end
Loading

0 comments on commit c1d4d30

Please sign in to comment.