Skip to content

Instantly share code, notes, and snippets.

@gkaklas
Last active January 7, 2019 09:54
Show Gist options
  • Save gkaklas/42f05be03d05c0d77b32d2b41321bbe1 to your computer and use it in GitHub Desktop.
Save gkaklas/42f05be03d05c0d77b32d2b41321bbe1 to your computer and use it in GitHub Desktop.
A Ruby script for parsing all devices from LineageOS wiki and filtering them based on some needed specifications
#!/bin/env ruby
# This script assumes you have cloned the wiki:
# git clone https://github.com/LineageOS/lineage_wiki --depth 1 && cd lineage_wiki/_data/devices
#
# Then run this script with something like:
# for i in *.yml;do ruby ./which_phone_should_i_buy.rb $i "https://wiki.lineageos.org/devices/"; done
# You can use the second argument to prepend some text to the output
require 'psych'
require 'date'
device = Psych.load_file(ARGV[0])
exit if device['channels'].include? 'discontinued'
# Devices with multiple releases are not handled!
unless device['release'].is_a? Array
# %Y-%m is automatically parsed from the yml file as a date, so we need
# to convert it to string for consistent handling among formats
release = device['release'].to_s
if release.length == 7
release = Date.strptime(release, '%Y-%m')
elsif release.length == 10
release = Date.strptime(release, '%Y-%m-%d')
elsif release.length == 4
release = Date.strptime(release, '%Y')
end
recent = (release.year == Date.today.year) ||
(release.year == Date.today.prev_year.year)
end
four_g = false
if device['network'] && (device['network'] != 'None')
# Most devices support multiple network types
device['network'].each do |network|
if network['tech'] == '4G'
four_g = true
break
end
end
end
is_phone = device['type'] == 'phone'
# Sometimes there isn't an sdcard attribute at all, sometimes there is
# but it's empty
has_sdcard = device['sdcard'] && !device['sdcard'].empty?
if recent && four_g && is_phone && has_sdcard
puts ARGV[1] + device['codename']
# Useful ARGV[1]:
# https://www.skroutz.gr/c/40/kinhta-thlefwna.html?keyphrase=
# puts ARGV[1] + device["vendor"] + " " + device["name"]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment