Skip to content

Instantly share code, notes, and snippets.

@urielhdz
Created August 23, 2019 20:01
Show Gist options
  • Save urielhdz/85f5fee7fd79fcf493a6deda1eb965d3 to your computer and use it in GitHub Desktop.
Save urielhdz/85f5fee7fd79fcf493a6deda1eb965d3 to your computer and use it in GitHub Desktop.
require 'digest/sha1'
require "google/cloud/firestore"
firebase_credentials = File.open('./firebase-key.json').read
firestore = Google::Cloud::Firestore.new(project_id: 'livemusiccodigofacilito', credentials: './firebase-key.json')
track_ref = firestore.doc "tracks/main"
music_data = ""
loop do
sleep(2)
file_content = File.read("./music.txt")
if file_content != music_data
# Upload to firebase
data = file_content.split("-")
song = data[0].strip
singer = data[1].strip
response = track_ref.set({ singer: singer, song: song })
puts response.to_yaml
end
music_data = file_content
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment