2016-05-16 19:29:04 +02:00
require_relative 'osia_helper'
2016-05-13 16:58:49 +02:00
require 'date'
2016-05-11 16:22:10 +02:00
2019-05-07 14:16:24 +02:00
# Constants
2016-05-13 17:50:39 +02:00
README = 'README.md'
2016-05-13 18:22:57 +02:00
ARCHIVE = 'ARCHIVE.md'
2017-06-14 23:07:35 +02:00
APPSTORE = 'APPSTORE.md'
2019-05-07 13:53:46 +02:00
LATEST = 'LATEST.md'
2017-06-14 23:07:35 +02:00
2019-04-17 05:53:05 +02:00
ARCHIVE_TAG = 'archive'
2018-05-28 17:10:36 +02:00
2020-08-19 15:45:36 +02:00
LATEST_NUM = 30
2019-05-08 03:39:12 +02:00
2020-07-14 17:12:41 +02:00
SHOW_TWITTER = false
2020-07-13 18:37:22 +02:00
2019-05-07 14:16:24 +02:00
# Helpers
def app_store_total ( j )
apps = j [ 'projects' ]
s = apps . reject { | x | x [ 'itunes' ] . nil? }
count = 1
s . each do | x |
tags = x [ 'tags' ]
if tags . nil?
t = " #{ count } "
count = count + 1
else
unless tags . include? ( ARCHIVE_TAG )
t = " #{ count } #{ tags } "
count = count + 1
end
end
end
count
end
2016-05-13 18:22:57 +02:00
def apps_archived ( apps )
2019-04-17 05:53:05 +02:00
a = apps . select { | a | a [ 'tags' ] != nil } . select { | b | b [ 'tags' ] . include? ( ARCHIVE_TAG ) }
2017-03-28 19:11:16 +02:00
a . sort_by { | k , v | k [ 'title' ] . downcase }
2016-05-13 18:22:57 +02:00
end
2016-05-11 16:22:10 +02:00
def apps_for_cat ( apps , id )
2016-05-13 18:22:57 +02:00
f = apps . select do | a |
tags = a [ 'tags' ]
if tags . nil?
true
else
2019-04-17 05:53:05 +02:00
! ( tags . include? ( ARCHIVE_TAG ) )
2016-05-13 18:22:57 +02:00
end
end
s = f . select do | a |
2016-08-25 16:35:26 +02:00
cat = a [ 'category-ids' ]
2016-05-11 17:07:03 +02:00
cat . class == Array ? cat . include? ( id ) : ( cat == id )
end
2016-06-12 06:06:12 +02:00
s . sort_by { | k , v | k [ 'title' ] . downcase }
2016-05-11 17:07:03 +02:00
end
2019-05-08 03:39:12 +02:00
def apps_latest ( apps , num )
2019-05-07 13:53:46 +02:00
a = apps . select { | a | a [ 'date_added' ] != nil }
. sort_by { | k , v | DateTime . parse ( k [ 'date_added' ] ) }
. reverse
2019-05-08 03:39:12 +02:00
a [ 0 .. num - 1 ]
2019-05-07 13:53:46 +02:00
end
2021-02-28 04:45:17 +01:00
def apps_updated ( apps , num )
a = apps . select { | a | a [ 'updated' ] != nil }
. sort_by { | k , v | DateTime . parse ( k [ 'updated' ] ) }
. reverse
a [ 0 .. num - 1 ]
end
2017-06-14 23:07:35 +02:00
def output_apps ( apps , appstoreonly )
2016-05-11 16:22:10 +02:00
o = ''
2016-05-11 17:07:03 +02:00
apps . each do | a |
2016-09-03 03:39:38 +02:00
name = a [ 'title' ]
link = a [ 'source' ]
itunes = a [ 'itunes' ]
homepage = a [ 'homepage' ]
desc = a [ 'description' ]
tags = a [ 'tags' ]
stars = a [ 'stars' ]
2021-02-28 04:45:17 +01:00
date_updated = a [ 'updated' ]
2016-09-03 03:39:38 +02:00
screenshots = a [ 'screenshots' ]
license = a [ 'license' ]
2016-07-28 17:15:37 +02:00
2021-03-07 04:37:05 +01:00
lines = [ ]
2016-05-11 16:22:10 +02:00
2021-03-07 04:37:05 +01:00
line = [ ]
line . push " [ #{ name } ]( #{ link } ) "
unless desc . nil?
line . push " : #{ desc } " if desc . size > 0
end
lines . push line
line = [ ]
unless homepage . nil?
line . push " <a href= #{ homepage } >` #{ homepage } `</a> "
2016-09-03 03:39:38 +02:00
end
2021-03-07 04:37:05 +01:00
lines . push line
line = [ ]
2016-09-03 03:39:38 +02:00
unless itunes . nil?
2021-03-07 04:37:05 +01:00
line . push " [` App Store`]( #{ itunes } ) "
2016-09-03 03:39:38 +02:00
end
2017-06-14 23:07:35 +02:00
if appstoreonly
next if itunes . nil?
end
2021-03-07 04:37:05 +01:00
unless screenshots . nil? || screenshots . empty?
screenshots . each_with_index do | s , i |
line . push " <a href=' #{ screenshots [ i ] } '>`Screenshot #{ i + 1 } `</a> "
2016-05-11 16:22:10 +02:00
end
2016-09-03 03:39:38 +02:00
end
2021-03-07 04:37:05 +01:00
lines . push line
2016-09-03 03:39:38 +02:00
2021-03-07 04:37:05 +01:00
line = [ ]
2021-02-28 04:45:17 +01:00
unless date_updated . nil?
date = DateTime . parse ( date_updated )
formatted_date = date . strftime " %Y "
2021-03-07 04:37:05 +01:00
line . push " ` #{ formatted_date } ` "
2021-02-28 04:45:17 +01:00
end
2016-09-03 03:39:38 +02:00
2023-03-23 16:33:02 +01:00
# unless license.nil?
# license_display = license == 'other' ? "" : "[`#{license}`](http://choosealicense.com/licenses/#{license}/)"
# line.push << " #{license_display} "
# end
2016-05-11 16:22:10 +02:00
2021-03-07 04:37:05 +01:00
unless tags . nil?
line . push '`swift` ' if tags . include? 'swift'
tags . each do | t |
line . push " ` #{ t . downcase } ` " if t . downcase != 'swift'
end
2016-09-03 03:39:38 +02:00
end
2021-03-07 04:37:05 +01:00
lines . push line
2016-09-03 03:39:38 +02:00
2021-03-07 04:37:05 +01:00
line = [ ]
unless stars . nil?
line . push " ☆` #{ stars } ` " if stars > 0
end
2016-09-03 03:39:38 +02:00
2021-03-07 04:37:05 +01:00
lines . push line
lines . each_with_index do | item , i |
temp = ''
item . each { | x | temp << " #{ x } " }
unless temp . empty?
if i == 0
o << " \n - #{ temp } "
else
o << " \n - #{ temp } "
end
end
end
2016-09-03 03:39:38 +02:00
2021-03-07 04:37:05 +01:00
# o << "\n"
2016-05-11 16:22:10 +02:00
end
o
end
2020-07-13 18:37:22 +02:00
def output_badges ( count , twitter )
2016-08-08 22:20:47 +02:00
date = DateTime . now
date_display = date . strftime " %B %e, %Y "
2017-03-21 15:51:59 +01:00
date_display = date_display . gsub ' ' , '%20'
2016-08-08 22:20:47 +02:00
2020-07-13 18:37:22 +02:00
b = " ![](https://img.shields.io/badge/Projects- #{ count } -green.svg) "
if twitter
b << " [![](https://img.shields.io/badge/Twitter-@opensourceios-blue.svg)](https://twitter.com/opensourceios) "
end
b << " ![](https://img.shields.io/badge/Updated- #{ date_display } -lightgrey.svg) "
return b
2016-08-08 22:20:47 +02:00
end
2019-05-19 16:12:02 +02:00
def write_archive ( j , subtitle )
2019-05-07 14:16:24 +02:00
t = j [ 'title' ]
apps = j [ 'projects' ]
archived = apps_archived apps
2019-05-19 16:12:02 +02:00
footer = j [ 'footer' ]
2019-05-07 14:16:24 +02:00
output = " \# #{ t } Archive \n \n "
2019-05-19 16:12:02 +02:00
output << subtitle
2019-05-07 14:16:24 +02:00
output << " \n "
archived . each do | a |
t = a [ 'title' ]
s = a [ 'source' ]
output << " - [ #{ t } ]( #{ s } ) \n "
end
output << " \n "
2019-05-19 16:12:02 +02:00
output << footer
2019-05-07 14:16:24 +02:00
file = ARCHIVE
File . open ( file , 'w' ) { | f | f . write output }
puts " wrote #{ file } ✨ "
end
2021-02-28 04:45:17 +01:00
def write_latest ( j , num , sub1 , sub2 )
2019-05-07 14:16:24 +02:00
t = j [ 'title' ]
apps = j [ " projects " ]
2019-05-19 16:12:02 +02:00
footer = j [ 'footer' ]
2019-05-08 03:39:12 +02:00
latest = apps_latest ( apps , num )
2019-05-07 14:16:24 +02:00
output = " \# #{ t } Latest \n \n "
2021-02-28 04:45:17 +01:00
output << sub1
2019-05-07 14:16:24 +02:00
output << " \n "
count = 1
latest . each do | a |
t = a [ 'title' ]
s = a [ 'source' ]
output << " #{ count } . [ #{ t } ]( #{ s } ) \n "
count = count + 1
end
2021-02-28 04:45:17 +01:00
updated = apps_updated ( apps , num )
output << " \n "
output << sub2
output << " \n "
count = 1
updated . each do | a |
t = a [ 'title' ]
s = a [ 'source' ]
output << " #{ count } . [ #{ t } ]( #{ s } ) \n "
count = count + 1
end
2019-05-07 14:16:24 +02:00
output << " \n "
2019-05-19 16:12:02 +02:00
output << footer
2019-05-07 14:16:24 +02:00
file = LATEST
File . open ( file , 'w' ) { | f | f . write output }
puts " wrote #{ file } ✨ "
end
2019-05-19 16:12:02 +02:00
def write_list ( j , file , subtitle , appstoreonly = false )
2019-04-19 04:52:08 +02:00
t = j [ 'title' ]
2019-05-19 16:12:02 +02:00
desc = j [ 'description' ]
2019-04-19 04:52:08 +02:00
h = j [ 'header' ]
f = j [ 'footer' ]
2016-05-13 17:50:39 +02:00
cats = j [ 'categories' ]
apps = j [ 'projects' ]
2016-05-11 16:22:10 +02:00
2018-04-22 22:48:15 +02:00
sponsor = j [ 'sponsor' ]
2016-05-13 17:50:39 +02:00
output = '# ' + t
output << " \n \n "
2017-06-15 18:20:00 +02:00
output << desc
2017-06-14 23:07:35 +02:00
2019-05-20 03:59:08 +02:00
output << " \n \n #{ subtitle } \n \n "
2019-05-19 16:12:02 +02:00
2017-06-14 23:07:35 +02:00
if appstoreonly == false
2020-07-13 18:37:22 +02:00
output << output_badges ( apps . count , SHOW_TWITTER )
2018-04-22 22:48:15 +02:00
unless sponsor . length == 0
output << " \n \n "
output << sponsor
output << " \n "
end
2017-06-14 23:07:35 +02:00
end
2016-05-13 16:58:49 +02:00
2016-08-09 14:58:50 +02:00
output << " \n \n Jump to \n \n "
2016-05-13 16:58:49 +02:00
2016-05-13 17:50:39 +02:00
cats . each do | c |
2016-06-06 18:00:38 +02:00
title = c [ 'title' ]
m = title . match / \ [.*? \ ] /
title = m [ 0 ] . sub ( '[' , '' ) . sub ( ']' , '' ) unless m . nil?
2019-04-17 05:53:05 +02:00
temp = " #{ ' ' unless c [ 'parent' ] == nil } - [ #{ title } ]( \# #{ c [ 'id' ] } ) \n "
2016-05-13 17:50:39 +02:00
output << temp
end
2016-05-11 16:22:10 +02:00
2016-07-29 17:18:19 +02:00
output << " - [Thanks]( # thanks) \n "
output << " - [Contact]( # contact) \n "
2016-05-13 17:50:39 +02:00
output << " \n "
output << h
output << " \n "
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
cats . each do | c |
temp = " \n # \# #{ '#' unless c [ 'parent' ] == nil } #{ c [ 'title' ] } \n \n "
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
d = c [ 'description' ]
temp << " #{ d } — " unless d . nil?
2016-05-11 19:53:59 +02:00
2016-05-13 17:50:39 +02:00
temp << " [back to top]( # readme) \n \n "
output << temp
2016-05-11 19:53:59 +02:00
2016-05-13 17:50:39 +02:00
cat_apps = apps_for_cat ( apps , c [ 'id' ] )
2017-06-14 23:07:35 +02:00
output << output_apps ( cat_apps , appstoreonly )
2016-05-13 17:50:39 +02:00
end
output << " \n "
output << f
2016-05-11 16:22:10 +02:00
2017-06-14 23:07:35 +02:00
File . open ( file , 'w' ) { | f | f . write output }
puts " wrote #{ file } ✨ "
2016-05-11 16:22:10 +02:00
end
2019-05-07 14:16:24 +02:00
# Script begins
2019-05-07 13:53:46 +02:00
2016-05-16 19:29:04 +02:00
j = get_json
2016-05-11 16:22:10 +02:00
2019-05-19 16:12:02 +02:00
subtitle_readme = j [ 'subtitle' ]
write_list ( j , README , subtitle_readme )
2019-05-19 16:16:27 +02:00
subtitle_app_store = " List of ** #{ app_store_total j } ** open-source apps published on the App Store (complete list [here](https://github.com/dkhamsing/open-source-ios-apps)). "
2019-05-19 16:12:02 +02:00
write_list ( j , APPSTORE , subtitle_app_store , true )
subtitle_archive = " This is an archive of the [main list](https://github.com/dkhamsing/open-source-ios-apps) for projects that are no longer maintained / old. \n \n "
write_archive ( j , subtitle_archive )
2021-02-28 04:45:17 +01:00
subtitle_latest = " # # Lastest additions to the [main list](https://github.com/dkhamsing/open-source-ios-apps) \n "
subtitle_updated = " # # Most recently updated \n "
write_latest ( j , LATEST_NUM , subtitle_latest , subtitle_updated )