1
0
mirror of https://github.com/dkhamsing/open-source-ios-apps.git synced 2024-12-24 23:43:31 +01:00
App-Open-Source-per-iPhone-.../convert.rb

122 lines
2.1 KiB
Ruby
Raw Normal View History

2016-05-11 16:22:10 +02:00
require 'json'
OUTPUT = 'README.md'
def output_stars(number)
case number
when 100...200
'🔥'
when 200...500
'🔥🔥'
when 500...1000
'🔥🔥🔥'
when 1000...2000
'🔥🔥🔥🔥'
when 2000...100000
'🔥🔥🔥🔥🔥'
end
end
def output_flag(lang)
case lang
when 'jpn'
'🇯🇵'
when 'ltz'
'🇱🇺'
when 'por'
'🇧🇷'
when 'spa'
'🇪🇸'
when 'zho'
'🇨🇳'
end
end
def apps_for_cat(apps, id)
2016-05-11 17:19:04 +02:00
s = apps.select do |a|
2016-05-11 17:07:03 +02:00
cat = a['category']
cat.class == Array ? cat.include?(id) : (cat == id)
end
2016-05-11 17:19:04 +02:00
s.sort_by { |k, v| k['title'] }
2016-05-11 17:07:03 +02:00
end
def output_apps(apps)
2016-05-11 16:22:10 +02:00
o = ''
2016-05-11 17:07:03 +02:00
apps.each do |a|
2016-05-11 16:22:10 +02:00
name = a['title']
link = a['source']
itunes = a['itunes']
2016-05-11 17:19:04 +02:00
homepage = a['homepage']
2016-05-11 16:22:10 +02:00
desc = a['description']
tags = a['tags']
stars = a['stars']
lang = a['lang']
o << "- #{name}"
if desc.nil?
o << ' '
else
o << ": #{desc} " if desc.size>0
end
unless tags.nil?
o << "🔶" if tags.include? 'swift'
end
unless lang.nil?
o << output_flag(lang)
end
unless stars.nil?
o << output_stars(stars)
end
o << "\n"
o << " - #{link}\n"
2016-05-11 17:19:04 +02:00
o << " - #{homepage}\n" unless homepage.nil?
2016-05-11 16:22:10 +02:00
o << " - #{itunes}\n" unless itunes.nil?
end
o
end
c = File.read 'contents.json'
j = JSON.parse c
2016-05-11 19:43:14 +02:00
t = j['title']
2016-05-11 16:22:10 +02:00
desc = j['description']
2016-05-11 19:43:14 +02:00
h = j['header']
f = j['footer']
2016-05-11 16:22:10 +02:00
cats = j['categories']
apps = j['projects']
output = '# ' + t
output << "\n\n"
output << desc
output << "\n \nJump to \n \n"
cats.each do |c|
temp = "#{' ' unless c['parent']==nil }- [#{c['title']}](\##{c['id']}) \n"
output << temp
end
2016-05-11 19:43:14 +02:00
output << "- [Bonus](#bonus) \n"
2016-05-11 16:22:10 +02:00
2016-05-11 19:43:14 +02:00
output << "\n"
2016-05-11 16:22:10 +02:00
output << h
output << "\n"
cats.each do |c|
temp = "\n#\##{'#' unless c['parent']==nil } #{c['title']} \n \n"
output << temp
2016-05-11 17:07:03 +02:00
cat_apps = apps_for_cat(apps, c['id'])
output << output_apps(cat_apps)
2016-05-11 16:22:10 +02:00
end
output << "\n"
output << f
File.open(OUTPUT, 'w') { |f| f.write output }
puts "wrote #{OUTPUT}"