Last active
December 16, 2015 08:39
Revisions
-
timfall revised this gist
Apr 20, 2013 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ else puts "No local database detected, grabbing one from the server" ldb = auth.get('v1/my_data/articles') ldb = JSON.parse(ldb.body) @local = File.new("#{absworkingdir}/localdb.json", "w") @local << ldb i = ldb['count'] @@ -68,7 +68,7 @@ #Compare local and remote databses for differences rdb = auth.get('v1/my_data/articles') rdb = JSON.parse(rdb.body) i = rdb[count] r = ldb[count] for i.times do @@ -85,7 +85,9 @@ File.new('#{absworkingdir}/localdb/#{remotearticlelist[i].name}', "w") = auth.get(remotearticlelist[i].path)#download remote version localarticlelist[r] = Article.new(rdb[i].name, "#{absworkingdir}/localdb/#{rbd[i].name}", rbd[i].id)#create new local article entry download = auth.get(remotearticlelist[i].path) download = JSON.parse(download.body) @local = File.read("#{absworkingdir}/localdb.json") @local.gsub(/pattern/) { matchmatchmatch } #replace entry in localdb.json end elsif File.mtime(remotearticlelist[i].path) <= File.mtime(localarticlelist[r].path)#If local version is newer than remote localfile = JSON.pretty_generate('Title' => localarticlelist[r].title, 'description' => localarticlelist[r].description, 'defined_type' => localarticlelist[r].defined_type)#generate a json list from the object -
timfall revised this gist
Apr 18, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,7 @@ #oauth authenticate auth = OauthFighshare.new(consumerkey, consumersecret, accesstoken, accesstokensecret) if auth.header (v1/my_data/articles) == Net::HTTPUnauthorized puts "Figshare returned #{auth.header (v1/my_data/articles)}" end puts "Successfully authenticated" -
timfall revised this gist
Apr 18, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ end #oauth authenticate auth = OauthFighshare.new(consumerkey, consumersecret, accesstoken, accesstokensecret) if auth.header (v1/my_data/articles) == Net::HTTPUnauthorized puts "Figshare returned #{auth.head (v1/my_data/articles)}" end puts "Successfully authenticated" -
timfall revised this gist
Apr 18, 2013 . 1 changed file with 19 additions and 7 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,7 +50,7 @@ ldb = JSON.parse("#{absworkingdir}/localdb.json") @i = ldb['count'] for @i.times do localarticlelist[i] = Article.new(ldb[i].name, "#{absworkingdir}/localdb/#{ldb[i].name}", ldb[i].id, ldb[i].title, ldb[i].description, ldb[i].defined_type) done puts "Done populating the local list from local database" else @@ -61,7 +61,7 @@ @local << ldb i = ldb['count'] for i.times do localarticlelist[i] = Article.new(ldb[i].name, "#{absworkingdir}/localdb/#{ldb[i].name}", ldb[i].id, ldb[i].title, ldb[i].description, ldb[i].defined_type) done puts "Local database file created and populated from server" done @@ -72,16 +72,28 @@ i = rdb[count] r = ldb[count] for i.times do remotearticlelist[i] = Article.new(rdb[i].name, "v1/my_data/articles/#{ldb[i].name}", rdb[i].id, rdb[i].title, rdb[i].description, rdb[i].defined_type) done for i.times do for r.times do @remotehash = remotearticlelist[i].hash @localhash = localarticlelist[r].hash if rdb[i].id == ldb[r].id if @remotehash != @localhash puts "Hash mismatch! #{remotearticlelist[i].name} and #{localarticlelist[r].name} do not match" if File.mtime(remotearticlelist[i].path) >= File.mtime(localarticlelist[r].path)#If remote version is newer than local File.new('#{absworkingdir}/localdb/#{remotearticlelist[i].name}', "w") = auth.get(remotearticlelist[i].path)#download remote version localarticlelist[r] = Article.new(rdb[i].name, "#{absworkingdir}/localdb/#{rbd[i].name}", rbd[i].id)#create new local article entry download = auth.get(remotearticlelist[i].path) #replace entry in localdb.json end elsif File.mtime(remotearticlelist[i].path) <= File.mtime(localarticlelist[r].path)#If local version is newer than remote localfile = JSON.pretty_generate('Title' => localarticlelist[r].title, 'description' => localarticlelist[r].description, 'defined_type' => localarticlelist[r].defined_type)#generate a json list from the object auth.post('v1/my_data/articles/', localfile, {"Content-Type" => "application/json"})#upload json list end end end next done done puts "All hashes match" -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,9 +76,9 @@ done for i.times do for r.times do @remotehash = remotearticlelist[i].hash @localhash = localarticlelist[r].hash if @remotehash == @localhash if @remotehash != @localhash puts "Hash mismatch! #{remotearticlelist[i].name} and #{localarticlelist[i].name} do not match" end -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,14 +70,18 @@ rdb = auth.get('v1/my_data/articles') rdb = JSON.parse(rdb) i = rdb[count] r = ldb[count] for i.times do remotearticlelist[i] = Article.new(rdb[i].name, "v1/my_data/articles/#{ldb[i].name}", rdb[i].id) done for i.times do for r.times do if remotearticlelist[i].hash == localarticlelist[r].hash @remotehash = remotearticlelist[i].hash @localhash = localarticlelist[i].hash if @remotehash != @localhash puts "Hash mismatch! #{remotearticlelist[i].name} and #{localarticlelist[i].name} do not match" end end puts "All hashes match" done -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,4 +68,16 @@ #Compare local and remote databses for differences rdb = auth.get('v1/my_data/articles') rdb = JSON.parse(rdb) i = rdb[count] for i.times do remotearticlelist[i] = Article.new(rdb[i].name, "v1/my_data/articles/#{ldb[i].name}", rdb[i].id) done for i.times do @remotehash = remotearticlelist[i].hash @localhash = localarticlelist[i].hash if @remotehash != @localhash puts "Hash mismatch! #{remotearticlelist[i].name} and #{localarticlelist[i].name} do not match" end puts "All hashes match" done -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,4 +64,8 @@ localarticlelist[i] = Article.new(ldb[i].name, "#{absworkingdir}/localdb/#{ldb[i].name}", ldb[i].id) done puts "Local database file created and populated from server" done #Compare local and remote databses for differences rdb = auth.get('v1/my_data/articles') rdb = JSON.parse(rdb) -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,17 +48,17 @@ if File.exists?("#{absworkingdir}/localdb.json") puts "Local database detected, populating from there" ldb = JSON.parse("#{absworkingdir}/localdb.json") @i = ldb['count'] for @i.times do localarticlelist[i] = Article.new(ldb[i].name, "#{absworkingdir}/localdb/#{ldb[i].name}", ldb[i].id) done puts "Done populating the local list from local database" else puts "No local database detected, grabbing one from the server" ldb = auth.get('v1/my_data/articles') ldb = JSON.parse(ldb) @local = File.new("#{absworkingdir}/localdb.json", "w") @local << ldb i = ldb['count'] for i.times do localarticlelist[i] = Article.new(ldb[i].name, "#{absworkingdir}/localdb/#{ldb[i].name}", ldb[i].id) -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,5 +59,9 @@ ldb = JSON.parse(ldb) local = File.new("#{absworkingdir}/localdb.json", "w") local << ldb i = ldb['count'] for i.times do localarticlelist[i] = Article.new(ldb[i].name, "#{absworkingdir}/localdb/#{ldb[i].name}", ldb[i].id) done puts "Local database file created and populated from server" done -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 13 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,7 @@ consumersecret accesstoken accesstokensecret localarticlelist #First run setup absworkingdir = File.expand_path(workingdir) @@ -47,6 +48,16 @@ if File.exists?("#{absworkingdir}/localdb.json") puts "Local database detected, populating from there" ldb = JSON.parse("#{absworkingdir}/localdb.json") i = ldb['count'] for i.times do localarticlelist[i] = Article.new(ldb[i].name, "#{absworkingdir}/localdb/#{ldb[i].name}", ldb[i].id) done puts "Done populating the local list from local database" else puts "No local database detected, grabbing one from the server" ldb = auth.get('v1/my_data/articles') ldb = JSON.parse(ldb) local = File.new("#{absworkingdir}/localdb.json", "w") local << ldb puts "Local database file created and populated from server" done -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ @input = gets.chomp if @input != nil workingdir = @input absworkingdir = File.expand_path(workingdir) else break end @@ -42,4 +43,10 @@ end puts "Successfully authenticated" #Create article database and populate from local sources if File.exists?("#{absworkingdir}/localdb.json") puts "Local database detected, populating from there" ldb = JSON.parse("#{absworkingdir}/localdb.json") i = lab['count'] for i.times do Article.new(JSON.parse("#{absworkingdir}/localdb.json")) -
timfall revised this gist
Apr 17, 2013 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ #First run setup absworkingdir = File.expand_path(workingdir) if File.exist?("#{absworkingdir}/FirstRun.lock") break else puts "This appears to be the first run of FigShare Sync. We'll setup a few things." @@ -33,6 +33,7 @@ print "Please enter OAuth access token secret: " accesstokensecret = gets.chomp puts "Great! we'll get running now..." File.new("#{absworkingdir}/FirstRun.lock", "r") end #oauth authenticate auth = OauthFighshare.new(consumerkey, consumersecret, accesstoken, accesstokensecret) -
timfall created this gist
Apr 17, 2013 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ #!/usr/bin/ruby require 'json' require 'oauth' #require '../lib/OauthFigsharesync' #require '../lib/FigshareClasses' workingdir = "~/.figsharesync/" consumerkey consumersecret accesstoken accesstokensecret #First run setup absworkingdir = File.expand_path(workingdir) if File.exist?(absworkingdir) break else puts "This appears to be the first run of FigShare Sync. We'll setup a few things." print "Where would you like to store settings and files? [~./figsharesync]: " @input = gets.chomp if @input != nil workingdir = @input else break end print "Please enter OAuth consumer key: " consumerkey = gets.chomp print "Please enter OAuth consumer key secret: " consumersecret = gets.chomp print "Please enter OAuth access token: " accesstoken = gets.chomp print "Please enter OAuth access token secret: " accesstokensecret = gets.chomp puts "Great! we'll get running now..." end #oauth authenticate auth = OauthFighshare.new(consumerkey, consumersecret, accesstoken, accesstokensecret) if auth.head (v1/my_data/articles) =! #http auth error puts "Figshare returned #{auth.head (v1/my_data/articles)}" end puts "Successfully authenticated" #Create article database and populate from local sources