Skip to content

Instantly share code, notes, and snippets.

@dmiro
Last active August 25, 2023 11:43
Show Gist options
  • Save dmiro/6688b92f25f9c1fedc1b7bfd22f0de68 to your computer and use it in GitHub Desktop.
Save dmiro/6688b92f25f9c1fedc1b7bfd22f0de68 to your computer and use it in GitHub Desktop.
Create sqlite database from repository radio-browser.info
import subprocess
import gzip
import os
"""
create sqlite database from repository radio-browser.info
prerequisites:
(1) install sqlite3 (client)
> sudo apt-get install sqlite3
(2) copy mysql2sqlite script from github
https://github.com/dumblob/mysql2sqlite
"""
# init
print '--init--'
# creating database backup
if os.path.exists('radio.db'):
print 'creating database backup'
os.rename('radio.db', 'radio.db.bak')
# download radio-browser database
print 'download radio-browser database'
subprocess.call(['curl', 'http://www.radio-browser.info/backups/latest.sql.gz', '--output', 'latest.sql.gz'])
# decompress database
print 'decompress database'
inF = gzip.open('latest.sql.gz', 'rb')
outF = open('latest.sql', 'wb')
outF.write(inF.read())
inF.close()
outF.close()
# convert dump from mysql to sqlite
print 'convert dump from mysql to sqlite'
process = subprocess.Popen(['./mysql2sqlite', 'latest.sql'], stdout=subprocess.PIPE)
out, err = process.communicate()
outF = open('latest.sqlite', 'wb')
outF.write(out)
outF.close()
# create and populate database
print 'create and populate database'
myinput = open('latest.sqlite')
process = subprocess.Popen(['sqlite3', 'radio.db'], stdin=myinput)
process.wait()
# remove files
print 'removing files'
if os.path.exists('latest.sql.gz'): os.remove('latest.sql.gz')
if os.path.exists('latest.sql'): os.remove('latest.sql')
if os.path.exists('latest.sqlite'): os.remove('latest.sqlite')
# end
print '--end--'
@wolkenarchitekt
Copy link

I wrote a docker-compose stack to to the same - so you don't have to install anything on your machine besides docker-compose:
https://github.com/ifischer/radio-browser-mysql-to-sqlite

It uses rubygem Sequel which seems like a much cleaner approach than mysql2sqlite and it can convert to any other database, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment