Skip to content

Instantly share code, notes, and snippets.

@manton
Created July 4, 2022 21:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manton/50293c39b6f9c96e5e0ed19ebbff93bf to your computer and use it in GitHub Desktop.
Save manton/50293c39b6f9c96e5e0ed19ebbff93bf to your computer and use it in GitHub Desktop.
require "json"
# JSON file of App.net data, Micro.blog auth token, and blog UID if multiple blogs
json_path = "/Users/manton/Dropbox/Documents/Weblog/Ohai/appdotnet-data-manton-1466255913-messages.json"
token = "..."
blog_uid = "https://you.micro.blog/"
messages = JSON.parse(IO.read(json_path))
for m in messages
# make sure it's Ohai
app_name = m["source"]["name"]
if app_name == "Ohai"
# get check-in fields
found_location = false
id = m["id"]
s = m["text"].to_s
d = m["created_at"]
name = ""
latitude = 0
longitude = 0
for a in m["annotations"]
type = a["type"]
puts "Found annotation type #{type}"
if type == "net.app.ohai.location"
value = a["value"]
name = value["name"]
latitude = value["latitude"]
longitude = value["longitude"]
found_location = true
break
end
end
# some check-ins have no text or location, skip those
if found_location || (s.length > 0)
# format the post
if found_location
info = {
type: [ "h-entry" ],
"mp-destination": blog_uid,
properties: {
content: [ s ],
checkin: [
{
type: [ "h-card" ],
properties: {
latitude: [ latitude ],
longitude: [ longitude ],
name: [ name ]
}
}
],
published: [ d ]
}
}
else
info = {
type: [ "h-entry" ],
"mp-destination": blog_uid,
properties: {
content: [ s ],
published: [ d ]
}
}
end
json_escaped = info.to_json.gsub("\"", "\\\"")
# publish the post
puts "Publishing check-in #{id}: #{d} - #{s}"
result = `curl https://micro.blog/micropub -H "Authorization: Bearer #{token}" -H "Content-Type: application/json" -d "#{json_escaped}"`
puts result
# wait a half second between each post
sleep 0.5
end
end
end
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment